Programmers working on Java programs are aware of the error thrown to them when compiling long codes. There is no such error that can’t be solved. When you are working on Java, you may encounter “java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment” error warning, which obviously seems like a challenging issue to fix.
You don’t need to worry about the error as we are here to guide you about the error and what measures you can take to get rid of the error. First, have a look at the error thrown when you code
How error warning comes up?
When you try to use the Lombok plugin in order to generate getters and setters for a specific category’s area. As soon as you do it, you end up with an error warning.
java: java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment
Now, let’s figure out how to solve it.
Solutions to Tackle “java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment”
Solution 1 – Use Lombok (@Data)
You can solve the error warning using Lombok class @Data. Take the below example as a reference and implement the same technique in your code
import lombok.Data;
@Data
public class Ingredient {
private final String id;
private final String name;
private final Type type;
public enum Type {
WRAP, PROTEIN, VEGGIES, CHEESE, SAUCE
}
}
Or
Try the Pseudo Code
@Getter @Setter
@RequiredArgsConstructor
@ToString
@EqualsAndHashCode
public class User1 {
private Long id;
private String username;
}
Solution 2 – Update Lombok Version
Another solution to fix the error is to update the version of Lombok to 1.18.20. For this, use the below code
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
</dependency>
Solution 3 – Downgrade the Java version
If updating the Lombok version doesn’t work, you need to downgrade the Java version from 16 to 15. The downgrading of the version works. In this way, the error can be removed.
Solution 4 – Install the pom.xml Plugin
Another solution to fix the error warning, you need to install a plugin. This is one of the effective solution to get rid of the “java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment” error warning. Take a look at the plugin code
<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
In this article, we have shed light on the solutions to fix “java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment”. Different solutions are discussed so that you can successfully get rid of the error and code the way you want without any interruption.
I hope the solutions can be helpful for you! Don’t forget to drop a message below to share your opinion!