0

The above exception is thrown from a unit test when I add Java modularity to my project. I cannot find a solution to this exception.

I have added to MAVEN_OPTS

--add-opens java.base/java.lang=ALL-UNNAMED

And the same in the configuration of the surefire plugin (to no avail) because the following is part of the stacktrace:

throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to module com.google.guice

My project is a maven multiproject with two modules:

module org.veary.debs.api {
    exports org.veary.debs.api;
    exports org.veary.debs.api.model;
    exports org.veary.debs.api.dao;
}

module org.veary.debs.db {
    exports org.veary.debs.db;

    requires com.google.guice;
    requires com.google.guice.extensions.persist;
    requires java.persistence;
    requires javax.inject;
    requires org.veary.debs.api;
}

Here is a snippet of the first section of the stacktrace. Any help would be appreciated.

INFO: An exception was caught and reported. Message: java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,by te[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to module com.google.guice java.lang.IllegalStateException: Unable to load cache item at com.google.guice@4.2.2/com.google.inject.internal.cglib.core.internal.$LoadingCache.createEntry(LoadingCache.java:79) at com.google.guice@4.2.2/com.google.inject.internal.cglib.core.internal.$LoadingCache.get(LoadingCache.java:34) at com.google.guice@4.2.2/com.google.inject.internal.cglib.core.$AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:116) at com.google.guice@4.2.2/com.google.inject.internal.cglib.core.$AbstractClassGenerator.create(AbstractClassGenerator.java:291) at com.google.guice@4.2.2/com.google.inject.internal.cglib.reflect.$FastClass$Generator.create(FastClass.java:65) at com.google.guice@4.2.2/com.google.inject.internal.BytecodeGen.newFastClassForMember(BytecodeGen.java:258) at com.google.guice@4.2.2/com.google.inject.internal.BytecodeGen.newFastClassForMember(BytecodeGen.java:207) at com.google.guice@4.2.2/com.google.inject.internal.ProviderMethod.create(ProviderMethod.java:69) at com.google.guice@4.2.2/com.google.inject.internal.ProviderMethodsModule.createProviderMethod(ProviderMethodsModule.java:272) at com.google.guice@4.2.2/com.google.inject.internal.ProviderMethodsModule.getProviderMethods(ProviderMethodsModule.java:116) at com.google.guice@4.2.2/com.google.inject.internal.ProviderMethodsModule.configure(ProviderMethodsModule.java:100) at com.google.guice@4.2.2/com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:344) at com.google.guice@4.2.2/com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:353) at com.google.guice@4.2.2/com.google.inject.spi.Elements.getElements(Elements.java:103) at com.google.guice@4.2.2/com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:137) at com.google.guice@4.2.2/com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:103) at com.google.guice@4.2.2/com.google.inject.Guice.createInjector(Guice.java:87) at com.google.guice@4.2.2/com.google.inject.Guice.createInjector(Guice.java:69) at com.google.guice@4.2.2/com.google.inject.Guice.createInjector(Guice.java:59) at org.veary.debs.db/org.veary.debs.tests.PersistenceTest.testAccountDao(PersistenceTest.java:43) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566)

nzeru
  • 11
  • 1
  • 1
  • 6
  • 3
    `ALL-UNNAMED` means "open this to all unnamed modules". Your modules are not unnamed. Try changing `ALL-UNNAMED` to `com.google.guice` (or prepending it, if you also need ALL-UNNAMED). – Joachim Sauer May 31 '19 at 08:41
  • @JoachimSauer Thanks for suggestion. That solved it. I appreciate the help - sometimes I can't see the wood for the trees. – nzeru May 31 '19 at 13:25

1 Answers1

1

You need to check that you have correct java version, use this command:

java --version

If it's not version 11 configure java to version 11. If you already have multiple java installed use this command:

alternatives --config java

and select java 11

Petter Friberg
  • 21,252
  • 9
  • 60
  • 109