openrewrite / rewrite

Automated mass refactoring of source code.
https://docs.openrewrite.org
Apache License 2.0
2.21k stars 330 forks source link

`org.openrewrite.java.migrate.jakarta.JavaxMigrationToJakarta` crashes with `java.lang.LinkageError` #3416

Open iuliiasobolevska opened 1 year ago

iuliiasobolevska commented 1 year ago

What version of OpenRewrite are you using?

I was using:

see linkageerror_stacktrace_original.txt

then tried to update to the latest:

but it actually got worse - linkageerror_stacktrace_after_upgrade.txt

How are you running OpenRewrite?

Gradle plugin, multimodule project.

What is the smallest, simplest way to reproduce the problem?

TBD. My best guess right now is that it's somehow related to lombok usage (one of the stacktraces pointed to the lombok annotation line).

timtebeek commented 1 year ago

Welcome back & thanks for reporting this in such detail! Some general questions and remarks below until someone else chimes in with more insightful comments.

Out of curiosity: what version of Java are you running?

For the latest versions it looks like you might be missing a dependency on rewrite-java-17. Not sure why, as I'd assume that to be available as a transient dependency. Does it help to add that explicitly?

There's also been a new release of the gradle plugin; the latest is now 6.1.16.

If none of the above help, then how much of your Gradle build file are you able to share?

iuliiasobolevska commented 1 year ago

Hi Tim!

Welcome back

Thank you and sorry for being on and off!

Out of curiosity: what version of Java are you running?

17.0.6-zulu

For the latest versions it looks like you might be missing a dependency on rewrite-java-17. Not sure why, as I'd assume that to be available as a transient dependency. Does it help to add that explicitly?

Updated to org.openrewrite:plugin:6.1.16, added rewrite("org.openrewrite:rewrite-java-17:8.1.8") and still the same: linkageerror_stacktrace_2.txt

If none of the above help, then how much of your Gradle build file are you able to share?

We use Nebula with internal plugins and abstractions so there is not much in the build.gradle files. On top of that this repo is massive (data bridge for each datastore + Netflix DGS) which doesn't help with figuring out the minimal repo to repro issue.

My earlier assumption about lombok might be totally off - I tried on a demo project created with initializr and a couple of internal ones and it worked fine.

Let me poke around it a bit more. Logged it more like a placeholder.

timtebeek commented 1 year ago

Hi @iuliiasobolevska ; any update to your explorations there? We keep all items on a board here and try to track progress; with this one I'm wondering if there's any next step we can take to get this resolved.

timtebeek commented 1 year ago

I hope you don't mind me closing this issue, as we're having an issue to replicate this without more details. Feel free to chime back in when you have more details to share using the latest versions!

iuliiasobolevska commented 1 year ago

Hey! Sorry, was OOO for 3 weeks.

I got the LinkageError today again on a different single-module project. Stacktrace is slightly different this time.

Versions:

Stacktrace:

Caused by: java.lang.IllegalStateException: Unable to construct Java17Parser.
        at org.openrewrite.java.Java17Parser$Builder.build(Java17Parser.java:96)
        at org.openrewrite.java.Java17Parser$Builder.build(Java17Parser.java:63)
        at org.openrewrite.gradle.isolated.DefaultProjectParser.lambda$parse$7(DefaultProjectParser.java:688)
        at org.openrewrite.gradle.isolated.DefaultProjectParser.listResults(DefaultProjectParser.java:1007)
        at org.openrewrite.gradle.isolated.DefaultProjectParser.run(DefaultProjectParser.java:397)
        at org.openrewrite.gradle.DelegatingProjectParser.lambda$run$2(DelegatingProjectParser.java:100)
        at org.openrewrite.gradle.DelegatingProjectParser.unwrapInvocationException(DelegatingProjectParser.java:147)
        ... 119 more
Caused by: java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at org.openrewrite.java.Java17Parser$Builder.build(Java17Parser.java:92)
        ... 125 more
Caused by: java.lang.LinkageError: loader constraint violation: loader 'platform' wants to load interface javax.lang.model.type.TypeMirror. A different interface with the same name was previously loaded by org.openrewrite.gradle.RewriteClassLoader @35907719. (javax.lang.model.type.TypeMirror is in unnamed module of loader org.openrewrite.gradle.RewriteClassLoader @35907719, parent loader org.gradle.internal.classloader.VisitableURLClassLoader$InstrumentingVisitableURLClassLoader @3068f147)
        at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:821)
        at java.base/jdk.internal.loader.BuiltinClassLoader.findClassInModuleOrNull(BuiltinClassLoader.java:741)
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:665)
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
        at org.gradle.internal.classloader.FilteringClassLoader.loadClass(FilteringClassLoader.java:91)
        at org.gradle.internal.classloader.CachingClassLoader.loadClass(CachingClassLoader.java:56)
        at org.openrewrite.gradle.RewriteClassLoader.loadClass(RewriteClassLoader.java:64)
        at org.openrewrite.java.JavaUnrestrictedClassLoader.loadClass(JavaUnrestrictedClassLoader.java:93)
        at org.openrewrite.java.JavaUnrestrictedClassLoader.loadClass(JavaUnrestrictedClassLoader.java:86)
        at com.sun.tools.javac.util.AbstractDiagnosticFormatter.<init>(AbstractDiagnosticFormatter.java:534)
        at com.sun.tools.javac.util.BasicDiagnosticFormatter.<init>(BasicDiagnosticFormatter.java:76)
        at com.sun.tools.javac.util.JavacMessages.<init>(JavacMessages.java:95)
        at com.sun.tools.javac.util.JavacMessages.instance(JavacMessages.java:58)
        at com.sun.tools.javac.util.JCDiagnostic$Factory.<init>(JCDiagnostic.java:71)
        at com.sun.tools.javac.util.JCDiagnostic$Factory.instance(JCDiagnostic.java:61)
        at com.sun.tools.javac.util.Log.<init>(Log.java:319)
        at com.sun.tools.javac.util.Log.<init>(Log.java:256)
        at org.openrewrite.java.isolated.ReloadableJava17Parser$ResettableLog.<init>(ReloadableJava17Parser.java:290)
        at org.openrewrite.java.isolated.ReloadableJava17Parser.<init>(ReloadableJava17Parser.java:94)
        ... 129 more

I still struggle to get a demo app with the issue but this new stacktrace at least gives some clues on why it crashes.

timtebeek commented 1 year ago

Sorry to hear you're still having these issues! Thanks for the additional details; this is starting to sound like a complicated class loader issue. Would it be an option for this project to try again on Java 8 or 11 to see if that produces different results?

We're right in the middle of a big overhaul on how each of the plugins integrate the various parsers. That might also have an effect here, so keep an eye out for any 6.2.x or 7.x release of the Gradle plugin, expected somewhere in the next week(s).

iuliiasobolevska commented 1 year ago

Would it be an option for this project to try again on Java 8 or 11 to see if that produces different results?

that's an interested suggestion, I'm gonna try for an experimentation purposes but realistically we only run it on Java 17 projects because we only use it for Spring Boot 3 upgrade