-
Enhancement
-
Resolution: Won't Fix
-
P5
-
None
-
5.0
-
x86
-
windows_xp
FULL PRODUCT VERSION :
java version "1.5.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
EXTRA RELEVANT SYSTEM CONFIGURATION :
It's an API implementation bug, applies to all versions
A DESCRIPTION OF THE PROBLEM :
The following method from the java.beans.Introspector class:
static BeanInfo getBeanInfo(Class<?> beanClass)
doesn't detect write methods whose return type is not void. It is normal to return "this" in reply to a setter methods, so beans can be used more efficiently:
Example:
Person p = new Person().setName("Jon").setAge(15);
the setter for Name would be for example:
public Person setName(String name) {
this.name = name;
return this;
}
This method isn't interpreted as a "write method" by the getBeanInfo implementation and it is not possible to have both method types at the same time as a different return type is not enough to overload a method.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
class test
{
public static void main(String[] args) {
try {
BeanInfo info = Introspector.getBeanInfo(Person.class);
Method writeMethod = info.getPropertyDescriptors()[1].getWriteMethod();
System.out.println(writeMethod);
} catch (IntrospectionException e) {}
}
}
public class Person {
private String name;
public String getName(String name) {
return name;
}
// If you make it void it gets recognized
public Person setName(String name) {
this.name = name;
return this;
}
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No exceptions as the attribute is recognized as a JavaBean property
ACTUAL -
Exception because the property is not recognized
REPRODUCIBILITY :
This bug can be reproduced always.
CUSTOMER SUBMITTED WORKAROUND :
Writing a home grown Bean Inspector
java version "1.5.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
EXTRA RELEVANT SYSTEM CONFIGURATION :
It's an API implementation bug, applies to all versions
A DESCRIPTION OF THE PROBLEM :
The following method from the java.beans.Introspector class:
static BeanInfo getBeanInfo(Class<?> beanClass)
doesn't detect write methods whose return type is not void. It is normal to return "this" in reply to a setter methods, so beans can be used more efficiently:
Example:
Person p = new Person().setName("Jon").setAge(15);
the setter for Name would be for example:
public Person setName(String name) {
this.name = name;
return this;
}
This method isn't interpreted as a "write method" by the getBeanInfo implementation and it is not possible to have both method types at the same time as a different return type is not enough to overload a method.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
class test
{
public static void main(String[] args) {
try {
BeanInfo info = Introspector.getBeanInfo(Person.class);
Method writeMethod = info.getPropertyDescriptors()[1].getWriteMethod();
System.out.println(writeMethod);
} catch (IntrospectionException e) {}
}
}
public class Person {
private String name;
public String getName(String name) {
return name;
}
// If you make it void it gets recognized
public Person setName(String name) {
this.name = name;
return this;
}
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No exceptions as the attribute is recognized as a JavaBean property
ACTUAL -
Exception because the property is not recognized
REPRODUCIBILITY :
This bug can be reproduced always.
CUSTOMER SUBMITTED WORKAROUND :
Writing a home grown Bean Inspector