Topic
  • 1 reply
  • Latest Post - ‏2012-02-03T09:41:37Z by RigasGrigoropoulos
RigasGrigoropoulos
RigasGrigoropoulos
2 Posts

Pinned topic Bug in Introspector in Java 6 SR10

‏2012-02-03T09:36:26Z |
A new bug has been introduced in the Introspector in Java 6 SR10, probably by the fix for IZ94761 & IZ95114. This was found using the Linux x86_64 version.
The scenario is the following:
A superclass defines a Boolean property and a subclass a boolean property with the same name.
The result of calling Introspector.getBeanInfo for the subclass will contain the PropertyDescriptor with the ReadMethod properly set but the WriteMethod will be null.
The following example demonstrates the problem:

import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;

public class IntrospectorTest {
+ +
+ private static final String PROP_NAME = "testProperty";+
+ public static void main(String[] args) {+
+ try { +
+ Introspector.flushCaches();+
+ BeanInfo beanInfo = Introspector.getBeanInfo(TestSubclass.class);+
+ PropertyDescriptor[] propDescriptors = beanInfo.getPropertyDescriptors();+

+ for (PropertyDescriptor descr : propDescriptors) {+
+ if (descr.getDisplayName().contains(PROP_NAME)) { +
+ System.out.println("Getter for property " + descr.getName() + " = " + descr.getReadMethod());+
+ System.out.println("Setter for property " + descr.getName() + " = " + descr.getWriteMethod()); +
+ }+
+ }+
+ } catch (Exception e) {+
+ e.printStackTrace();+
+ }+
+ }+
+ +
+ public class TestSubclass extends TestSuperclass {+
+ +
+ private boolean testProperty;+

+ public boolean isTestProperty() {+
+ return testProperty;+
+ }+

+ public void setTestProperty(boolean testProperty) {+
+ this.testProperty = testProperty;+
+ }+
+ }+
+ +
+ public class TestSuperclass {+

+ private Boolean testProperty;+

+ public Boolean getTestProperty() {+
+ return testProperty;+
+ }+

+ public void setTestProperty(Boolean testProperty) {+
+ this.testProperty = testProperty;+
+ }+
+ }+
}
Updated on 2012-02-03T09:41:37Z at 2012-02-03T09:41:37Z by RigasGrigoropoulos
  • RigasGrigoropoulos
    RigasGrigoropoulos
    2 Posts

    Re: Bug in Introspector in Java 6 SR10

    ‏2012-02-03T09:41:37Z  
    Posting example again hopefully with better formatting this time.

    Example:

    import java.beans.BeanInfo;
    import java.beans.Introspector;
    import java.beans.PropertyDescriptor;

    public class IntrospectorTest {

    private static final String PROP_NAME = "testProperty";
    public static void main(String[] args) {
    try {
    Introspector.flushCaches();
    BeanInfo beanInfo = Introspector.getBeanInfo(TestSubclass.class);
    PropertyDescriptor[] propDescriptors = beanInfo.getPropertyDescriptors();

    for (PropertyDescriptor descr : propDescriptors) {
    if (descr.getDisplayName().contains(PROP_NAME)) {
    System.out.println("Getter for property " + descr.getName() + " = " + descr.getReadMethod());
    System.out.println("Setter for property " + descr.getName() + " = " + descr.getWriteMethod());
    }
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    }

    public class TestSubclass extends TestSuperclass {

    private boolean testProperty;

    public boolean isTestProperty() {
    return testProperty;
    }

    public void setTestProperty(boolean testProperty) {
    this.testProperty = testProperty;
    }
    }

    public class TestSuperclass {

    private Boolean testProperty;

    public Boolean getTestProperty() {
    return testProperty;
    }

    public void setTestProperty(Boolean testProperty) {
    this.testProperty = testProperty;
    }
    }
    }