PropertyUtils.getProperty(bean,name)出现的问题 BeanApacheJavathread
程序员文章站
2022-07-14 19:07:22
...
public calss Point { private Double xPoint; private Double yPoint; getter and setter .... public static void main(String... args) { Point p = new Point(); p.setXPoint(12.3); PropertyUtils.getProperty(p, "xPoint"); } }
报错
Exception in thread "main" java.lang.NoSuchMethodException: Unknown property 'xPoint'
at org.apache.commons.beanutils.PropertyUtils.getSimpleProperty(PropertyUtils.java:1175)
at org.apache.commons.beanutils.PropertyUtils.getNestedProperty(PropertyUtils.java:772)
at org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:801)
当属性换用 xxPoint时便不报错。跟踪测试时发现反射得到的属性是 XPoint, 而非xPoint,这是怎么回事呢?
经查证实是commons-beanutils自身bug
https://issues.apache.org/jira/browse/BEANUTILS-30
https://issues.apache.org/jira/browse/BEANUTILS-323?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12613904#action_12613904