. Advertisement .
..3..
. Advertisement .
..4..
We are applying Lombok Plugin to simplify getter and setter, but encounter java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment instead.
We intend to discuss it thoroughly and immediately as it can be a difficult issue. So, let’s jump right in!
How Does The Error Occur?
We are attempting to apply the Lombok plugin to generate getters/setters for areas of a specific category. But when we do so, we are surprised by this error.
java: java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment
How To Fix “java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment” Error?
To resolve the error, you should update Lombok to the 1.18.20 version. The second solution is you may downgrade from Java 16 to Java 15, and the error will disappear. You can clearly see the processing steps below:
Solution 1
For the first solution, you need to update Lombok to version 1.18.20.
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
</dependency>
Solution 2
In our situation, the error remained unsolved in Java 16. So, our second solution is to downgrade it to Java 15, and the error disappears.
Solution 3: Using Lombok @Data
You can refer to the code below:
@Getter @Setter
@RequiredArgsConstructor
@ToString
@EqualsAndHashCode
public class User1 {
private Long id;
private String username;
}
Solution 4:
Also, another method to handle the error is that you can install a plugin to pom.xml, like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>16</source>
<target>16</target>
<!-- <release>16</release>-->
<fork>true</fork>
<compilerArgs>
<arg>--enable-preview</arg>
<arg>-Xlint:all</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED</arg>
</compilerArgs>
<!--for unmappable characters in classes-->
<encoding>UTF-8</encoding>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<!--for lombok annotations to resolve-->
<!--contradictory to maven, intelliJ fails with this-->
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.16</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
Conclusion
Our article should have demonstrated the most valid solutions to the java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment error.
If you happen to come up with any thoughts about this problem or require additional assistance, please discuss them with us in the chat. Thank you for your time!
Leave a comment