Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] extensions method with long/double argument causes JNI error when run in Eclipse #3463

Closed
marc-guenther opened this issue Jul 22, 2023 · 2 comments · Fixed by #3478
Closed
Milestone

Comments

@marc-guenther
Copy link

marc-guenther commented Jul 22, 2023

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.

marc-guenther pushed a commit to marc-guenther/lombok-problems that referenced this issue Jul 22, 2023
marc-guenther pushed a commit to marc-guenther/lombok-problems that referenced this issue Jul 23, 2023
marc-guenther pushed a commit to marc-guenther/lombok-problems that referenced this issue Jul 23, 2023
@Rawi01
Copy link
Collaborator

Rawi01 commented Aug 2, 2023

Thanks for the detailed bug report. IIRC we already have some special handling for casts but it seems to be incomplete or incompatible with recent eclipse versions.

@marc-guenther
Copy link
Author

I can confirm that this fixes the problem. Thanks a lot! Always nice to fix a bug by removing "magic" from the code :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants