JNI Thought

One problem that occurs when writing JNI code is that it is easy
to mistype a method name or signature, yielding errors only detectable
at runtime. Another problem is that if you change a class, you might
forget to update your JNI code, giving the same problem along a
different path. Neither of these problems can occur with CNI, and
last night it occurred to me that you could duplicate this in JNI with
just a little work.

The idea is to modify javah to generate slightly
different headers, and in particular to generate headers for the
classes you plan to reference from JNI. For each method or field in a
header, the new program would emit a define for the name and another
for the signature. Then JNI code would simply always use these new
defines.

The last step is to ensure that these headers are rebuilt whenever
the corresponding java classes change. Then you will either get
always-correct compilations of your JNI code, or, if the change was
incompatible, an error since the symbols used in your C code will not
be declared.

Be the first to leave a comment. Don’t be shy.

Join the Discussion

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.