Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java 9 compatibility #117

Open
gioborelli opened this issue Jun 26, 2018 · 4 comments
Open

Java 9 compatibility #117

gioborelli opened this issue Jun 26, 2018 · 4 comments

Comments

@gioborelli
Copy link

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);
    } 
@cervenf
Copy link

cervenf commented Feb 11, 2022

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

@gioborelli
Copy link
Author

gioborelli commented Feb 11, 2022 via email

@lostiniceland
Copy link

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>

@Martinedo
Copy link

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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants