MyBatis needs to access java.lang and java.util . Not working anymore by default in Java 17
See original GitHub issueHello MyBatis,
I try to upgrade our application to Java 17. Sadly I hit a few bumps on the way. With Java 17 you can’t anymore allow reflection for anyone with --illegel-access=permit
.
From my understanding the proper way to fix this, is that mybatis supports the Java module system and correctly specify what it needs. So it is not an unnamed module anymore.
Current package it tries to access are java.lang and java.util (accessing List). For the 2nd one I can provide the stacktrace soon as well, if you need it.
Can you please help me out? Thank you very much.
MyBatis version
3.5.7
Database vendor and version
MySQL 8.0.17
Test case or example project
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private final long java.lang.Long.value accessible: module java.base does not "opens java.lang" to unnamed module @7334aada at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354) at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297) at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178) at java.base/java.lang.reflect.Field.setAccessible(Field.java:172) at org.apache.ibatis.reflection.invoker.GetFieldInvoker.invoke(GetFieldInvoker.java:38) at org.apache.ibatis.reflection.wrapper.BeanWrapper.getBeanProperty(BeanWrapper.java:164) at org.apache.ibatis.reflection.wrapper.BeanWrapper.get(BeanWrapper.java:49) at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:122) at org.apache.ibatis.executor.keygen.SelectKeyGenerator.processGeneratedKeys(SelectKeyGenerator.java:76)
Workaround
Workaround is to add following statement to the java process that opens.
--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (2 by maintainers)
@harawata Thank you very much! That solved my issue.
I’m using isEmpty without brackets now.
So far I have no further issues. Seems like the issue was only the false use of the library.
@keiki85 ,
That error may occur if you write
<if test="x.isEmpty()">
. Try<if test="x.empty">
or<if test="x.isEmpty">
instead.isEmpty
is one of the Pseudo-Properties for Collections.