question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MyBatis needs to access java.lang and java.util . Not working anymore by default in Java 17

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
keiki85commented, Nov 17, 2021

@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.

3reactions
harawatacommented, Nov 17, 2021

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

mybatis - MyBatisSystemException for Java17 - Stack Overflow
Cause: java.lang.reflect.InaccessibleObjectException: Unable to make public int java.util.Collections$EmptyList.size() accessible: module java.
Read more >
OracleDriver (Oracle &reg; Database JDBC API Reference)
The Oracle JDBC driver class that implements the java.sql.Driver interface. Register the JDBC drivers. To access a database from a Java application, you...
Read more >
Java & Databases: An Overview of Libraries & APIs
You can use this guide to get an overview of all popular database libraries & APIs in Java. Covers JDBC, Hibernate, JPA, jOOQ,...
Read more >
Custom pluggable types for ... - The Checker Framework Manual
The Java Language Specification also defines declaration ... To use the castNonNull method, the checker-util.jar file must be on the ...
Read more >
Logging Problems in IBM WebSphere Application Server
How can I get WebSphere Application Server logs to go to syslog or the ... To create a Handler you need to extend...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found