-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
MyBatis needs to access java.lang and java.util . Not working anymore by default in Java 17 #2383
Comments
Hey @harawata . Thanks for the fast reply. I thought this is a more general issue with Java 17 that's why I didn't thought about creating an example project yet. Or digging more into my personal configuration. |
I found the cause for the first issue. We have following code:
The problem is that "value" is on one hand the field/getter name in "LongRef", but also in the resulting java.lang.Long itself. That's why in org/apache/ibatis/executor/keygen/SelectKeyGenerator.java:75 the test succeeds for having a getter for java.lang.Long value field and tries to make it accessible. After changing the field name to "number" in LongRef and the result of the query everthingy works fine as it doesn't find any getter. |
@keiki85 are you running mybatis on java 17 with no problems? |
@GeorgeSalu Not yet that's why I'm here. Most works fine though. The next issue I'm facing is related to ognl. I could add "--add-open" to it, but is not a long term fix. |
Looks like ognl is setting isEmpty (of java/util/ImmutableCollections.java:574) "accessible". Even though it's already callable, but not "accessible" as term of java reflection. I guess I create a ticket for them... |
@keiki85 , That error may occur if you write
|
@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. |
通过这个解决了问题,thanks |
Replaced my comment. Please open new issues rather than comments on years old tickets. Also please write in English. |
Hello 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
The text was updated successfully, but these errors were encountered: