JDK-4346874 : Introspector returns incorrect BeanInfo class
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.beans
  • Affected Version: 1.3.0
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: generic
  • CPU: generic
  • Submitted: 2000-06-20
  • Updated: 2002-05-23
  • Resolved: 2002-05-23
Related Reports
Relates :  
Description

Name: stC104175			Date: 06/20/2000


Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

Let's assume I've created a class called "com.mycompany.Component". The
following code:

Introspector.getBeanInfo(Class.forName("com.mycompany.Component"));

will return java.beans.BeanInfo with property descriptors for
java.awt.Component, i.e. Introspector picks up property descriptors from the
class in different package, which is wrong.

The source that I used to reproduce the problem follows:

import java.beans.*;

class Test {
static public void main(String[] args) {
        try {
                PropertyDescriptor[]  properties = Introspector.getBeanInfo
(com.mycompany.Component.class).getPropertyDescriptors();
                for (int i = 0; i < properties.length; ++i) {
                       System.out.println(properties[i].getName());
                }

        }
        catch (IntrospectionException e) {
                e.printStackTrace();
        }
}
}
(Review ID: 106167) 
======================================================================

Comments
PUBLIC COMMENTS .
10-06-2004

EVALUATION This problem is exclusive to Introspecting Beans with the name "Component". By default, the Introspector defines the classpath for which it searches for explicit BeanInfos to be "sun.beans.infos". This package is located in the Java Runtime archive (jre\lib\rt.jar) and contains only one class: ComponentBeanInfo. When a class called "Component" defined in any package is introspected, the first action that occus is to find an explicit BeanInfo for the class. The flexibility of the setBeanInfoSearchPath() method is a double edged sword because it allows for the definition of BeanInfo classes outside of the package for which it had been defined in. The default behaviour of the Introspector is to retrieve the sun.beans.infos.ComponentBeanInfo BeanInfo class for all Beans which are named Component. There are a couple of work arounds for this which are discussed in the work arounds section of this report. This is a problem and one of our licencees feel it is such so I will keep this bug open and have a resolution for the next release. mark.davidson@Eng 2000-06-21 The solution for this is to move the sun.beans.infos.ComponentBeanInfo class to the java.awt package. Also, the default BeanInfo search path should be an empty String[]. This will increase Introspector performance. See 4520754. After these two changes, there shouldn't be a problem. In the meantime, you can implements the suggestions in the work around section. ###@###.### 2001-10-29 After talking with some vendors, they are hesitant from pulling the sun.beans.infos.ComponentBeanInfo class since that would introduce a lot of extra properties. If you want to name you JavaBeans "Component" then you must change the BeanInfoSearch path to be the empty String array or the package name to find your BeanInfo. ###@###.### 2002-05-22
22-05-2002

WORK AROUND Name: stC104175 Date: 06/20/2000 There is none. ====================================================================== Sure there is. Set BeanInfo search path to be an empty String array so that the sun.beans.infos path is not searched: Introspector.setBeanInfoSearchPath(new String[] {}); This way, the explicit java.awt.Component BeanInfo class (located in sun.beans.infos.ComponentBeanInfo) is not picked up. You cannot set the BeanInfo search path to null since it will cause havoc in the Introspector see 4167121. Another workaround is to write your own explicit ComponentBeanInfo and place it in the same package as your own Component class. mark.davidson@Eng 2000-06-21
21-06-2000