JDK-4751725 : Wrong introspection result for custom class named "Component"
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.beans
  • Affected Version: 1.4.1
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2002-09-23
  • Updated: 2002-09-23
  • Resolved: 2002-09-23
Related Reports
Duplicate :  
Description
The attached program uses Introspector.getBeanInfo() to get the BeanInfo associated with the class specified on the command line, and then enumerates the PropertyDescriptor[] returned by BeanInfo.getPropertyDescriptors().

I have a class named "Component" in a package named "test" (attached). This class defines a single getter method (getData()).

When I specify "test.Component" as the class to be introspected, I am getting the following wrong result, which looks more like the result of introspecting
"java.awt.Component":

  java Introspect test.Component
  class: test.Component
  pd.length: 7
  0:
  public java.awt.Color java.awt.Component.getBackground()
  class java.awt.Color
  1:
  public boolean java.awt.Component.isEnabled()
  boolean
  2:
  public boolean java.awt.Component.isFocusable()
  boolean
  3:
  public java.awt.Font java.awt.Component.getFont()
  class java.awt.Font
  4:
  public java.awt.Color java.awt.Component.getForeground()
  class java.awt.Color
  5:
  public java.lang.String java.awt.Component.getName()
  class java.lang.String
  6:
  public boolean java.awt.Component.isVisible()
  boolean

However, when i specify "test.component" (with a lower-case 'c') as
the class to be introspected, I get the expected result:

  java Introspect test.component
  class: test.component
  pd.length: 2
  0:
  public final native java.lang.Class java.lang.Object.getClass()
  class java.lang.Class
  1:
  public java.lang.String test.component.getData()
  class java.lang.String

Introspecting "test.Color" (with upper-case 'C') also seems to work as
expected:

  java Introspect test.Color 
  class: test.Color
  pd.length: 2
  0:
  public final native java.lang.Class java.lang.Object.getClass()
  class java.lang.Class
  1:
  public java.lang.String test.Color.getData()
  class java.lang.String

Comments
EVALUATION This is a duplicate of 4346874. A similar bug, 4750368, was filed recently that presented an excellent solution. The problem is that any class named Component will probably pick up the ComponentBeanInfo in the class path sun.beans.infos. The solution to 4750368 will fix this problem. See the workaround section for a workaround. ###@###.### 2002-09-23
23-09-2002

WORK AROUND 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. ###@###.### 2002-09-23
23-09-2002