0

I have a multi-module Maven project build / compiled using Java 8.

I recently just installed OpenJDK 11 in an effort to upgrade the project to Java 11. Before actually updated any components, etc. I wanted to compile my Java 8 project as Java 8 but using the Java 11 compiler.

I updated my parent pom.xml

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.0</version>
    <configuration>
        <release>8</release>
    </configuration>
</plugin>

I am able to compile all my sources without issue.

When I go to run my tests (mvn test), my tests succeed up until they reach my MyBatis tests at which point I get a failure:

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.ExecutorException: Error creating lazy proxy.  Cause: java.lang.NullPointerException
        at org.apache.ibatis.javassist.util.proxy.SecurityActions.setAccessible(SecurityActions.java:103)
        at org.apache.ibatis.javassist.util.proxy.DefineClassHelper.toClass3(DefineClassHelper.java:151)
        at org.apache.ibatis.javassist.util.proxy.DefineClassHelper.toClass2(DefineClassHelper.java:134)
        at org.apache.ibatis.javassist.util.proxy.DefineClassHelper.toClass(DefineClassHelper.java:95)
        at org.apache.ibatis.javassist.util.proxy.FactoryHelper.toClass(FactoryHelper.java:131)
        at org.apache.ibatis.javassist.util.proxy.ProxyFactory.createClass3(ProxyFactory.java:530)
        at org.apache.ibatis.javassist.util.proxy.ProxyFactory.createClass2(ProxyFactory.java:515)
        at org.apache.ibatis.javassist.util.proxy.ProxyFactory.createClass1(ProxyFactory.java:451)
        at org.apache.ibatis.javassist.util.proxy.ProxyFactory.createClass(ProxyFactory.java:422)
        at org.apache.ibatis.javassist.util.proxy.ProxyFactory.create(ProxyFactory.java:698)
        at org.apache.ibatis.executor.loader.javassist.JavassistProxyFactory.crateProxy(JavassistProxyFactory.java:94)
        at org.apache.ibatis.executor.loader.javassist.JavassistProxyFactory$EnhancedResultObjectProxyImpl.createProxy(JavassistProxyFactory.java:125)
        at org.apache.ibatis.executor.loader.javassist.JavassistProxyFactory.createProxy(JavassistProxyFactory.java:61)
        at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.createResultObject(DefaultResultSetHandler.java:600)
        at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:396)
        at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForSimpleResultMap(DefaultResultSetHandler.java:355)
        at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:330)
        at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:303)
        at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:196)
        at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:64)
        at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79)
        at org.apache.ibatis.executor.ReuseExecutor.doQuery(ReuseExecutor.java:60)
        at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:326)
        at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
        at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)
        at org.apache.ibatis.executor.loader.ResultLoader.selectList(ResultLoader.java:81)
        at org.apache.ibatis.executor.loader.ResultLoader.loadResult(ResultLoader.java:70)
        at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getNestedQueryMappingValue(DefaultResultSetHandler.java:772)
        at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getPropertyMappingValue(DefaultResultSetHandler.java:464)
        at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.applyPropertyMappings(DefaultResultSetHandler.java:440)
        at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:403)
        at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForSimpleResultMap(DefaultResultSetHandler.java:355)
        at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:330)
        at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:303)
        at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:196)
        at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:64)
        at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79)
        at org.apache.ibatis.executor.ReuseExecutor.doQuery(ReuseExecutor.java:60)
        at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:326)
        at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
        at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)
        at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:83)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
        at jdk.internal.reflect.GeneratedMethodAccessor67.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433)
        at com.sun.proxy.$Proxy27.selectList(Unknown Source)
        at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:230)

My understanding was that by using the <release> tag, not only would the compiler target the specified version for byte code compatibility, but the correct JDK packages would also be used. This seems like it's doing its job to some extent because the compilation worked correctly, but the running of the tests is not.

Ryan Griffith
  • 1,591
  • 17
  • 41
  • Please upgrade MyBatis to 3.5.x. The latest version is 3.5.7. – ave Sep 20 '21 at 18:48
  • @ave, I certainly can do that, but my question is why should I have to? I supposedly should be allowed to target Java 8 with my Java 11 compiler and everything should just "work" as I understand it. What about this is causing MyBatis to all of a sudden not work? – Ryan Griffith Sep 20 '21 at 19:09
  • 2
    The issue is in Javassist which is a dependency of MyBatis. MyBatis uses maven-shade-plugin to include Javassist code inside its .jar under different package name. Newer versions of MyBatis contain newer versions of Javassist which do not have this particular issue. I didn't take any deeper look, but [this](https://github.com/jboss-javassist/javassist/issues/369) seems to be the issue you are experiencing. – ave Sep 20 '21 at 19:19
  • @ave, I saw that javaassist was essentially embedder into the jar like you're saying. I guess it is still not clear to me why if I'm compiling against Java 8, why *anything* would break, period. I upgraded by MyBatis, and I'm led to a whole new error having to do with PowerMock `cannot access jdk/internal/reflect superclass jdk.internal.reflect.MagicAccessorImpl`. So, regardless of whether or not we're talking about MyBatis or some other library, I'm just curious why when using the OpenJDK 11 compiler to compile Java 8, would anything break period. – Ryan Griffith Sep 20 '21 at 19:24
  • After compiling the project, you seem to be running the tests on 11. If you want to run your project on 8 (that's what you want, right?), you should run the tests on 8. – ave Sep 20 '21 at 19:56
  • 1
    If I read PowerMock I strongly recommend to get rid of it... The question is why is PowerMock even needed? – khmarbaise Sep 21 '21 at 07:26
  • I completely agree as I do with @ave above. I've inherited an older system that is massive and I am the sole developer. I'm not at a place to start making those moves. I have one, supposedly simple, goal. I want to take my existing project which runs correctly on Java 8 and compile and run it with Java 11. So, my question remains: Why does my Java 8 project compiled and ran with Java 11 not function? What am I missing and why do these random pieces of code fail? Am I missing a compiler switch? What's going on here? – Ryan Griffith Sep 21 '21 at 11:49
  • @RyanGriffith Are you saying that if you didn't specify the target version, the same tests run without an error on 11? In my understanding, if you want to run/test your project on 11, all dependent libraries need to support 11 and it does not matter whether you specify 8 as the target version or not. – ave Sep 21 '21 at 15:06
  • @ave, no, I am not saying that the same tests run OK on 11. Put another way NOTHING is running correctly on 11. That said, If I'm targeting 8, shouldn't 11 be able to run apps built targeting 8? Isn't that the whole backwards compatible thing? Especially if I'm telling the compiler to target 8 and I'm using the *exact same POM dependencies* that worked on 8.... why is 11 (supposedly backwards compatible) not able to run my 8 stack? – Ryan Griffith Sep 21 '21 at 20:54
  • Unfortunately, since version 9, it is relatively common that upgrading JDK requires some code changes (I found a similar [question](https://stackoverflow.com/q/54439762/1261766)). I already mentioned the Javassist issue. PowerMock also has some [issues](https://stackoverflow.com/q/52966897/1261766), it seems. Oracle provides the compatibility [status](https://wiki.openjdk.java.net/display/quality/Quality+Outreach) of some popular FOSSs, but it's mostly about their latest versions. – ave Sep 21 '21 at 22:20

0 Answers0