13

I cloned this Project from Github

https://github.com/PacktPublishing/Java-Machine-Learning-for-Computer-Vision.git

I am going to use the FaceRecognizition from this project. But as soon as I try to run this in IntelliJ I get this error

java: java.lang.ExceptionInInitializerError Unable to make field private com.sun.tools.javac.processing.JavacProcessingEnvironment$DiscoveredProcessors com.sun.tools.javac.processing.JavacProcessingEnvironment.discoveredProcs accessible: module jdk.compiler does not "opens com.sun.tools.javac.processing" to unnamed module @4bae33a6

What can I do?

Greg W.F.R
  • 544
  • 1
  • 5
  • 13
  • 5
    yes, you are using jdk-16 and that and that project you have touches some internal APIs, which that java version prohibits. – Eugene Jul 12 '21 at 01:12

5 Answers5

19

I had same issue first check what Java version is used by maven by using

mvn -v

if it is set to Jdk 16 then you will have to update file below

/usr/local/Cellar/maven/{version}/bin/mvn

and set

JAVA_HOME:-$(/usr/libexec/java_home)

then you can confirm by running mvn -v again

Above steps have resolved the issue for me

Govind Kalyankar
  • 574
  • 1
  • 4
  • 17
16

For me, the problem is the Lombok version.

After upgradation from java8 to java17 and from lombok version 1.18.6 to 1.18.26

Old one:

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.18.6</version>
    <scope>provided</scope>
</dependency>

Upgraded one for java17

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.18.26</version>
    <scope>provided</scope>
</dependency>
Jan Schultke
  • 17,446
  • 6
  • 47
  • 96
Radhakrishnan
  • 564
  • 4
  • 6
2

In my case, I had to upgrade Lombok dependency version and then the issue was resolved.

Mahesh Revaskar
  • 106
  • 1
  • 5
1

Unfortunately this error can have multiple causes, but all caused due to the compatibility issues between the JDK used for compilation and the dependent libraries.

To learn the exact cause, run maven with -e or -X switch. This will produce the stack trace pointing the exact incompatibility issue. Post this, you can change the JDK version and/or upgrade/downgrade the library.

In my case it was lombok (trace below). I had to upgrade the version from 1.16.xx to 1.18.28 for it to compile.

Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private com.sun.tools.javac.processing.JavacProcessingEnvironment$DiscoveredProcessors com.sun.tools.javac.processing.JavacProcessingEnvironment.discoveredProcs accessible: module jdk.compiler does not "opens com.sun.tools.javac.processing" to unnamed module @4ed56cfd at java.lang.reflect.AccessibleObject.checkCanSetAccessible (AccessibleObject.java:354) at java.lang.reflect.AccessibleObject.checkCanSetAccessible (AccessibleObject.java:297) at java.lang.reflect.Field.checkCanSetAccessible (Field.java:178) at java.lang.reflect.Field.setAccessible (Field.java:172) -> at lombok.javac.apt.LombokProcessor.getFieldAccessor (LombokProcessor.java:116) -> at lombok.javac.apt.LombokProcessor. (LombokProcessor.java:108) at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0 (Native Method) ...
Sandeep Deb
  • 125
  • 6
  • 1
    you're right! I found a similar exception stacktrace after reading your post. Now it makes sense why Lombok had to be upgraded – asgs Aug 11 '23 at 09:24
0

Set your IDE to use the right version of SDK and that resolved it for me.

ionyekanna
  • 440
  • 5
  • 7