openpojo icon indicating copy to clipboard operation
openpojo copied to clipboard

Java 9 compatibility

Open gioborelli opened this issue 6 years ago • 4 comments

Hi, looks like openpojo 0.8.10 has some compatibility issues with java 9:

java.lang.IllegalAccessError: class com.openpojo.random.generator.security.CredentialsRandomGenerator (in unnamed module @0x4275e80d) cannot access class sun.security.krb5.Credentials (in module java.security.jgss) because module java.security.jgss does not export sun.security.krb5 to unnamed module @0x4275e80d
        at com.openpojo.random.generator.security.CredentialsRandomGenerator.<clinit>(CredentialsRandomGenerator.java:39)
        at com.openpojo.registry.ServiceRegistrar.initializeRandomGeneratorService(ServiceRegistrar.java:94)
        at com.openpojo.registry.ServiceRegistrar.<init>(ServiceRegistrar.java:57)
        at com.openpojo.registry.ServiceRegistrar.<init>(ServiceRegistrar.java:49)
        at com.openpojo.registry.ServiceRegistrar$Instance.<clinit>(ServiceRegistrar.java:199)
        at com.openpojo.registry.ServiceRegistrar.getInstance(ServiceRegistrar.java:170)
        at com.openpojo.reflection.impl.PojoClassFactory.getPojoClass(PojoClassFactory.java:42)
        at ...

this was the test code:

   @Test
    public void validateSettersAndGetters() {
        PojoClass userPojo = PojoClassFactory.getPojoClass(User.class);

        Validator pojoValidator = ValidatorBuilder.create()

        // Lets validate that setters and getters are behaving as expected
        .with(new SetterTester())
        .with(new GetterTester())

        .build();

        // Start the Test
        pojoValidator.validate(userPojo);
    } 

gioborelli avatar Jun 26 '18 08:06 gioborelli

hello, I have a similar issue with java 17 now. Did you please solve it? thank you.

cervenf avatar Feb 11 '22 09:02 cervenf

I can't even recall what this was about 😅

Sorry

Il ven 11 feb 2022, 10:40 cervenf @.***> ha scritto:

hello, I have a similar issue with java 17 now. Did you please solve it? thank you.

— Reply to this email directly, view it on GitHub https://github.com/OpenPojo/openpojo/issues/117#issuecomment-1036025890, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADKVU63FGTBXO4DMH2WM3TDU2TKR3ANCNFSM4FG55XIA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

gioborelli avatar Feb 11 '22 15:02 gioborelli

The problem is the use of reflection for JPMS modules residing within the JDK like in our case java.base/java.time. Since Java 9 this produced warnings along the lines "Illegal Reflective Access..." but with Java 17 this grace period has ended and you have to tell the JVM if additional packages need to be "opened".

So for instance when using Maven surefire, you can use this approach

<argLine>
    --add-opens java.base/java.time=ALL-UNNAMED
</argLine>

lostiniceland avatar Apr 04 '22 08:04 lostiniceland

The issue can be resolved by using the maven-surefire-plugin which is compatible with Java 17 and adding --add-opens arguments.

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-surefire-plugin</artifactId>
	<version>3.0.0-M5</version>
	<configuration>
		<argLine>
			--add-opens java.security.jgss/sun.security.krb5=ALL-UNNAMED
			--add-opens java.security.jgss/sun.security.krb5.internal=ALL-UNNAMED
			--add-opens java.base/java.time=ALL-UNNAMED
		</argLine>
	</configuration>
</plugin>

Martinedo avatar Mar 13 '23 07:03 Martinedo