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

IllegalArgumentException in java 11 using RC3 #612

Closed
regrog opened this issue Jul 31, 2020 · 38 comments
Closed

IllegalArgumentException in java 11 using RC3 #612

regrog opened this issue Jul 31, 2020 · 38 comments
Labels

Comments

@regrog
Copy link

regrog commented Jul 31, 2020

Hi,

I'm using jsweet in an eclipse project using you project (https://github.com/cincheo/jsweet-eclipse-plugin).
Actually running it with java 8 everything works perfectly.

Now I'm migrating to java 11+ but I'm having some issues.
I' replaced the old jsweet-transpiler-latest-jar-with-dependencies.jar with the new release candidate jsweet-transpiler-3.0.0-RC3-jar-with-dependencies.jar

I changed the call to Utils.addFiles to Utils.Static.addFiles and removed the call to JSweetConfig.jinitClassPath(jdkHome).

But when I run the transpilation this error occurs that doesn't seem to be part of what I changed.

Can I have any help?
Thanks

dumping transpiler's strack trace:
   [JCMethodDecl] public <init>() {... (myHome/myProject/src/main/java/myClass.java(6,8))
   [JCClassDecl] public class IsAccTraIdSettedC... (myHome/myProject/src/main/java/myClass.java(6,1))
   [JCCompilationUnit] package it.smi.galileo.acc.acc... (myHome/myProject/src/main/java/myClass.java(1,1))
java.lang.RuntimeException: Cannot call internal Javac API :( please adapt this code if API changed
	at org.jsweet.transpiler.util.Util.isGeneratedConstructor(Util.java:2194)
	at org.jsweet.transpiler.Java2TypeScriptTranslator.visitMethod(Java2TypeScriptTranslator.java:2163)
	at org.jsweet.transpiler.Java2TypeScriptTranslator.visitMethod(Java2TypeScriptTranslator.java:146)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:898)
	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
	at org.jsweet.transpiler.util.AbstractTreeScanner.scan(AbstractTreeScanner.java:269)
	at org.jsweet.transpiler.util.AbstractTreePrinter.print(AbstractTreePrinter.java:121)
	at org.jsweet.transpiler.Java2TypeScriptTranslator.visitClass(Java2TypeScriptTranslator.java:1746)
	at org.jsweet.transpiler.Java2TypeScriptTranslator.visitClass(Java2TypeScriptTranslator.java:146)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:808)
	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
	at org.jsweet.transpiler.util.AbstractTreeScanner.scan(AbstractTreeScanner.java:269)
	at org.jsweet.transpiler.util.AbstractTreePrinter.print(AbstractTreePrinter.java:121)
	at org.jsweet.transpiler.Java2TypeScriptTranslator.visitCompilationUnit(Java2TypeScriptTranslator.java:857)
	at org.jsweet.transpiler.Java2TypeScriptTranslator.visitCompilationUnit(Java2TypeScriptTranslator.java:146)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:591)
	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
	at org.jsweet.transpiler.util.AbstractTreeScanner.scan(AbstractTreeScanner.java:269)
	at org.jsweet.transpiler.util.AbstractTreePrinter.print(AbstractTreePrinter.java:121)
	at org.jsweet.transpiler.JSweetTranspiler.generateTsFiles(JSweetTranspiler.java:880)
	at org.jsweet.transpiler.JSweetTranspiler.java2ts(JSweetTranspiler.java:843)
	at org.jsweet.transpiler.JSweetTranspiler.transpile(JSweetTranspiler.java:771)
	at org.jsweet.plugin.builder.JSweetBuilderJob.transpileFiles(JSweetBuilderJob.java:300)
	at org.jsweet.plugin.builder.JSweetBuilderJob.run(JSweetBuilderJob.java:126)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: java.lang.IllegalArgumentException: Can not set int field com.sun.tools.javac.tree.JCTree.pos to com.sun.tools.javac.tree.JCTree$JCMethodDecl
	at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
	at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
	at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:58)
	at java.base/jdk.internal.reflect.UnsafeIntegerFieldAccessorImpl.getInt(UnsafeIntegerFieldAccessorImpl.java:56)
	at java.base/jdk.internal.reflect.UnsafeIntegerFieldAccessorImpl.get(UnsafeIntegerFieldAccessorImpl.java:36)
	at java.base/java.lang.reflect.Field.get(Field.java:418)
	at org.jsweet.transpiler.util.Util.isGeneratedConstructor(Util.java:2189)
	... 24 more
@renaudpawlak
Copy link
Contributor

renaudpawlak commented Jul 31, 2020 via email

@regrog
Copy link
Author

regrog commented Aug 25, 2020

Hemmm... what do you mean?
Is this something that concerns jsweet transpiler?

@lgrignon lgrignon added the bug label Aug 25, 2020
@lgrignon lgrignon added this to the 3.0.0 milestone Aug 25, 2020
@lgrignon
Copy link
Collaborator

lgrignon commented Aug 25, 2020

@regrog Even if Eclipse plugin is not officially supported yet with JSweet 3. It seems that you hit an intersting bug. Thanks for reporting.

@renaudpawlak I assume this was meant to be a PM? :)

@regrog
Copy link
Author

regrog commented Aug 26, 2020

Great!
I know that the Eclipse plugin is not officially supported but as it turned out I suspected that the bug is something else.
Thanks!

@lgrignon
Copy link
Collaborator

@regrog Could you please post here the code which caused this error
(myHome/myProject/src/main/java/myClass.java I guess)

@regrog
Copy link
Author

regrog commented Sep 1, 2020

Well...I can't replicate on my own but one of my colleague can...
I recently reset my PC and tried to reproduce the error from the git repo I have but it's impossible..
Now the transpilation seems to work normally but I can't figure out how.
These are the classes to transpile:
main class

public class IsAccTraIdSettedCondition extends BooleanCondition {

	@Override
	public boolean evaluate(final ExecutionContext context) {

		return !context.isVariableEmpty("accounting_transaction_id");
	}
}
public abstract class BooleanCondition {
	public native boolean evaluate(ExecutionContext context);
}
public interface ExecutionContext {
	public boolean isVariableEmpty(String variableName);
}

Tomorrow I will try to understand more

@lgrignon
Copy link
Collaborator

lgrignon commented Sep 1, 2020

Thanks for your reply.

If you try again, please start from this branch:
https://github.com/cincheo/jsweet/commits/JSweet3.0-moduleInfo

Many errors have been fixed recently

@regrog
Copy link
Author

regrog commented Sep 2, 2020

Can you please publish a new RC for jsweet 3.0.0 so I can include it in my project?
Thanks

@lgrignon
Copy link
Collaborator

lgrignon commented Sep 8, 2020

Absolutely.

We are currently doing a lot of stabilisation work on JSweet 3. I will publish it right after

@lgrignon
Copy link
Collaborator

lgrignon commented Sep 8, 2020

Hello again @regrog
3.0.0-RC4 has been deployed (and maven plugin is up to date)
Warning : if you declare jsweet-core as a dependency, groupId is now <groupId>org.jsweet.v3</groupId>

I hope it will work for you

@regrog
Copy link
Author

regrog commented Sep 11, 2020

Hello @lgrignon
I figured out the problem!
my colleagues are using nodejs 8.1.2
I'm using nodejs 10.22.0 after I reinstalled it on my machine.
I'm going to do more tests next week and close this issue if everything is ok.

@lgrignon
Copy link
Collaborator

Thanks @regrog !

@lgrignon
Copy link
Collaborator

3.0.0-RC5 is deployed, if you test please do it on this version.
groupId is org.jsweet.v3 for almost all artifacts now (please see pom.xml & build.gradle here: https://github.com/cincheo/jsweet-examples)

@regrog
Copy link
Author

regrog commented Sep 16, 2020

Actually the test is not going anywhere...
We have different errors in windows but in Linux it works...
keep searching what is not working properly.
Can you tell me what's your jdk and which version of node are you using?
Thanks

@lgrignon
Copy link
Collaborator

Oh, shoot

I use Node 12.18.3
but I know for sure it's working with 10.16.0 (so I guess LTS 10.22.1 is ok too)
JDK is 11.0.4 but I think any JDK 11 will be ok.
Please I would be glad to read any information you have about this because I didn't think node version (>= 10) could be a problem.

See you soon.
Bye

@lgrignon
Copy link
Collaborator

Hello @regrog Did you find time to investigate further?

@regrog
Copy link
Author

regrog commented Oct 6, 2020

Hi sorry for the delay but this thing is really annoying me...
I have trouble reproducing this in different systems and I'm really busy during these months 😢

@lgrignon
Copy link
Collaborator

lgrignon commented Oct 8, 2020

No problem, there is no rush. I just want to understand what's going on because this is the only repro I have for this problem.
Given the original error, it might come from the JDK variant installed? Oracle vs openjdk?
Are all your machines running the same JDK?

@regrog
Copy link
Author

regrog commented Oct 9, 2020

Yes we are using the same JDK: https://adoptopenjdk.net/
The strange thing is that I created our environment in both Linux and windows and I managed to get it to work BUT when my colleagues try do replicate the same env with the same jdk, nodejs and jsweet...they have different errors...
I think this is something not connected to jsweet but I can't prove that so far.

@lgrignon
Copy link
Collaborator

I am looking forward to learn more about this. It could reveal some unexpected problems.
Please keep us informed if you make progress :)
Thanks for your time & interest for JSweet

@lgrignon lgrignon removed this from the 3.0.0 milestone Nov 11, 2020
@lgrignon
Copy link
Collaborator

lgrignon commented Jan 6, 2021

Hey. Did you find time to try again? :)
FYI you can now use 3.1.0-SNAPSHOT

@regrog
Copy link
Author

regrog commented Jan 15, 2021

Not yet sorry.
The time is always short.
I'm updating and trying each release and java 11 but without good results.
I hope to debug the issue soon next month 🤞

@regrog
Copy link
Author

regrog commented Jan 18, 2021

Maybe this can be useful for some debug or improvement. This warning shows up in console (on a working machine):

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.jsweet.transpiler.util.Util (file:/home/myHome/myProject/org.jsweet.plugin/lib/jsweet-transpiler-3.1.0-SNAPSHOT.jar) to field com.sun.tools.javac.tree.JCTree.type
WARNING: Please consider reporting this to the maintainers of org.jsweet.transpiler.util.Util
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

@lgrignon
Copy link
Collaborator

Thanks.
I am sorry but it's unfortunately irrelevant here, those are only warnings to tell that some reflective accesses are unsafe, but it works on multiple JDK versions.
I hope we will find more clues to get you out of troubles.

@regrog
Copy link
Author

regrog commented Jan 19, 2021

Maybe the warning can lead to somethings.
It says that in org.jsweet.transpiler.util.Util there is an illegal reflective access.
Can this have different behavior in JDK in different platforms? (I'm using jdk-11.0.9.1+1 https://adoptopenjdk.net/)

The stack trace is changed with the latest jdk 11 and the 3.1.0-SNAPSHOT

java.lang.RuntimeException: Cannot call internal Javac API 🙁 please adapt this code if API changed
at org.jsweet.transpiler.util.Util.erasureRecursive(Util.java:2375)
at org.jsweet.transpiler.OverloadScanner$Overload.hasMethodType(OverloadScanner.java:371)
at org.jsweet.transpiler.OverloadScanner$Overload.safeAdd(OverloadScanner.java:388)
at org.jsweet.transpiler.OverloadScanner$Overload.register(OverloadScanner.java:478)
at org.jsweet.transpiler.OverloadScanner.processMethod(OverloadScanner.java:551)
at org.jsweet.transpiler.OverloadScanner.visitClass(OverloadScanner.java:523)
at org.jsweet.transpiler.OverloadScanner.visitClass(OverloadScanner.java:69)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:808)
at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
at org.jsweet.transpiler.util.AbstractTreeScanner.scan(AbstractTreeScanner.java:279)
at org.jsweet.transpiler.util.AbstractTreeScanner.scan(AbstractTreeScanner.java:65)
at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:105)
at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:113)
at jdk.compiler/com.sun.source.util.TreeScanner.visitCompilationUnit(TreeScanner.java:144)
at org.jsweet.transpiler.OverloadScanner.visitCompilationUnit(OverloadScanner.java:563)
at org.jsweet.transpiler.OverloadScanner.visitCompilationUnit(OverloadScanner.java:69)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:591)
at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
at org.jsweet.transpiler.util.AbstractTreeScanner.scan(AbstractTreeScanner.java:279)
at org.jsweet.transpiler.OverloadScanner.process(OverloadScanner.java:574)
at org.jsweet.transpiler.JSweetTranspiler.generateTsFiles(JSweetTranspiler.java:916)
at org.jsweet.transpiler.JSweetTranspiler.java2ts(JSweetTranspiler.java:898)
at org.jsweet.transpiler.JSweetTranspiler.transpile(JSweetTranspiler.java:821)
at org.jsweet.transpiler.JSweetTranspiler.transpile(JSweetTranspiler.java:779)
at org.jsweet.plugin.builder.JSweetBuilderJob.transpileFiles(JSweetBuilderJob.java:295)
at org.jsweet.plugin.builder.JSweetBuilderJob.run(JSweetBuilderJob.java:124)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.jsweet.transpiler.util.Util.erasureRecursive(Util.java:2373)
... 26 more

@lgrignon
Copy link
Collaborator

This stacktrace is interesting. This should not happen.
Can you reproduce on multiple machines with the same JDK? If so, please send here JDK version, I will try to reproduce.
Can you please also try to narrow down the transpiled Java source code that caused this issue?

Thanks for your efforts on this :)

@regrog
Copy link
Author

regrog commented Jan 24, 2021

Beware that JSweetBuilderJob is something we created to run in eclipse plugin. We basically duplicated the JSweetBuilder to use as a job in eclipse because we use that on multiple projects.
I'm thinking to make a PR on you jsweet-eclipse-plugin with our improvements if can help you more.
I'm also working in a simple example but I need to test on my team mate pc.

@regrog
Copy link
Author

regrog commented Jan 24, 2021

Ok, I hope this can help a bit and maybe you can merge my PR.
cincheo/jsweet-eclipse-plugin#30

@lgrignon
Copy link
Collaborator

lgrignon commented Jan 25, 2021

Are you saying that you do not face this error with jsweet maven plugin for instance?
Are you sure you start Eclipse with JDK >= 11? Is adoptjdk used to start Eclipse itself?

@regrog
Copy link
Author

regrog commented Jan 25, 2021

Are you sure you start Eclipse with JDK >= 11? Is adoptjdk used to start Eclipse itself?

I'm 110% sure eclipse is started with jdk >= 11 as you can see the stacktrace shows java modules and I only have java 8 or java 11 on my machine.
The adopted jdk is used to start eclipse.

Are you saying that you do not face this error with jsweet maven plugin for instance?

I only used jsweet from the eclipse plugin, I will provide an example as soon as I can not using the plugin but the gradle/maven plugin.

@lgrignon
Copy link
Collaborator

Hello. I noticed your PR on the gradle plugin :) Did you give it a try for your project?

@regrog
Copy link
Author

regrog commented Jan 27, 2021

Yes, I'm trying to use the gradle plugin to create a sample to test on other machines.
Actually I'm having some strange issue because sometimes ./gradlew jsweet generates the folder generated_js but sometimes doesn't.
I hope to have some news soon this week 💪

@regrog
Copy link
Author

regrog commented Jan 29, 2021

lgrignon/jsweet-gradle-plugin#32
Recap:
I tried my sample project with jdk 11 in a windows machine and everything works fine. But the example project is really skinny.
I'm starting to think the problem is something that comes from the classpath I pass to the transpiler.

@niktekusho
Copy link

Hi, I am the colleague with the "problematic" environment. 😄

We managed to find some time to go a bit deeper into this problem, and I'm sorry to report that I still encounter the issue with the eclipse plugin.

To streamline everything and see if we were doing something wrong, we decided to:

  1. use the eclipse plugin (org.jsweet.plugin) from the GitHub repo without modifications: fork link
  2. create a simple Gradle project without the needs for external jars (attached in the comment as a zip file)
  3. use ad RCP eclipse in debug mode with the plugin sources to capture any meaningful details

Jsweet runs fine on the same project when using the Gradle plugin, but I get the error reported above with org.jsweet.plugin (eclipse plugin).
We even tried to replicate the same parameters for the Jsweet transpiler across the Gradle plugin and org.jsweet.plugin without success.

We debugged into the org.jsweet.transpiler.util.Util class and found some bizarre things: at

return (TypeMirror) erasureRecursiveMethod.invoke(javacInternals().typesInstance, type);

erasureRecursiveMethod's declaring class is not assignable to the javacInternals().typesInstance's class (see attached screenshot).

breakpoint-evaluations

Breakpoint's screenshot from the jsweet-transpiler 3.0.0 sources:
debug-breakpoint

The strangest thing, though, is that the "same" type com.sun.tools.javac.code.Types differ "only" from classloader: the erasureRecursiveMethod declaring class uses the eclipse OSGi classloader implementation, while the javacInternals().typesInstance's class is using the standard JDK 11 classloader.

We believe this is the cause of the issue we encounter with the eclipse plugin. In the instances where org.jsweet.plugin ran fine, we found that the classloaders used were the same JDK 11 classloader.
Do you think this could relate to the issues we're having? Is there anything we could try to do on the Eclipse plugin side to ensure the classloaders are consistent?

Sample project: example.zip

Java runtime info:
java-version

@lgrignon
Copy link
Collaborator

lgrignon commented Apr 10, 2021

Thanks a lot @niktekusho for your time on this, and your explanation

I just deployed this commit 5a81ff7 which in our opinion could fix your problem.

Could you please try again with latest 3.1.0-SNAPSHOT? Let's cross fingers 🤞

@regrog
Copy link
Author

regrog commented Apr 14, 2021

Still something not working ;(

 java.lang.RuntimeException: Cannot call internal Javac API :( please adapt this code if API changed
        at org.jsweet.transpiler.util.Util.erasureRecursive(Util.java:2278)
        at org.jsweet.transpiler.OverloadScanner$Overload.hasMethodType(OverloadScanner.java:371)
        at org.jsweet.transpiler.OverloadScanner$Overload.safeAdd(OverloadScanner.java:388)
        at org.jsweet.transpiler.OverloadScanner$Overload.register(OverloadScanner.java:475)
        at org.jsweet.transpiler.OverloadScanner.processMethod(OverloadScanner.java:548)
        at org.jsweet.transpiler.OverloadScanner.visitClass(OverloadScanner.java:520)
        at org.jsweet.transpiler.OverloadScanner.visitClass(OverloadScanner.java:69)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:808)
        at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
        at org.jsweet.transpiler.util.AbstractTreeScanner.scan(AbstractTreeScanner.java:279)
        at org.jsweet.transpiler.util.AbstractTreeScanner.scan(AbstractTreeScanner.java:65)
        at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:105)
        at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:113)
        at jdk.compiler/com.sun.source.util.TreeScanner.visitCompilationUnit(TreeScanner.java:144)
        at org.jsweet.transpiler.OverloadScanner.visitCompilationUnit(OverloadScanner.java:560)
        at org.jsweet.transpiler.OverloadScanner.visitCompilationUnit(OverloadScanner.java:69)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:591)
        at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
        at org.jsweet.transpiler.util.AbstractTreeScanner.scan(AbstractTreeScanner.java:279)
        at org.jsweet.transpiler.OverloadScanner.process(OverloadScanner.java:571)
        at org.jsweet.transpiler.JSweetTranspiler.generateTsFiles(JSweetTranspiler.java:923)
        at org.jsweet.transpiler.JSweetTranspiler.java2ts(JSweetTranspiler.java:905)
        at org.jsweet.transpiler.JSweetTranspiler.transpile(JSweetTranspiler.java:828)
        at org.jsweet.transpiler.JSweetTranspiler.transpile(JSweetTranspiler.java:786)
        at org.jsweet.plugin.builder.JSweetBuilderJob.transpileFiles(JSweetBuilderJob.java:307)
        at org.jsweet.plugin.builder.JSweetBuilderJob.run(JSweetBuilderJob.java:132)
        at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.jsweet.transpiler.util.Util.erasureRecursive(Util.java:2276)
        ... 26 more

@regrog
Copy link
Author

regrog commented Aug 26, 2021

Hi
I recently started again to work on this problem.
After more test, we decided to switch to the Gradle plugin to avoid this behavior.
I think this issue could be closed.

@lgrignon
Copy link
Collaborator

Thanks for the update

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

No branches or pull requests

4 participants