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

Support JDK 20 and JDK 21 #177

Merged

Conversation

Stephan202
Copy link
Contributor

@Stephan202 Stephan202 commented Apr 28, 2023

This PR aims to resolve the following error when building with JDK 20 (which I hit while working on PicnicSupermarket/error-prone-support#603):

Jabel: initialized
An exception has occurred in the compiler (20.0.1). Please file a bug against the Java compiler via the Java bug reporting page (https://bugreport.java.com) after checking the Bug Database (https://bugs.java.com) for duplicates. Include your program, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.
java.lang.NoSuchFieldError: LAMBDA
	at jdk.compiler/com.sun.tools.javac.parser.JavacParser.checkSourceLevel(JavacParser.java:5073)
	at jdk.compiler/com.sun.tools.javac.parser.JavacParser.term2Rest(JavacParser.java:1002)
	at jdk.compiler/com.sun.tools.javac.parser.JavacParser.term2(JavacParser.java:957)
	at jdk.compiler/com.sun.tools.javac.parser.JavacParser.term1(JavacParser.java:925)
	at jdk.compiler/com.sun.tools.javac.parser.JavacParser.term(JavacParser.java:881)
	at jdk.compiler/com.sun.tools.javac.parser.JavacParser.term(JavacParser.java:861)
	at jdk.compiler/com.sun.tools.javac.parser.JavacParser.parseExpression(JavacParser.java:758)
	at jdk.compiler/com.sun.tools.javac.parser.JavacParser.parExpression(JavacParser.java:2554)
	at jdk.compiler/com.sun.tools.javac.parser.JavacParser.parseSimpleStatement(JavacParser.java:2808)
	at jdk.compiler/com.sun.tools.javac.parser.JavacParser.blockStatement(JavacParser.java:2656)
	at jdk.compiler/com.sun.tools.javac.parser.JavacParser.blockStatements(JavacParser.java:2593)
	at jdk.compiler/com.sun.tools.javac.parser.JavacParser.block(JavacParser.java:2563)
	at jdk.compiler/com.sun.tools.javac.parser.JavacParser.block(JavacParser.java:2577)
	at jdk.compiler/com.sun.tools.javac.parser.JavacParser.methodDeclaratorRest(JavacParser.java:4628)
	at jdk.compiler/com.sun.tools.javac.parser.JavacParser.classOrInterfaceOrRecordBodyDeclaration(JavacParser.java:4491)
	at jdk.compiler/com.sun.tools.javac.parser.JavacParser.classInterfaceOrRecordBody(JavacParser.java:4375)
	at jdk.compiler/com.sun.tools.javac.parser.JavacParser.classDeclaration(JavacParser.java:4077)
	at jdk.compiler/com.sun.tools.javac.parser.JavacParser.classOrRecordOrInterfaceOrEnumDeclaration(JavacParser.java:4024)
	at jdk.compiler/com.sun.tools.javac.parser.JavacParser.typeDeclaration(JavacParser.java:4013)
	at jdk.compiler/com.sun.tools.javac.parser.JavacParser.parseCompilationUnit(JavacParser.java:3856)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:634)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:611)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:671)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.parseFiles(JavaCompiler.java:1020)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler$InitialFileParser.parse(JavaCompiler.java:1940)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.parseFiles(JavaCompiler.java:1007)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:933)
	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:104)
	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.invocationHelper(JavacTaskImpl.java:152)
	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:100)
	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:94)
	at org.codehaus.plexus.compiler.javac.JavaxToolsCompiler.compileInProcess(JavaxToo

This PR also resolves the following error when using JDK 21:

Caused by: java.lang.IllegalArgumentException: Java 21 (65) is not supported by the current version of Byte Buddy which officially supports Java 20 (64) - update Byte Buddy or set net.bytebuddy.experimental as a VM property
    at net.bytebuddy.utility.OpenedClassReader.of(OpenedClassReader.java:96)
    at net.bytebuddy.dynamic.scaffold.TypeWriter$Default$ForInlining.create(TypeWriter.java:4011)
    at net.bytebuddy.dynamic.scaffold.TypeWriter$Default.make(TypeWriter.java:2224)
    at net.bytebuddy.dynamic.DynamicType$Builder$AbstractBase$UsingTypeWriter.make(DynamicType.java:4050)
    at net.bytebuddy.dynamic.DynamicType$Builder$AbstractBase.make(DynamicType.java:3734)
    at com.github.bsideup.jabel.JabelCompilerPlugin.lambda$static$0(JabelCompilerPlugin.java:91)
    at java.base/java.util.HashMap.forEach(HashMap.java:1429)
    at com.github.bsideup.jabel.JabelCompilerPlugin.<clinit>(JabelCompilerPlugin.java:84)
    ... 38 more

I hope that this change matches the spirit of what CheckSourceLevelAdvice is meant to do 🤞.

Suggested commit message:

Support JDK 20 and JDK 21 (#177)

From JDK 20 onwards the `LAMBDA` feature enum constant is no longer
recognized. Falling back to the `RECORDS` enum constant should guarantee
support for the next few JDK releases.

Upgrading Byte Buddy from 1.12.18 to 1.14.9 introduces Java 21 byte code
support.

@Stephan202
Copy link
Contributor Author

@bsideup would you have time to review this small PR?

I'd like to introduce this library in a project that (a.o.) builds against JDK 20 (see PicnicSupermarket/error-prone-support#603), but without these changes our build fails.

@rickie
Copy link

rickie commented Aug 10, 2023

It would help us enormously if this PR could be reviewed and merged 😄. Could you take a look at this? @bsideup

@NebelNidas
Copy link

At this point, it might be better to switch to https://github.com/RaphiMC/JavaDowngrader

@Stephan202
Copy link
Contributor Author

Tnx for sharing @NebelNidas! On cursory inspection of that project, it doesn't appear to provide a javac plugin, meaning that it can't "simply" be added to the annotationProcessorPaths of the maven-compiler-plugin. That's probably fixable, though.

@bsideup I'm sure you're super busy; if there's anything else we can do to get this merged/released (perhaps deferring review to another dev you trust with this task?), do let us know. ❤️

From JDK 20 onwards the `LAMBDA` feature enum constant is no longer
recognized. Falling back to the `RECORDS` enum constant should guarantee
support for the next few JDK releases.

Upgrading Byte Buddy from 1.12.18 to 1.14.9 introduces Java 21 byte code
support.
@Stephan202 Stephan202 changed the title Support JDK 20 Support JDK 20 and JDK 21 Oct 11, 2023
@Stephan202
Copy link
Contributor Author

Rebased and updated the PR (including the PR description). It turns out that JDK 21 compatibility also required upgrading Byte Buddy, so I added that to the change set. As best as I can tell this makes the plugin compatible with JDK 20 and JDK 21.

@bsideup bsideup merged commit 67e4018 into bsideup:master Oct 26, 2023
1 check passed
@Stephan202 Stephan202 deleted the improvement/jdk-20-support branch October 26, 2023 13:54
@bsideup
Copy link
Owner

bsideup commented Oct 26, 2023

Hi everyone! I apologize for missing this PR (thank you @asolntsev for the ping!). I just merged it and will release a new version ASAP.

@Stephan202 thank you for your contribution (and consistency!)

@Stephan202
Copy link
Contributor Author

Thanks for releasing version 1.0.1, @bsideup! I know Maven Central syncing can take a few hours, and that therefore release may not yet be visible here, but a direct download also yields an HTTP 404 response. Could it be that the artifacts have have yet to be published?

@Stephan202
Copy link
Contributor Author

Hey @bsideup! I see that the artifact is still not on Maven Central. Can you please have a look? 🙏

@Stephan202
Copy link
Contributor Author

^ @sergeykad just filed a separate issue for this: #182. (Tnx!)

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 this pull request may close these issues.

5 participants