JDK-6453295 : Java Bean Introspection changed in JDK 1.4.2_12
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.beans
  • Affected Version: 1.4.2_12
  • Priority: P2
  • Status: Closed
  • Resolution: Won't Fix
  • OS: solaris_8
  • CPU: sparc
  • Submitted: 2006-07-26
  • Updated: 2011-01-19
  • Resolved: 2006-08-02
Related Reports
Relates :  
Relates :  
Relates :  
Description
My customer has experienced a difference in behaviour in how Java Beans are handled between JDK 1.4.2_05 and JDK1.4.2_12

Below are two example of how to reproduce this behaviour:

Generic Reproducer:

public class Test {
         class MyBean extends TestBean {
             public String getMyValue(int i){
                return "abab";
            }
         }

         class TestBean {
            private String myvalue="bla";


         /*    public String getMyValue(){
                return myvalue;
            }*/

            public void setMyValue(String my){
                myvalue = my;
            }

        }

        public static void main(String[] args) throws Exception{


            BeanInfo beanInfo = Introspector.getBeanInfo(MyBean.class);
            PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();

            for (int i = 0; i < descriptors.length; i++) {
                System.out.println(i);
                System.out.println(descriptors[i].getName());
                System.out.println(descriptors[i].getPropertyType());
                System.out.println(descriptors[i].getReadMethod());
                System.out.println(descriptors[i].getWriteMethod());
                System.out.println();
            }
        }
    }


Ouput using JDK 1.4.2_05:
0
class
class java.lang.Class
public final native java.lang.Class java.lang.Object.getClass()
null

1
myValue
class java.lang.String
null
public void Test$TestBean.setMyValue(java.lang.String)

Ouput using JDK 1.4.2_12:
0
class
class java.lang.Class
public final native java.lang.Class java.lang.Object.getClass()
null

1
myValue
null
null
null

As you can see the result of the introspection is different.

I'll also show you the Web App, which resembles the behaviour we have initially identified:

Deploy this war file to your application server:

<<struts-test.ZIP>>

Call the localhost:<yourport>/struts-test/forms/register3.jsp page, enter a valid email address and leave the pasword blank, click submit.

Running the application server with JDK 1.4.2_05 will show you an error page saying that the pwd is invalid. If you run the application server with JDK 1.4.2_12 you will get a JspException, saying that the property "level" cannot be found.

The offending Java Bean looks like this:

public class Level1 {
    public String getLevel(){
        return "level1";
    }

    public String getLevel(int dummy){
        return "int method level1";
    }
}

From speaking with several engineers, I believe that this problem is similar (and related to) bug 4867168, which in turn, was caused by a regression introduced by the fix for 4750368.

The problem was initially introduced in 1.4.2_06, but my customer has only just noticed as they are upgrading from 1.4.2_05 to 1.4.2_12. This issue does appear to be fixed in 1.5, but my customer is unable to move to this version at present.

Comments
WORK AROUND I suggest the following workaround for the test: 1. Get PDs for MyBean class without parent Introspector.getBeanInfo(MyBean.class,MyBean.class.getSuperclass()); The test prints the following IndexedPropertyDescriptor: myValue PropertyType: null ReadMethod: null WriteMethod: null IndexedPropertyType: class java.lang.String IndexedReadMethod: public java.lang.String Test$MyBean.getMyValue(int) IndexedWriteMethod: null 2. Get PDs for TestBean class without parent Introspector.getBeanInfo(TestBean.class,TestBean.class.getSuperclass()); The test prints the following PropertyDescriptor: myValue PropertyType: class java.lang.String ReadMethod: null WriteMethod: public void Test$TestBean.setMyValue(java.lang.String) If they cannot rewrite both their beans and client code, they can create a BeanInfo class for the beans with conflicting methods, to specify the property type and accessor methods explicitely. It could be an acceptable solution that doesn't require rewriting existing code. *** (#1 of 1): [ UNSAVED ] ###@###.###
02-08-2006

EVALUATION I think we cann't to fix this bug, because this right behavior that was introduced, when the bug 4619536 was fixed.
31-07-2006

EVALUATION Requested fuctionality was changed some years ago. We should find the reason.
27-07-2006