java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class when upgrade from java 11 to 17

10,754

Maybe try adding a vm parameter at lauch:

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

The --illegal-access is set to become ineffective in Java 17 (all values are equivalent to deny) but it will still be possible to use the --add-opens command-line option, or the Add-Opens JAR-file manifest attribute, to open specific packages (cf. openjdk.java.net/jeps/403 )

Share:
10,754

Related videos on Youtube

Rajkumar Natarajan
Author by

Rajkumar Natarajan

Updated on June 04, 2022

Comments

  • Rajkumar Natarajan
    Rajkumar Natarajan almost 2 years

    our project uses [schema-repo-server][1]. The code for starting the schema-repo-server is below -

        package technorati.tut.fes;
        
        import org.schemarepo.server.RepositoryServer;
        import java.util.Properties;
        
        public class Main2 {
            public static void main(String[] args) throws Exception {
                Properties props = new Properties();
                props.put("schema-repo.class", "com.technorati.camus.schemaregistry.ZooKeeperRepository");
                props.put("schema-repo.zookeeper.ensemble", "kafka01.cap.qa.opal.synacor.com:2181,kafka02.cap.qa.opal.synacor.com:2181,kafka03.cap.qa.opal.synacor.com:2181");
                RepositoryServer rs = new RepositoryServer(props);
                rs.start();
            }
        
        }
        
    

    This code is working fine in java11.

    I'm upgrading java version from java 11 to java 17. After the upgrade when I start the service I get below error.

    Note: modules in the startup list are --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens jdk.management/com.sun.management.internal=ALL-UNNAMED

    How can I fix this issue?

    14:18:48 INFO [org.schemarepo.server.RepositoryServer ] Routing java.util.logging traffic through SLF4J Exception in thread "main" com.google.inject.internal.util.$ComputationException: java.lang.ExceptionInInitializerError at com.google.inject.internal.util.$MapMaker$StrategyImpl.compute(MapMaker.java:553) at com.google.inject.internal.util.$MapMaker$StrategyImpl.compute(MapMaker.java:419) at com.google.inject.internal.util.$CustomConcurrentHashMap$ComputingImpl.get(CustomConcurrentHashMap.java:2041) at com.google.inject.internal.FailableCache.get(FailableCache.java:50) at com.google.inject.internal.ConstructorInjectorStore.get(ConstructorInjectorStore.java:49) at com.google.inject.internal.ConstructorBindingImpl.initialize(ConstructorBindingImpl.java:125) at com.google.inject.internal.InjectorImpl.initializeBinding(InjectorImpl.java:507) at com.google.inject.internal.AbstractBindingProcessor$Processor$1.run(AbstractBindingProcessor.java:159) at com.google.inject.internal.ProcessedBindingData.initializeBindings(ProcessedBindingData.java:44) at com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:122) at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:106) at com.google.inject.Guice.createInjector(Guice.java:95) at com.google.inject.Guice.createInjector(Guice.java:72) at com.google.inject.Guice.createInjector(Guice.java:62) at org.schemarepo.server.RepositoryServer.(RepositoryServer.java:97) at technorati.tut.fes.Main2.main(Main2.java:12) Caused by: java.lang.ExceptionInInitializerError at com.google.inject.internal.cglib.reflect.$FastClassEmitter.(FastClassEmitter.java:67) at com.google.inject.internal.cglib.reflect.$FastClass$Generator.generateClass(FastClass.java:72) at com.google.inject.internal.cglib.core.$DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25) at com.google.inject.internal.cglib.core.$AbstractClassGenerator.create(AbstractClassGenerator.java:216) at com.google.inject.internal.cglib.reflect.$FastClass$Generator.create(FastClass.java:64) at com.google.inject.internal.BytecodeGen.newFastClass(BytecodeGen.java:207) at com.google.inject.internal.DefaultConstructionProxyFactory.create(DefaultConstructionProxyFactory.java:53) at com.google.inject.internal.ProxyFactory.create(ProxyFactory.java:153) at com.google.inject.internal.ConstructorInjectorStore.createConstructor(ConstructorInjectorStore.java:89) at com.google.inject.internal.ConstructorInjectorStore.access$000(ConstructorInjectorStore.java:28) at com.google.inject.internal.ConstructorInjectorStore$1.create(ConstructorInjectorStore.java:36) at com.google.inject.internal.ConstructorInjectorStore$1.create(ConstructorInjectorStore.java:32) at com.google.inject.internal.FailableCache$1.apply(FailableCache.java:39) at com.google.inject.internal.util.$MapMaker$StrategyImpl.compute(MapMaker.java:549) ... 15 more Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @f0c8a99 at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:357) at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297) at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199) at java.base/java.lang.reflect.Method.setAccessible(Method.java:193) at com.google.inject.internal.cglib.core.$ReflectUtils$2.run(ReflectUtils.java:56) at java.base/java.security.AccessController.doPrivileged(AccessController.java:312) at com.google.inject.internal.cglib.core.$ReflectUtils.(ReflectUtils.java:46) ... 29 more

    Process finished with exit code 1

    This is working fine [1]: https://mvnrepository.com/artifact/org.schemarepo/schema-repo-server.

    Note: I've added vm argument --illegal-access=permit --add-opens java.base/java.lang=ALL-UNNAMED but still I'm facing this error on java-17