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

Assert Java 9 compatibility [DATACMNS-1033] #1481

Closed
spring-projects-issues opened this issue Apr 7, 2017 · 14 comments
Closed

Assert Java 9 compatibility [DATACMNS-1033] #1481

spring-projects-issues opened this issue Apr 7, 2017 · 14 comments
Assignees

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Apr 7, 2017

John Blum opened DATACMNS-1033 and commented

Assert compatibility of Spring Data Commons on Java 9.

Setup Travis CI build using JDK 9.

State of compatibility:

Part JDK9 Compatibility with --permit-illegal-access without --permit-illegal-access Comment
Commons Yes Yes Building on JDK9 doesn't run on Travis yet, due to an outdated JDK version there, but the result of the JDK 8 build is JDK 9 compatible. On JDK 9 ClassGeneratingPropertyAccessor cannot be used which should result in worse performance. See DATACMNS-1080
Examples.JPA (Hibernate) Yes No  
Examples.JPA (EclipseLink) Yes Yes  
Examples.ElasticSearch Yes No DATAES-354
Examples.Cassandra No No DATACASS-444 (Won't run)
Examples.LDAP Yes No DATALDAP-38
Examples.KeyValue Yes No DATAKV-180
Examples.MongoDb Yes Yes  
Examples.MultiStore Yes No see Hibernate
Examples.Neo4J Yes No DATAGRAPH-999
Examples.Rest Yes No see Hibernate (only some examples fail)
Examples.Redis Yes Yes  
Examples.Web Yes No see Hibernate (only some examples fail)

Issue Links:

  • DATACASS-444 Spring Data Example Tests fail with JDK 9

  • DATACMNS-1079 ClassGeneratingPropertyAccessorFactory fails on Java 9

  • DATAES-354 Spring Data Example Tests fail with JDK 9

  • DATACMNS-990 Enable building with JDK11+

  • SPR-14579 Document Spring recommendations/restrictions for Java 9 module setups

  • DATACMNS-991 Update DefaultMethodInvokingMethodInterceptor to Java 9 compatible method handle invocation

  • DATACMNS-1080 Inject generated property accessor classes via ReflectUtils.defineClass(…)

  • DATAKV-180 Spring Data Example Tests fail with JDK 9

  • DATALDAP-38 Spring Data Example Tests fail with NoClassDefFoundError: LdapContextSource

1 votes, 6 watchers

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Apr 7, 2017

John Blum commented

Due Date was based on the tentative date for Kay M3 set in the Spring Release calendar

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Apr 27, 2017

Jens Schauder commented

When compiling commons or the examples maven produces the following error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project spring-data-cassandra-example-utils: Fatal error compiling: 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 @2d4a3e13

This seems to come from our use of Lombok. See rzwitserloot/lombok#985

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Apr 27, 2017

Jens Schauder commented

DefaultMethodInvokingMethodInterceptor is not Java 9 compatible.

It causes

Caused by: java.lang.IllegalStateException: java.lang.reflect.InaccessibleObjectException: Unable to make java.lang.invoke.MethodHandles$Lookup(java.lang.Class) accessible: module java.base does not "opens java.lang.invoke" to unnamed module @f627d13

There should be a fix possible. See: http://mail.openjdk.java.net/pipermail/core-libs-dev/2017-March/046567.html

And there is already a separate issue for it: DATACMNS-991

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Apr 28, 2017

Jens Schauder commented

Current status:

  • Running (very simple) applications based on Spring Data is possible IFF --permit-illegal-access is provided at runtime of the application. See the surefire configuration here for an example.
  • It is not clear if there are uses cases that don't work at all. In order to clarify this, it would be nice to run the example project with jdk9 (see below).
  • In order to make --permit-illegal-access superfluous we need to fix the issues linked to this one. For this, we need to be able to compile commons with jdk9 (see below).
  • We can't compile the examples nor commons with jdk9 since Lombok isn't compatible with jdk9 and the --permit-illegal-access doesn't seem to help. See rzwitserloot/lombok#1372
  • A Travis-CI build with jdk9 is configured in the branch matching this issue, but fails (see above) and uses an unstable environment and a rather old EA version of jdk9
@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 19, 2017

Jens Schauder commented

The build needs to run with

export MAVEN_OPTS='--add-modules java.xml.ws.annotation'

Order to avoid java.lang.ClassNotFoundException: javax.annotation.Generated from the apt plugin. I created an issue for this: querydsl/apt-maven-plugin#36

Even with the maven-option, an error is logged, but the plugin reports a success and the build continues

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 22, 2017

Jens Schauder commented

Static inner classes with @Delegate annotation don't work with JDK9. See rzwitserloot/lombok#1398

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 23, 2017

Jens Schauder commented

Code generation of QueryDSL fails in tests: querydsl/querydsl#2151

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 30, 2017

Jens Schauder commented

-Something is wrong with the initialization of the DataSource in Spring Boot, causing at least some of the JPA test fail during setup, because the DataSource is null.-

-Note that the DataSource does get instantiated, but the DataSourceInitializer never gets its init method called, therefore the datasource field stays empty.-

-See spring-projects/spring-boot#9354

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jun 6, 2017

Jens Schauder commented

This comment is to collect failure modes users might see and what they need to change on their side. Although it is only indirectly related to Spring Data, I guess it would be nice to have a place where people can find this kind of stuff.

  1. Symptom
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException

Explanation jaxb is in a separate module and access to it needs to be granted separately.

Fix add {--add-modules java.xml.bind} to the relevant java process. The relevant java process might be: The one actually executing the code, e.g. the commandline used to start a webserver; The part that executes some test, e.g. the surefire plugin of Maven, or javac when this happens during compiling (this would be customer code accessing jaxb, so completely unrelated to Spring Data, but still)

  1. Symptom Various Hibernate related exceptions

Explanation Hibernate (and most certainly other JPA providers) do all kind of stuff that is not Ok with JDK 9

Fix Short term: add --permit-illegal-access to the parameters of the JVM.

Long term: Use Hibernate 5.x and request build time byte code enhancement; Test your application carefully, since this might introduce subtile changes in behaviour according to https://stackoverflow.com/questions/43258796/hibernate-support-for-java-9 this SO answer

I currently cannot confirm that this works, since I get exceptions like the following:

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.37 s <<< FAILURE! - in example.springdata.jpa.basics.BasicFactorySetup
executingFinders(example.springdata.jpa.basics.BasicFactorySetup)  Time elapsed: 0.112 s  <<< ERROR!
javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: Exception occurred inside setter of example.springdata.jpa.simple.User.id
	at example.springdata.jpa.basics.BasicFactorySetup.setUp(BasicFactorySetup.java:65)
Caused by: org.hibernate.PropertyAccessException: Exception occurred inside setter of example.springdata.jpa.simple.User.id
	at example.springdata.jpa.basics.BasicFactorySetup.setUp(BasicFactorySetup.java:65)
Caused by: java.lang.reflect.InvocationTargetException
	at example.springdata.jpa.basics.BasicFactorySetup.setUp(BasicFactorySetup.java:65)
Caused by: java.lang.NoSuchMethodError: org.springframework.data.jpa.domain.AbstractPersistable.$$_hibernate_write_id(Ljava/io/Serializable;)V
	at example.springdata.jpa.basics.BasicFactorySetup.setUp(BasicFactorySetup.java:65)
@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Aug 25, 2017

Jens Schauder commented

The CI builds fails with what might be a javadoc bug, but I can't reproduce it with a simple test case. My failed attempt is here: https://github.com/schauder/javadoc-arity-bug/tree/master

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Aug 29, 2017

Jens Schauder commented

There now is an issue in the jdk9 tracker: http://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8186841

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Mar 28, 2018

Oliver Drotbohm commented

Regarding the correct invocation of default methods, this blog by Lukas Eder

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 16, 2018

Mark Paluch commented

Java 9 compatibility asserted, Spring Data Examples builds with Java 9 in place, see spring-projects/spring-data-examples#360

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 17, 2018

Mark Paluch commented

Closing this one as compatibility with Java 9 and 10 is given. Issues that prevented usage of Spring Data were fixed in the linked tickets, upstream dependencies, and the Java runtime.

We'll revisit building Spring Data with a newer JDK in the scope of a future ticket

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

Successfully merging a pull request may close this issue.

None yet
2 participants