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] lombok 1.8.26 incompatible with JDK21 #3393

Closed
jnaalisv opened this issue Apr 3, 2023 · 54 comments · Fixed by #3473
Closed

[BUG] lombok 1.8.26 incompatible with JDK21 #3393

jnaalisv opened this issue Apr 3, 2023 · 54 comments · Fixed by #3473
Assignees
Milestone

Comments

@jnaalisv
Copy link

jnaalisv commented Apr 3, 2023

Describe the bug
Lombok 1.8.26 does not work with JDK21 (EA build 16)

To Reproduce

import lombok.Data;

@Data
public class Person {

    private String name;
}
$ javac -version
javac 21-ea
$ javac -cp lombok-1.18.26.jar Person.java

will fail with this error:

An annotation processor threw an uncaught exception.
Consult the following stack trace for details.
java.lang.NoSuchFieldError: Class com.sun.tools.javac.tree.JCTree$JCImport does not have member field 'com.sun.tools.javac.tree.JCTree qualid'
	at lombok.javac.JavacImportList.getFullyQualifiedNameForSimpleNameNoAliasing(JavacImportList.java:53)
	at lombok.core.TypeResolver.typeRefToFullyQualifiedName(TypeResolver.java:60)
	at lombok.javac.HandlerLibrary.handleAnnotation(HandlerLibrary.java:247)
	at lombok.javac.JavacTransformer$AnnotationVisitor.visitAnnotationOnType(JavacTransformer.java:79)
	at lombok.javac.JavacNode.traverse(JavacNode.java:132)
	at lombok.javac.JavacAST.traverseChildren(JavacAST.java:222)
	at lombok.javac.JavacNode.traverse(JavacNode.java:95)
	at lombok.javac.JavacAST.traverseChildren(JavacAST.java:222)
	at lombok.javac.JavacNode.traverse(JavacNode.java:90)
	at lombok.javac.JavacAST.traverse(JavacAST.java:218)
	at lombok.javac.JavacTransformer.transform(JavacTransformer.java:63)
	at lombok.javac.apt.LombokProcessor.process(LombokProcessor.java:328)
	at lombok.core.AnnotationProcessor$JavacDescriptor.process(AnnotationProcessor.java:187)
	at lombok.core.AnnotationProcessor.process(AnnotationProcessor.java:241)
	at lombok.launch.AnnotationProcessorHider$AnnotationProcessor.process(AnnotationProcessor.java:90)
	at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:1017)
	at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:933)
	at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1261)
	at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1376)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1252)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:934)
	at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:317)
	at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:176)
	at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:64)
	at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:50)

Expected behavior
Lombok should work with JDK21

Version info:

  • Lombok 1.8.26
  • Platform javac 21-ea, build 16
@jnaalisv
Copy link
Author

jnaalisv commented Apr 5, 2023

I probably should have opened this as a "Feature Request"?

@Rawi01
Copy link
Collaborator

Rawi01 commented Apr 5, 2023

Whether you consider this a bug or a feature is debatable. In any case, thanks for creating it.

@kangarko
Copy link

kangarko commented Apr 8, 2023

@Rawi01 is lombok compatible with Java 20? Last changelog only mentions JDK 19

@dstango
Copy link

dstango commented Apr 8, 2023

@kangarko #3353

@kangarko
Copy link

kangarko commented Apr 9, 2023

My apologies, I have missed that!

@SimSonic
Copy link

Very slow release cycle for 20 and 19 Java versions. I understand that odd versions are interpreted as cutting edge and even as stable, but maybe we need to split releases which adds only support for new Java releases and feature-rich releases?

ascopes added a commit to ascopes/java-compiler-testing that referenced this issue May 6, 2023
ascopes added a commit to ascopes/java-compiler-testing that referenced this issue May 6, 2023
@jnaalisv
Copy link
Author

When can we expect the fix to be integrated? I just tested with the latest build (21.ea.26-open) and it fails with the same stacktrace. That build is now feature complete, so there should not be any big changes before the GA release in September.

@Rawi01
Copy link
Collaborator

Rawi01 commented Jun 19, 2023

There are some more failing tests using the latest ea build. I will try to fix that this week,

@NotArchon
Copy link

Any workarounds?

@evantoli
Copy link

Just wondering if there is any news on this or any workarounds?

@matthiasblaesing
Copy link

This is also a problem for NetBeans, which builds on top of javac and no renders all lombok using classes as broken.

@Rawi01
Copy link
Collaborator

Rawi01 commented Aug 2, 2023

You can use my jdk21 branch or download the ci build artifact if you really need to use JDK21 now.

@estekhin
Copy link

estekhin commented Aug 4, 2023

@Rawi01 please release a central version with these changes.

I tried edge snapshot from https://projectlombok.org/download-edge locally with JDK 21 ea b34, and my code base builds and passes tests - thanks a lot for the fix!

I would like to use it in CI builds that run against Java 21 EA, but i can't due to constraints on which repositories i can use there.

@dgcooke
Copy link

dgcooke commented Aug 24, 2023

I am finding even with the edge version I am still getting the same result,

java.lang.NoSuchFieldError: Class com.sun.tools.javac.tree.JCTree$JCImport does not have member field 'com.sun.tools.javac.tree.JCTree qualid'

openjdk version "21" 2023-09-19
OpenJDK Runtime Environment (build 21+35-2513)
OpenJDK 64-Bit Server VM (build 21+35-2513, mixed mode, sharing)

@alison-gravley
Copy link

I just wanted to throw in with this. Java 21 and eventually 22 will be VERY important to me and my team as we are starting to use Panama for our projects, which will be out of pre-release starting in Java 22 (March 2024).

I was able to get past the error above, once I included the repository and changed to the edge release, but this came up.

Compilation failure
  on the class path. A future release of javac may disable annotation processing
  unless at least one processor is specified by name (-processor), or a search
  path is specified (--processor-path, --processor-module-path), or annotation
  processing is enabled explicitly (-proc:only, -proc:full).
  Use -Xlint:-options to suppress this message.
  Use -proc:none to disable annotation processing.

Here are the changes I made to my pom.xml to get it to compile again. For some reason I had to specifically add the org.slf4j dependency as well to get things to work.

<project ...>
...
    <repositories>
        <repository>
            <id>projectlombok.org</id>
            <url>https://projectlombok.org/edge-releases</url>
        </repository>
    </repositories>
...
    <dependencies>
...
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>2.0.7</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>edge-SNAPSHOT</version>
        </dependency>
    </dependencies>
...
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven.compilerplugin.version}</version>
                <configuration>
                    <source>21</source>
                    <target>21</target>
                    <enablePreview>true</enablePreview>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                            <version>edge-SNAPSHOT</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>
            ...
        </plugins>
    </build>
...
</project>

@Rawi01
Copy link
Collaborator

Rawi01 commented Aug 24, 2023

The message about annotation processing was backported to 21 but should not break the compilation, it is only a warning and it disappears if you add lombok as explicit annotation processor (as you did).

Slf4j is not required for lombok and it should not change anything expect you @Slf4j somewhere in your code.

You should also add <scope>provided</scope> to the lombok dependency in your pom.xml to not include it at runtime.

@dgcooke
Copy link

dgcooke commented Aug 24, 2023

I am finding even with the edge version I am still getting the same result,

java.lang.NoSuchFieldError: Class com.sun.tools.javac.tree.JCTree$JCImport does not have member field 'com.sun.tools.javac.tree.JCTree qualid'

openjdk version "21" 2023-09-19 OpenJDK Runtime Environment (build 21+35-2513) OpenJDK 64-Bit Server VM (build 21+35-2513, mixed mode, sharing)

This is resolved using edge-SNAPSHOT, I had missed the annotation processor


org.projectlombok
lombok
${lombok.version}

StenAL added a commit to StenAL/Baltic-stocks that referenced this issue Oct 21, 2023
Major features can be found here: https://advancedweb.hu/a-categorized-list-of-all-java-and-jvm-features-since-jdk-8-to-21/

Required companion upgrades:
  - Gradle 8.0.2 -> 8.4, see https://docs.gradle.org/8.4/userguide/upgrading_version_8.html for changes
  - Lombok 1.18.24 -> 1.18.30, see projectlombok/lombok#3393
  - Spring Boot 3.0.1 -> 3.1.4 to support new version of Lombok, see https://stackoverflow.com/a/77171271
StenAL added a commit to StenAL/Baltic-stocks that referenced this issue Oct 21, 2023
Major features can be found here: https://advancedweb.hu/a-categorized-list-of-all-java-and-jvm-features-since-jdk-8-to-21/

Required companion upgrades:
  - Gradle 8.0.2 -> 8.4, see https://docs.gradle.org/8.4/userguide/upgrading_version_8.html for changes
  - Lombok 1.18.24 -> 1.18.30, see projectlombok/lombok#3393
  - Spring Boot 3.0.1 -> 3.1.4 to support new version of Lombok, see https://stackoverflow.com/a/77171271
@youngclown
Copy link

youngclown commented Nov 2, 2023

implementation 'org.projectlombok:lombok:1.18.30'
annotationProcessor 'org.projectlombok:lombok:1.18.30'

Adding it solved the problem.

@mohssinassel
Copy link

to solve it follow those steps in this web site
https://projectlombok.org/download-edge

@Romulo-S
Copy link

Fixed by updating springboot to 3.1.4.

The error should be more friendly tough.

https://stackoverflow.com/questions/77171270/compilation-error-after-upgrading-to-jdk-21-nosuchfielderror-jcimport-does-n

0x131315 added a commit to 0x131315/hikvision-download-assistant that referenced this issue Dec 5, 2023
odysseus654 added a commit to odysseus654/comixed that referenced this issue Jan 5, 2024
Attempting to compile this under JDK 21 resulted in the following error:
Class com.sun.tools.javac.tree.JCTree$JCImport does not have member field 'com.sun.tools.javac.tree.JCTree qualid'

This error is in the Lombok library and was resolved in v1.18.30:
projectlombok/lombok#3393

This project uses the latest version of Lombok which is compatible
with JDK 21, however it also uses Spring Boot which has its own
dependency which is to a specific version of JDK.

This patch updates the version of Lombok specified to be the minimum
version supported by JDK 21.  The result compiles, but I have not done
significant testing of the result (yet) to ensure there are no latent
issues.

Related Stack Overflow discussion:
https://stackoverflow.com/questions/77171270/compilation-error-after-upgrading-to-jdk-21-nosuchfielderror-jcimport-does-n
odysseus654 added a commit to odysseus654/comixed that referenced this issue Feb 12, 2024
]

Attempting to compile this under JDK 21 resulted in the following error:
Class com.sun.tools.javac.tree.JCTree$JCImport does not have member field 'com.sun.tools.javac.tree.JCTree qualid'

This error is in the Lombok library and was resolved in v1.18.30:
projectlombok/lombok#3393

This project uses the latest version of Lombok which is compatible
with JDK 21, however it also uses Spring Boot which has its own
dependency which is to a specific version of JDK.

This patch updates the version of Lombok specified to be the minimum
version supported by JDK 21.  The result compiles, but I have not done
significant testing of the result (yet) to ensure there are no latent
issues.

Related Stack Overflow discussion:
https://stackoverflow.com/questions/77171270/compilation-error-after-upgrading-to-jdk-21-nosuchfielderror-jcimport-does-n
mcpierce pushed a commit to comixed/comixed that referenced this issue Feb 12, 2024
Attempting to compile this under JDK 21 resulted in the following error:
Class com.sun.tools.javac.tree.JCTree$JCImport does not have member field 'com.sun.tools.javac.tree.JCTree qualid'

This error is in the Lombok library and was resolved in v1.18.30:
projectlombok/lombok#3393

This project uses the latest version of Lombok which is compatible
with JDK 21, however it also uses Spring Boot which has its own
dependency which is to a specific version of JDK.

This patch updates the version of Lombok specified to be the minimum
version supported by JDK 21.  The result compiles, but I have not done
significant testing of the result (yet) to ensure there are no latent
issues.

Related Stack Overflow discussion:
https://stackoverflow.com/questions/77171270/compilation-error-after-upgrading-to-jdk-21-nosuchfielderror-jcimport-does-n
rkosegi added a commit to olamy/hetzner-cloud-plugin that referenced this issue May 23, 2024
There is error during compilation while running under JDK21:

java.lang.NoSuchFieldError: Class com.sun.tools.javac.tree.JCTree$JCImport does not have member field 'com.sun.tools.javac.tree.JCTree qualid'

Following advice from projectlombok/lombok#3393 seems to fix the issue

Signed-off-by: Richard Kosegi <richard.kosegi@gmail.com>
rkosegi added a commit to jenkinsci/hetzner-cloud-plugin that referenced this issue May 23, 2024
There is error during compilation while running under JDK21:

java.lang.NoSuchFieldError: Class com.sun.tools.javac.tree.JCTree$JCImport does not have member field 'com.sun.tools.javac.tree.JCTree qualid'

Following advice from projectlombok/lombok#3393 seems to fix the issue

Signed-off-by: Richard Kosegi <richard.kosegi@gmail.com>
@Rohan-Rathod
Copy link


4.0.0

org.springframework.boot
spring-boot-starter-parent
3.3.2


com.example
dettol
0.0.1-SNAPSHOT
dettol
Demo project for Spring Boot














<java.version>17</java.version>




org.springframework.boot
spring-boot-starter-data-jpa


org.springframework.boot
spring-boot-starter-web



mysql
mysql-connector-java
8.0.28



org.projectlombok
lombok
1.18.24

	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-test</artifactId>
		<scope>test</scope>
	</dependency>
</dependencies>


<build>
	<plugins>
		<plugin>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-maven-plugin</artifactId>
		</plugin>
	</plugins>
</build>

@Rohan-Rathod
Copy link

//getting these below error while running above code

java: java.lang.NoSuchFieldError: Class com.sun.tools.javac.tree.JCTree$JCImport does not have member field 'com.sun.tools.javac.tree.JCTree qualid'

@Renas63
Copy link

Renas63 commented Aug 6, 2024

Getting this error
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.13.0:testCompile (default-testCompile) on project HE Automation: Fatal error compiling: java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor (in unnamed module @0x21e97905) cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.processing to unnamed module @0x21e97905 -> [Help 1]
Any help will be appreciated!

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.