-
Bug
-
Resolution: Fixed
-
P3
-
1.2.0
-
None
-
1.2fcs
-
x86
-
windows_nt
-
Not verified
In JDK 1.2 beta4, it is not possible for a user to provide BeanInfo for
any of the core classes. I have reported this as a bug using the bug
submission form, but I thought I would mail you about it as well, as I
very much hope that it will be fixed as soon as possible. The details of the
problem are as follows:
I would like to provide a BeanInfo for a core class, lets say
java.awt.Component, for example. So I write a
my.beans.infos.ComponentBeanInfo class, and use the
Introspector.setBeanInfoSearchPath() method to put my.beans.infos on
the search path. Example source code for this is provided below. This
all works OK under 1.2beta3 and earlier, but under 1.2beta4 the
Introspector fails to find my BeanInfo. It does work if you use the
1.2Beta4 oldjava program. I believe the problem is due to the changes
in class loading in 1.2Beta4. What happens is that the Introspector
tries to get a classloader by using the getClassLoader() method, but
for the java.awt.Component class this returns null, because
java.awt.Component is a bootstrap class. Therefore the Introspector
uses Class.forName("my.beans.infos.ComponentBeanInfo") instead. This
fails because Class.forName() uses the classloader of the class it is
called from, and java.beans.Introspector is a bootstrap class, and the
bootstrap classloader fails because my.beans.infos.ComponentBeanInfo is
not a bootstrap class.
Note that a similar problem occurs with property editors and the
PropertyEditorManager.
Here is some source code that shows the problem:
BeanInfoCheck.java:
import java.beans.*;
public class BeanInfoCheck {
public static void main(String[] args) throws Exception {
String[] beanInfoPath = {"my.beans.infos"};
Introspector.setBeanInfoSearchPath(beanInfoPath);
BeanInfo bi = Introspector.getBeanInfo(java.awt.Component.class);
PropertyDescriptor[] pds = bi.getPropertyDescriptors();
for (int j = 0; j < pds.length; j++) {
System.out.println(pds[j].getName());
}
}
}
my.beans.infos.ComponentBeanInfo.java:
package my.beans.infos;
import java.beans.*;
public class ComponentBeanInfo extends SimpleBeanInfo {
public PropertyDescriptor[] getPropertyDescriptors() {
try {
PropertyDescriptor name =
new PropertyDescriptor("name", java.awt.Component.class);
PropertyDescriptor[] rv = {name};
return rv;
} catch (IntrospectionException e) {
throw new Error(e.toString());
}
}
}
Instructions:
Run "java BeanInfoCheck". It should just print out "name", but in fact
it prints out all the properties. It works correctly with oldjave or
previous JDKs.
[This came in on the java.beans alias]
graham.hamilton@Eng 1998-08-22
any of the core classes. I have reported this as a bug using the bug
submission form, but I thought I would mail you about it as well, as I
very much hope that it will be fixed as soon as possible. The details of the
problem are as follows:
I would like to provide a BeanInfo for a core class, lets say
java.awt.Component, for example. So I write a
my.beans.infos.ComponentBeanInfo class, and use the
Introspector.setBeanInfoSearchPath() method to put my.beans.infos on
the search path. Example source code for this is provided below. This
all works OK under 1.2beta3 and earlier, but under 1.2beta4 the
Introspector fails to find my BeanInfo. It does work if you use the
1.2Beta4 oldjava program. I believe the problem is due to the changes
in class loading in 1.2Beta4. What happens is that the Introspector
tries to get a classloader by using the getClassLoader() method, but
for the java.awt.Component class this returns null, because
java.awt.Component is a bootstrap class. Therefore the Introspector
uses Class.forName("my.beans.infos.ComponentBeanInfo") instead. This
fails because Class.forName() uses the classloader of the class it is
called from, and java.beans.Introspector is a bootstrap class, and the
bootstrap classloader fails because my.beans.infos.ComponentBeanInfo is
not a bootstrap class.
Note that a similar problem occurs with property editors and the
PropertyEditorManager.
Here is some source code that shows the problem:
BeanInfoCheck.java:
import java.beans.*;
public class BeanInfoCheck {
public static void main(String[] args) throws Exception {
String[] beanInfoPath = {"my.beans.infos"};
Introspector.setBeanInfoSearchPath(beanInfoPath);
BeanInfo bi = Introspector.getBeanInfo(java.awt.Component.class);
PropertyDescriptor[] pds = bi.getPropertyDescriptors();
for (int j = 0; j < pds.length; j++) {
System.out.println(pds[j].getName());
}
}
}
my.beans.infos.ComponentBeanInfo.java:
package my.beans.infos;
import java.beans.*;
public class ComponentBeanInfo extends SimpleBeanInfo {
public PropertyDescriptor[] getPropertyDescriptors() {
try {
PropertyDescriptor name =
new PropertyDescriptor("name", java.awt.Component.class);
PropertyDescriptor[] rv = {name};
return rv;
} catch (IntrospectionException e) {
throw new Error(e.toString());
}
}
}
Instructions:
Run "java BeanInfoCheck". It should just print out "name", but in fact
it prints out all the properties. It works correctly with oldjave or
previous JDKs.
[This came in on the java.beans alias]
graham.hamilton@Eng 1998-08-22
- relates to
-
JDK-6582164 JavaBeans tests should be open source
- Resolved