Skip to content

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

Closed

Description

@filiphr

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

Activity

  1. filiphr commented on Nov 25, 2021

    @filiphr
    Author

    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)
    
  2. harawata commented on Nov 25, 2021

    @harawata
    Member

    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

  3. filiphr commented on Nov 26, 2021

    @filiphr
    Author

    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

  4. harawata commented on Nov 26, 2021

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

  5. self-assigned this
    on Jan 10, 2022
  6. added this to the 3.5.10 milestone on Jan 10, 2022
  7. harawata commented on Jan 10, 2022

    @harawata
    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!

  8. filiphr commented on Jan 10, 2022

    @filiphr
    Author

    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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions