加入收藏 | 设为首页 | 会员中心 | 我要投稿 开发网_开封站长网 (http://www.0378zz.com/)- 科技、AI行业应用、媒体智能、低代码、办公协同!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

警惕,MyBatis的size()方法竟然有坑!

发布时间:2019-09-19 10:41:01 所属栏目:MySql教程 来源:http://h5ip.cn/aJgJ Mybatis是一个
导读:副标题#e# 来源:http://h5ip.cn/aJgJ Mybatis是一个开源的轻量级半自动化ORM框架,使得面向对象应用程序与关系数据库的映射变得更加容易。MyBatis使用xml描述符或注解将对象与存储过程或SQL语句相结合。Mybatis最大优点是应用程序与Sql进行解耦,sql语句是
副标题[/!--empirenews.page--]

警惕,MyBatis的size()方法竟然有坑!

来源:http://h5ip.cn/aJgJ

Mybatis是一个开源的轻量级半自动化ORM框架,使得面向对象应用程序与关系数据库的映射变得更加容易。MyBatis使用xml描述符或注解将对象与存储过程或SQL语句相结合。Mybatis最大优点是应用程序与Sql进行解耦,sql语句是写在Xml Mapper文件中。OGNL表达式在Mybatis当中应用非常广泛,其表达式的灵活性使得动态Sql功能的非常强大。OGNL是Object-Graph Navigation Language的缩写,代表对象图导航语言。OGNL是一种EL表达式语言,用于设置和获取Java对象的属性,并且可以对列表进行投影选择以及执行lambda表达式。Ognl类提供了许多简便方法用于执行表达式的。Struts2发布的每个版本都会出现的新的高危可执行漏洞也是因为它使用了灵活的OGNL表达式。公司后端采用Mybatis作为数据访问层,所使用版本为3.2.3。线上环境业务系统在运行过程中出现了一个令人困惑的异常, 该异常时而出现时而不出现,构造各种OGNL表达式为空等特殊情况均不会重现该异常。具体异常堆栈信息如下:

  1. ### Error querying database.  Cause: org.apache.ibatis.builder.BuilderException: Error evaluating expression 'list != null and list.size() > 0'. Cause: org.apache.ibatis.ognl.MethodFailedException: Method "size" failed for object [1] [java.lang.IllegalAccessException: Class org.apache.ibatis.ognl.OgnlRuntime can not access a member of class java.util.Collections$SingletonList with modifiers "public"] 
  2. ### Cause: org.apache.ibatis.builder.BuilderException: Error evaluating expression 'list != null and list.size() > 0'. Cause: org.apache.ibatis.ognl.MethodFailedException: Method "size" failed for object [1] [java.lang.IllegalAccessException: Class org.apache.ibatis.ognl.OgnlRuntime can not access a member of class java.util.Collections$SingletonList with modifiers "public"] 
  3.     at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23) org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:107) 
  4.     at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:98) 
  5.     at cn.com.shaobingmm.MybatisBugTest$2.run(MybatisBugTest.java:88) 
  6.     at java.lang.Thread.run(Thread.java:745) 
  7. Caused by: org.apache.ibatis.builder.BuilderException: Error evaluating expression 'list != null and list.size() > 0'. Cause: org.apache.ibatis.ognl.MethodFailedException: Method "size" failed for object [1] [java.lang.IllegalAccessException: Class org.apache.ibatis.ognl.OgnlRuntime can not access a member of class java.util.Collections$SingletonList with modifiers "public"] 
  8.     at org.apache.ibatis.scripting.xmltags.OgnlCache.getValue(OgnlCache.java 
  9.     at:47) 
  10.     at org.apache.ibatis.scripting.xmltags.ExpressionEvaluator.evaluateBoolean(ExpressionEvaluator.java:29) 
  11.     at org.apache.ibatis.scripting.xmltags.IfSqlNode.apply(IfSqlNode.java:30) 
  12.     at org.apache.ibatis.scripting.xmltags.MixedSqlNode.apply(MixedSqlNode.java:29) 
  13.     at org.apache.ibatis.scripting.xmltags.TrimSqlNode.apply(TrimSqlNode.java:51) 
  14.     at org.apache.ibatis.scripting.xmltags.MixedSqlNode.apply(MixedSqlNode.java:29) 
  15.     at org.apache.ibatis.scripting.xmltags.DynamicSqlSource.getBoundSql(DynamicSqlSource.java:37) 
  16.     at org.apache.ibatis.mapping.MappedStatement.getBoundSql(MappedStatement.java:275) 
  17.     at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:79) 
  18.     at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:104) 
  19.     ... 3 more 
  20. Caused by: org.apache.ibatis.ognl.MethodFailedException: Method "size" failed for object [1] [java.lang.IllegalAccessException: Class org.apache.ibatis.ognl.OgnlRuntime can not access a member of class java.util.Collections$SingletonList with modifiers "public"] 
  21.     at org.apache.ibatis.ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:837) 
  22.     at org.apache.ibatis.ognl.ObjectMethodAccessor.callMethod(ObjectMethodAccessor.java:61) 
  23.     at org.apache.ibatis.ognl.OgnlRuntime.callMethod(OgnlRuntime.java:860) 
  24.     at org.apache.ibatis.ognl.ASTMethod.getValueBody(ASTMethod.java:73) 
  25.     at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170) 
  26.     at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:210) 
  27.     at org.apache.ibatis.ognl.ASTChain.getValueBody(ASTChain.java:109) 
  28.     at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170) 
  29.     at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:210) 
  30.     at org.apache.ibatis.ognl.ASTGreater.getValueBody(ASTGreater.java:49) 
  31.     at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170) 
  32.     at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:210) 
  33.     at org.apache.ibatis.ognl.ASTAnd.getValueBody(ASTAnd.java:56) 
  34.     at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170) 
  35.     at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:210) 
  36.     at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:333) 
  37.     at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:413) 
  38.     at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:395) 
  39.     at org.apache.ibatis.scripting.xmltags.OgnlCache.getValue(OgnlCache.java:45) 
  40.     ... 12 more 

(编辑:开发网_开封站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读