Skip to content
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

WARNING: An illegal reflective access operation has occurred -> when using public method in non public class #2392

Closed
filiphr opened this issue Nov 25, 2021 · 6 comments
Assignees
Labels
bug on dependency library Indicates a bug on dependency library
Milestone

Comments

@filiphr
Copy link

filiphr commented Nov 25, 2021

MyBatis version

3.5.6

Database vendor and version

Not important

Steps to reproduce

  1. Create input parameter to be Collections.emptyList()
  2. Use input parameter in a test expression in XML e.g. parameter.isEmpty()

Expected result

No illegal reflective access warning

Actual result

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.ibatis.ognl.AccessibleObjectHandlerPreJDK9 (file:/~/.m2/repository/org/mybatis/mybatis/3.5.6/mybatis-3.5.6.jar) to method java.util.Collections$EmptyList.isEmpty()
WARNING: Please consider reporting this to the maintainers of org.apache.ibatis.ognl.AccessibleObjectHandlerPreJDK9
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

@filiphr
Copy link
Author

filiphr commented Nov 25, 2021

The problem also occurs on 3.5.7.

I also run with --illegal-access=debug and the entire stacktrace is:

WARNING: Illegal reflective access by org.apache.ibatis.ognl.AccessibleObjectHandlerPreJDK9 (file:/Users/filiphr/.m2/repository/org/mybatis/mybatis/3.5.7/mybatis-3.5.7.jar) to method java.util.Collections$EmptyList.isEmpty()
	at org.apache.ibatis.ognl.AccessibleObjectHandlerPreJDK9.setAccessible(AccessibleObjectHandlerPreJDK9.java:58)
	at org.apache.ibatis.ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:1232)
	at org.apache.ibatis.ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1979)
	at org.apache.ibatis.ognl.ObjectMethodAccessor.callMethod(ObjectMethodAccessor.java:68)
	at org.apache.ibatis.ognl.OgnlRuntime.callMethod(OgnlRuntime.java:2055)
	at org.apache.ibatis.ognl.ASTMethod.getValueBody(ASTMethod.java:97)
	at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
	at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:258)
	at org.apache.ibatis.ognl.ASTChain.getValueBody(ASTChain.java:141)
	at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
	at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:258)
	at org.apache.ibatis.ognl.ASTNot.getValueBody(ASTNot.java:49)
	at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
	at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:258)
	at org.apache.ibatis.ognl.ASTAnd.getValueBody(ASTAnd.java:61)
	at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
	at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:258)
	at org.apache.ibatis.ognl.ASTOr.getValueBody(ASTOr.java:61)
	at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
	at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:258)
	at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:586)
	at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:550)
	at org.apache.ibatis.scripting.xmltags.OgnlCache.getValue(OgnlCache.java:46)
	at org.apache.ibatis.scripting.xmltags.ExpressionEvaluator.evaluateBoolean(ExpressionEvaluator.java:32)
	at org.apache.ibatis.scripting.xmltags.IfSqlNode.apply(IfSqlNode.java:34)
	at org.apache.ibatis.scripting.xmltags.MixedSqlNode.lambda$apply$0(MixedSqlNode.java:32)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at org.apache.ibatis.scripting.xmltags.MixedSqlNode.apply(MixedSqlNode.java:32)
	at org.apache.ibatis.scripting.xmltags.TrimSqlNode.apply(TrimSqlNode.java:55)
	at org.apache.ibatis.scripting.xmltags.MixedSqlNode.lambda$apply$0(MixedSqlNode.java:32)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at org.apache.ibatis.scripting.xmltags.MixedSqlNode.apply(MixedSqlNode.java:32)

@harawata
Copy link
Member

harawata commented Nov 25, 2021

Hello @filiphr ,

Please use <if test="parameter.empty"> or <if test="parameter.isEmpty"> instead.

isEmpty is one of the Pseudo-Properties for Collections.

Duplicate of #2383

@filiphr
Copy link
Author

filiphr commented Nov 26, 2021

Thanks for the hint @harawata. I changed to isEmpty and it works fine without any warnings.

However, I still think that the issue will happen for non collections in a similar situation, a public method on a non public class

@harawata
Copy link
Member

Glad to know it worked!

Test expressions are evaluated by OGNL, so if you think there is a room for improvement, submit the enhancement request to their tracker : https://github.com/jkuhnert/ognl/issues

@harawata
Copy link
Member

This should be fixed by #2423

The OGNL issue is orphan-oss/ognl#144 (big thanks to @Farbfetzen !)

You can verify the fix with 3.5.10-SNAPSHOT .
If there still is an issue with the snapshot, please report the details.

Thank you for the report!

@filiphr
Copy link
Author

filiphr commented Jan 10, 2022

That is great to hear @harawata. Thanks for letting me know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug on dependency library Indicates a bug on dependency library
Projects
None yet
Development

No branches or pull requests

2 participants