1

Exploring Java 9, trying to migrate an example Spring-Boot Hibernate app from Java 8 to Java 9 and running into the below issue.

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 org.hibernate.boot.archive.spi.ArchiveException: Could not build ClassFile
    at spring.beans@4.3.6.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628) ~[spring-beans-4.3.6.RELEASE.jar:na]
    at spring.beans@4.3.6.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.6.RELEASE.jar:na]
    at spring.beans@4.3.6.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.6.RELEASE.jar:na]
    at spring.beans@4.3.6.RELEASE/org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.6.RELEASE.jar:na]
    at spring.beans@4.3.6.RELEASE/org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.6.RELEASE.jar:na]
    at spring.beans@4.3.6.RELEASE/org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.6.RELEASE.jar:na]
    at spring.beans@4.3.6.RELEASE/org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.6.RELEASE.jar:na]
    at spring.context@4.3.6.RELEASE/org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1081) ~[spring-context-4.3.6.RELEASE.jar:na]
    at spring.context@4.3.6.RELEASE/org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:856) ~[spring-context-4.3.6.RELEASE.jar:na]
    at spring.context@4.3.6.RELEASE/org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.6.RELEASE.jar:na]
    at spring.boot@1.5.1.RELEASE/org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.1.RELEASE.jar:na]
    at spring.boot@1.5.1.RELEASE/org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) [spring-boot-1.5.1.RELEASE.jar:na]
    at spring.boot@1.5.1.RELEASE/org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) [spring-boot-1.5.1.RELEASE.jar:na]
    at spring.boot@1.5.1.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-1.5.1.RELEASE.jar:na]
    at spring.boot@1.5.1.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.1.RELEASE.jar:na]
    at spring.boot@1.5.1.RELEASE/org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.1.RELEASE.jar:na]
    at restfulpeople@1.0/com.khs.restful.people.RestfulPeopleApplication.main(RestfulPeopleApplication.java:14) [restfulpeople-1.0.jar:na]
Caused by: org.hibernate.boot.archive.spi.ArchiveException: Could not build ClassFile
    at org.hibernate.boot.archive.scan.spi.ClassFileArchiveEntryHandler.toClassFile(ClassFileArchiveEntryHandler.java:64) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.boot.archive.scan.spi.ClassFileArchiveEntryHandler.handleEntry(ClassFileArchiveEntryHandler.java:47) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.boot.archive.internal.JarFileBasedArchiveDescriptor.visitArchive(JarFileBasedArchiveDescriptor.java:152) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.boot.archive.scan.spi.AbstractScannerImpl.scan(AbstractScannerImpl.java:47) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.boot.model.process.internal.ScanningCoordinator.coordinateScan(ScanningCoordinator.java:75) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.prepare(MetadataBuildingProcess.java:98) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:199) ~[hibernate-entitymanager-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:149) ~[hibernate-entitymanager-5.0.11.Final.jar:5.0.11.Final]
    at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:54) ~[spring-orm-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353) ~[spring-orm-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:373) ~[spring-orm-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:362) ~[spring-orm-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at spring.beans@4.3.6.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) ~[spring-beans-4.3.6.RELEASE.jar:na]
    at spring.beans@4.3.6.RELEASE/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ~[spring-beans-4.3.6.RELEASE.jar:na]
    ... 16 common frames omitted
Caused by: java.io.IOException: invalid constant type: 20 at 7
    at javassist@3.22.0-CR1/javassist.bytecode.ConstPool.readOne(ConstPool.java:1244) ~[javassist-3.22.0-CR1.jar:na]
    at javassist@3.22.0-CR1/javassist.bytecode.ConstPool.read(ConstPool.java:1175) ~[javassist-3.22.0-CR1.jar:na]
    at javassist@3.22.0-CR1/javassist.bytecode.ConstPool.<init>(ConstPool.java:185) ~[javassist-3.22.0-CR1.jar:na]
    at javassist@3.22.0-CR1/javassist.bytecode.ClassFile.read(ClassFile.java:839) ~[javassist-3.22.0-CR1.jar:na]
    at javassist@3.22.0-CR1/javassist.bytecode.ClassFile.<init>(ClassFile.java:164) ~[javassist-3.22.0-CR1.jar:na]
    at org.hibernate.boot.archive.scan.spi.ClassFileArchiveEntryHandler.toClassFile(ClassFileArchiveEntryHandler.java:61) ~[hibernate-core-5.2.9-SNAPSHOT.jar:5.2.9.SNAPSHOT]
    ... 29 common frames omitted

I was able to get this application working as an unnammed module and importing my entire lib directory, but have been stuck with the above exception for awhile now when trying to run the app as a single "monolithic module".

Googling the specific error I am getting brings me to this stackoverflow thread: Could not build ClassFile - ArchiveException

Can't really figure if that's relevant or not. Have only a single copy of javassist of classapth/modulepath and it's the latest release version of the library. Also, as previously mentioned this application does work as an unammed-module (so that would seem to suggest it isn't a version conflict issue).

Here is the build file I am using right now to launch the app:

set -e

CLASSPATH=mods/accessors-smart-1.1.jar:mods/spring-aop-4.3.6.RELEASE.jar:mods/android-json-0.0.20131108.vaadin1.jar:mods/spring-aspects-4.3.6.RELEASE.jar:mods/antlr-2.7.7.jar:mods/spring-beans-4.3.6.RELEASE.jar:mods/asm-5.0.3.jar:mods/spring-boot-1.5.1.RELEASE.jar:mods/aspectjweaver-1.8.9.jar:mods/spring-boot-autoconfigure-1.5.1.RELEASE.jar:mods/assertj-core-2.6.0.jar:mods/spring-boot-starter-1.5.1.RELEASE.jar:mods/classmate-1.3.3.jar:mods/spring-boot-starter-aop-1.5.1.RELEASE.jar:mods/dom4j-1.6.1.jar:mods/spring-boot-starter-data-jpa-1.5.1.RELEASE.jar:mods/evo-inflector-1.2.1.jar:mods/spring-boot-starter-data-rest-1.5.1.RELEASE.jar:mods/h2-1.4.193.jar:mods/spring-boot-starter-jdbc-1.5.1.RELEASE.jar:mods/hamcrest-core-1.3.jar:mods/spring-boot-starter-logging-1.5.1.RELEASE.jar:mods/hamcrest-modsrary-1.3.jar:mods/spring-boot-starter-test-1.5.1.RELEASE.jar:mods/hibernate-commons-annotations-5.0.1.Final.jar:mods/spring-boot-starter-tomcat-1.5.1.RELEASE.jar:mods/hibernate-core-5.0.11.Final.jar:mods/spring-boot-starter-web-1.5.1.RELEASE.jar:mods/hibernate-entitymanager-5.0.11.Final.jar:mods/hibernate-jpa-2.1-api-1.0.0.Final.jar:mods/hibernate-validator-5.3.4.Final.jar:mods/spring-context-4.3.6.RELEASE.jar:mods/jackson-annotations-2.8.0.jar:mods/spring-core-4.3.6.RELEASE.jar:mods/jackson-core-2.8.6.jar:mods/spring-data-commons-1.13.0.RELEASE.jar:mods/jackson-databind-2.8.6.jar:mods/spring-data-jpa-1.11.0.RELEASE.jar:mods/jandex-2.0.0.Final.jar:mods/spring-data-rest-core-2.6.0.RELEASE.jar:mods/javassist-3.21.0-GA.jar:mods/spring-data-rest-webmvc-2.6.0.RELEASE.jar:mods/javax.transaction-api-1.2.jar:mods/spring-expression-4.3.6.RELEASE.jar:mods/jboss-logging-3.3.0.Final.jar:mods/spring-hateoas-0.23.0.RELEASE.jar:mods/jcl-over-slf4j-1.7.22.jar:mods/spring-jdbc-4.3.6.RELEASE.jar:mods/json-path-2.2.0.jar:mods/spring-orm-4.3.6.RELEASE.jar:mods/json-smart-2.2.1.jar:mods/spring-plugin-core-1.2.0.RELEASE.jar:mods/jsonassert-1.4.0.jar:mods/jul-to-slf4j-1.7.22.jar:mods/spring-tx-4.3.6.RELEASE.jar:mods/spring-web-4.3.6.RELEASE.jar:mods/log4j-over-slf4j-1.7.22.jar:mods/spring-webmvc-4.3.6.RELEASE.jar:mods/logback-classic-1.1.9.jar:mods/tomcat-embed-core-8.5.11.jar:mods/logback-core-1.1.9.jar:mods/tomcat-embed-el-8.5.11.jar:mods/tomcat-embed-websocket-8.5.11.jar:mods/tomcat-jdbc-8.5.11.jar:mods/objenesis-2.1.jar:mods/tomcat-juli-8.5.11.jar:mods/slf4j-api-1.7.22.jar:mods/validation-api-1.1.0.Final.jar:mods/snakeyaml-1.17.jar:mods/spring-boot-test-1.5.1.RELEASE.jar:mods/spring-boot-test-autoconfigure-1.5.1.RELEASE.jar:mods/spring-test-4.3.6.RELEASE.jar:mods/junit-4.12.jar:mods/mockito-core-1.10.19.jar

javac -cp $CLASSPATH \
      --module-path mods \
      -d out         \
      --module-source-path src $(find src -name '*.java')

jar --create --file mods/restfulpeople-1.0.jar --module-version=1.0 -C out/restfulpeople .

java -cp $CLASSPATH \
     --module-path mods       \
     --add-modules java.xml.bind,java.sql,javassist,spring.core,spring.beans,java.instrument \
     --add-opens java.base/java.lang=javassist \
     --add-opens java.base/java.lang=spring.core \
     --add-opens java.base/java.lang=spring.beans \
     -m restfulpeople/com.khs.restful.people.RestfulPeopleApplication

And here is a link to my github repo for local testing purposes: https://github.com/wkorando/restful-people/tree/02-monolithic-module

Let me know if additional information is needed.

EDIT:

Added underlying exception. New constant pool types (in the case of this specific error CONSTANT_Package) were added in the jigsaw edition of java 9: https://bugs.openjdk.java.net/browse/JDK-8175089

Community
  • 1
  • 1
Billy Korando
  • 225
  • 3
  • 6
  • 5
    We haven't yet certified Hibernate to run on JDK9, just FYI. – Naros Feb 26 '17 at 00:59
  • Yea, definitely realize this is on the bleeding edge and *might* literally not be possible yet. But guess some unlucky individual needs to run into these issues first? I am basing my project heavily on the work by Sander Mak & Paul Bakker here: https://github.com/sandermak/java9-migration-demos/tree/master/3_MonolithicSpring, that does work, however it's not using spring boot. Now inspecting boot code for issues: https://github.com/spring-projects/spring-boot/blob/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.java – Billy Korando Feb 26 '17 at 01:22
  • 3
    Understood, well its likely worth mentioning we are doing CI against JDK9 with each push and aware of the incompatibilities. – Naros Feb 26 '17 at 02:09

1 Answers1

0

20 is the CONSTANT_Package but you should only see these tags in the constant pool of module-info.class. It may be the version of Javaassist used in the experiment doesn't support JDK 9 and version 53.0 class file yet.

Alan Bateman
  • 5,283
  • 1
  • 20
  • 25