-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Description
Describe the bug
An extension method with a long
or double
parameter, which is called with an int
, causes an JNI error during runtime when loading the class.
Definition of the extension method with a long
argument:
public static <T> void hello(String that, long n) {
// nothing here
}
Calling it with an int
:
public void someMethod() {
"".hello(1);
}
This compiles, but when run in Eclipse, produces the JNI error below.
Calling with a long
instead (eg. changing the 1
to a 1l
) fixes the problem.
To Reproduce
See here for an example project:
The problem can be seen in the JNIProblem.java class.
When launching the class in Eclipse, it will fail like this:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.VerifyError: Bad type on operand stack
Exception Details:
Location:
prob/lems/JNIProblem.someMethod()V @3: invokestatic
Reason:
Type integer (current frame, stack[1]) is not assignable to long_2nd
Current Frame:
bci: @3
flags: { }
locals: { 'prob/lems/JNIProblem' }
stack: { 'java/lang/String', integer }
Bytecode:
0x0000000: 120f 08b8 0011 120f 1400 17b8 0011 b1
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:650)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:632)
With javac
/java
it works just fine:
$ make jni_problem
javac -cp lombok-1.18.28.jar prob/lems/JNIProblem.java
java -cp lombok-1.18.28.jar:. 'prob.lems.JNIProblem'
works in javac but not with Eclipse
Expected behavior
No JNI error :)
Version info:
- Lombok version: 1.18.28
- Eclipse: 2022-03 (4.23.0)
Workaround
Define both versions of the extension method (int
and long)
, and let one call the other.
When I tried this, it still wouldn't work. Turns out, Eclipse does not recompile my calling class, when the extension method class changes.
After a Clean Build everything worked fine.