Hey all,
those of you following the development of JNA will have noticed, that
the master branch holds a version, that will released as 5.0.0.
I branched a bugfix branch 4.5.X, that will get (and already got) some
bugfixes, but feature work will be limited to master.
The upcoming 5.0 version will be an source and binary incompatible with
4.X, as for example the signature of the Native#loadLibrary method was
changed from:
public static <T> T loadLibrary(Class<T> interfaceClass);
to
public static <T extends Library> T loadLibrary(Class<T> interfaceClass);
The wildcard was bounded to require a subtype of Library as parameter,
turning the existing runtime check into an compiletime check.
This change as a drawback however: This change is binary incompatible,
as the return type of a method is part of the signature. After erasure,
the first method returns "Object", while the second returns "Library".
Any library building on JNA must be recompiled against 5.0 and you
can't design bindings, that work with both branches (ok you could, by
using reflection to invoke the correct version of loadLibrary).
There is an option though: It is possible to inject bridge methods into
the bytecode. The approach would use:
https://github.com/infradna/bridge-method-injector
Given the signature from above this:
@WithBridgeMethods(Object.class)
public static <T extends Library> T loadLibrary(Class<T> interfaceClass);
would generate the needed bridge method, if the class is postprocessed
with the method injector.
From the POV of java, the language, the old method is still gone, but
from the POV of the JVM, the method can be found.
A bit better visible is the consequence if you compare the attached
compatibility report. The one with the "_bridge_methods" suffix is the
postprocessed case, and the one without is the case without post
processing. The incompatible changes after applying the bridge methods
are reduced to removing deprecated methods and removing Pointer#SIZE
which was not deprecated.
I have mixed feelings about this:
* it reduces incompatibilities (with the bridge methods you can
trivially create bindings, that can be used with JNA 4.5.X and 5.X)
* it requires the developers of JNA to understand about bytecode
manipulation
* it introduces a new compile time dependency (asm)
What do you think?
Greetings
Matthias