- 浏览: 596178 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (213)
- jdk (40)
- J2EE (8)
- JavaScript (16)
- spring (1)
- 正则 (10)
- ORACLE (18)
- CSS (1)
- 生活学习 (14)
- XML (3)
- Linux (11)
- 项目架设 (12)
- Junit (1)
- Derby (3)
- JMX (5)
- 版本控制 (4)
- PowerDesigner (1)
- 加密解密 (1)
- android (4)
- Eclipse (4)
- Hibernate (6)
- Tomcat (4)
- JasperReport&iReport (1)
- SqlServer (6)
- C++ (3)
- 系统架构涉及名词解释 (5)
- Hadoop (8)
- windows (2)
- SOA (1)
- 有趣的Google (1)
- 编程语言 (0)
- 数据结构与算法 (1)
- nodejs (1)
- 一些测试整理备份在这里吧 (0)
- 性能 (3)
- Drill (5)
- 学习 (1)
最新评论
由ApacheCommon-BeanUtils1.8.3发现的Java的Bug
org.apache.commons.beanutils.BeanUtils.copyProperties(Object dest, Object orig) throws IllegalAccessException, InvocationTargetException
我实际工程中orig参数是一个实现了泛型接口的类
public class BaseRole implements java.io.Serializable,Sortable<Long> {
// Fields
private Long sort;
...略
public Long getSort() {
return this.sort;
}
public void setSort(Long sort) {
this.sort = sort;
}
}
接口为
public interface Sortable<T> {
public T getSort();
}
这个BaseRole中的sort是无法通过BeanUtils.copyProperties 写入值的
原因是BeanUtils.copyProperties 底层使用了
BeanInfo beanInfo = Introspector.getBeanInfo(BaseRole.class);
PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
而Java在这里是有Bug的
不能完全信任修复速度,1.6.0_05的BUG,我这跑的1.6.0_31仍未修复此问题!!
google 一下 BeanInfo.getPropertyDescriptors problem
第一个就是 sun 的Bug bolg
http://bugs.sun.com/view_bug.do?bug_id=6788525
Bug ID: |
6788525 |
Votes |
1 |
Synopsis |
RFE: BeanInfo.getPropertyDescriptors() gets mixed up with generic bridge methods |
Category |
java:classes_beans |
Reported Against |
|
Release Fixed |
|
State |
3-Accepted, request for enhancement |
Priority: |
4-Low |
Related Bugs |
|
Submit Date |
23-DEC-2008 |
Description |
FULL PRODUCT VERSION : java version "1.6.0_05" Java(TM) SE Runtime Environment (build 1.6.0_05-b13) Java HotSpot(TM) Client VM (build 10.0-b19, mixed mode)
ADDITIONAL OS VERSION INFORMATION : customer Windows XP [versão 5.1.2600]
A DESCRIPTION OF THE PROBLEM : If a JavaBean class has properties that are inherited from a generic superclass, java.beans.BeanInfo will find a PropertyDescriptor corresponding to synthetic bridge methods and not the actual typed methods.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : Create a generic superclass with a property (getter/setter pair) whose type is a type parameter. Create a parametrized subclass (a subclass with actual type arguments). Use java.beans.Introspector.getBeanInfo() to get a BeanInfo representing the subclass. Notice that the PropertyDescriptor that would correspond to the property (meaning, it's name is the same as the name of the property) has a type equal to the upper bound of the type parameter in the superclass, where we would expect it to have the corresponding type argument defined on the subclass.
This behavior is likely due to the Introspector finding synthetic bridge methods for the getter and setter instead of the actual methods.
(The Expected and Actual results below refer to the output of the sample code)
EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - class of type class java.lang.Class foo of type class java.lang.String
ACTUAL - class of type class java.lang.Class foo of type class java.lang.Object
REPRODUCIBILITY : This bug can be reproduced always.
---------- BEGIN SOURCE ---------- import java.beans.*;
class Super<T> { public T getFoo() {return null;} public void setFoo(T t) {} }
class Sub extends Super<String> { }
public class Main { public static void main(String[] args) throws IntrospectionException { BeanInfo beanInfo = Introspector.getBeanInfo(Sub.class);
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
for (PropertyDescriptor prop : propertyDescriptors) { System.out.printf("%s of type %s\n", prop.getName(), prop.getPropertyType()); } } } ---------- END SOURCE ---------- Posted Date : 2008-12-23 13:21:58.0 |
Work Around |
N/A |
Evaluation |
N/A |
Comments |
One more thing about this bug is that when interface Super<T> do not have set method. And Sub have this set method.
When called BeanInfo beanInfo = Introspector.getBeanInfo(Sub.class);
The PropertyDescriptor for foo do not have write method. But what I expected is although the interface Super do not have set method, but I am asking for the BeanInfo of Sub, its PropertyDescriptor should have writeMethod returned.
This is quite an annoying bug to run into and requires a bit of knowledge of the JLS to understand what is going on. I ran into this problem trying to get annotations of the method and was baffled as to why it wasn't working.
|
发表评论
-
关于饿汉式单例首次初始化失败后,可以再次尝试?
2012-07-11 15:14 1265思考一个问题,以下代码是一个简单的饿汉式单例代码,显然在第一次 ... -
JVM垃圾回收
2012-04-19 13:02 3526一、JVM内存模型及垃圾收集算法 1.根据Java虚 ... -
Java构建HashCode相同字符串算法
2012-01-10 15:05 5564import java.math.BigDecimal; ... -
线程全部结束与集合点
2011-11-12 16:26 1254final int size = 50; fin ... -
ddddddddd
2011-11-12 16:21 1258dddddddddd -
ccccccc
2011-11-12 16:20 1999ccccccccccc -
bbbbbb
2011-11-12 16:19 1798bbbbb -
Aaaaa
2011-11-12 16:19 938aaaaaaaa -
备忘链接
2011-08-16 18:25 958翻译,随便写了写,备忘一下 URLConnection co ... -
jvisualvm监听JVM
2011-08-05 10:14 1208配置好 set JAVA_OPTS=%JAVA_OPTS ... -
JVM 调优 技巧
2011-08-02 15:59 12641.升级 JVM 版本。如果能使用64-bit,使用64-bi ... -
JVM垃圾回收策略
2011-08-02 14:59 1066为什么要分代 分代的垃圾回收策略,是基于这样一个事实:不 ... -
Java GC
2011-08-02 13:38 1057调整JVM GC(Garbage Collection),可 ... -
Java的弱引用(Weak Reference)
2011-05-18 16:07 1251要理解弱引用,首先要 ... -
使用classloader动态加载Class
2011-05-17 14:25 969http://www.javaworld.com/javawo ... -
查看class文件信息
2011-05-16 14:15 1708看了第6章的java class文件这一部分,我觉得对clas ... -
.class文件格式--java字节码文件的格式
2011-05-14 23:07 25461 . 目的 Java 虚拟机识别的 class 文件格式包含 ... -
Calendar
2011-03-30 14:13 1059/**获得参数月份的一号及其下一个月的一号*/ priva ... -
Bad version number in .class file
2011-03-04 15:08 1342java.lang.UnsupportedClassVersi ... -
Java反射之:判断修饰符
2010-12-24 11:36 2600import java.lang.reflect.Modifi ...
相关推荐
在给定的压缩包文件中,包含了两个版本的Apache Commons BeanUtils库:`commons-beanutils-1.8.0`和`commons-beanutils-1.8.3`。 Apache Commons BeanUtils的核心功能包括: 1. **属性访问**:BeanUtils提供了一...
commons-beanutils-1.8.3是配置服务端打开工程所需要的一些相关的jar文件包,分别是:commons-beanutils-1.8.3.jarcommons-collections-3.2.1.jarcommons-lang-2.6.jarcommons-logging-1.2.jarezmorph-1.0.6.jarjson...
在实际应用中,`commons-beanutils-1.8.3.jar`常与其他Apache Commons库(如Collections、Lang等)结合使用,以实现更强大的功能。例如,结合Commons Collections,可以方便地处理复杂的数据结构;结合Commons Lang...
commons-beanutils-1.8.3.rar官方正版免费版,BeanUtils主要提供了对于JavaBean进行各种操作。 个包主要提供用于操作JavaBean的工具类,Jakarta-Common-BeanUtils的主要功能都在这个包里实现。
commons-beanutils-core-1.8.3.jar
commons-beanutils-1.8.3-bin.zip
commons-beanutils-1.8.3 java api chm 自己要用,就做了一个,反正我觉得很好,就和大家分享一下
commons-beanutils-1.8.3-src.zip
commons-beanutils-1.8.3。commons-beanutils是Apache开源组织提供的用于操作JAVA BEAN的工具包。使用commons-beanutils,我们可以很方便的对bean对象的属性进行操作。
这个"commons-beanutils-1.8.3-bin.rar"压缩包包含了版本为1.8.3的BeanUtils库的二进制文件,用于简化Java开发中的对象属性操作。 在Java编程中,BeanUtils库是一个非常实用的工具,它基于JavaBeans规范,允许...
总之,“commons-beanutils-1.8.3-sources.jar”作为Apache Commons BeanUtils的一个版本,包含的源代码对于理解和优化使用该库的代码非常有价值。了解并掌握BeanUtils的使用,能够提升Java开发的效率,同时也能增强...
从commons-beanutils-1.8.3.jar中删除了org/apache/commons/collections目录及其下的类,避免了与commons-collections-3.2.jar一起在android中使用时报Andorid Unable to execute dex: Multiple dex files define错...
标题和描述中提到的"commons-beanutils-1.8.3.jar", "commons-codec-1.7.jar", "commons-collections-3.2.1.jar"是Apache Commons项目中的三个不同组件的JAR文件,这些文件在Java开发中被广泛使用。Apache Commons是...
在开始JSP上传文件之前你要准备以下几个东西: 1. commons-FileUpload 1.2 包 下载地址:...3. Commons-BeanUtils 1.7 包 下载地址:http://jakarta.apache.org/commons/beanutils/
1. **Apache Commons BeanUtils 1.8.3**: Apache Commons BeanUtils是一个实用工具库,它提供了一种简单的方式来操纵Java Beans属性。这个库的核心功能是提供一种方便的方式,通过属性名来设置和获取对象的属性值...