-
Bug
-
Resolution: Fixed
-
P4
-
1.2.0, 1.2.2
-
beta
-
generic
-
generic
Name: wl91122 Date: 08/10/99
I just noticed some *very* scary changes to the jdk1.2 beans package. Specifically, the
addition and use of what is documented as "Package-private dup constructor" e.g.,
GenericBeanInfo(GenericBeanInfo old), PropertyDescriptor(PropertyDescriptor old). This is
an example extremely poor design, which happens to break a lot of existing Beans extensions.
For example I have a class which extends PropertyDescriptor to handle multiple inspection,
property hierarchies, correctly sorted properties, auto-update, etc. My bean inspector can
inspect any kind of bean; beans that expose properties with my extension can fully exploit all
the nifty features in my inspector and still function in standard inspectors e.g., bean box.
Unfortunately the aforementioned changes no longer allow for any meaningful extensions to
the beans package. This is rather alarming because the classes are public and are inviting this
sort of thing.
Again, this problem can be devastating for beans that expose meta info via
explicit BeanInfos. For example, PropertyDescriptor is a public class with
public constructors which invites (if not encourages) subclassing. But use
of the "package-private dup" constructor abandons information specific to a
subclass of PropertyDescriptor.
Another even more alarming problem is that the Introspector caches
descriptors. My BeanInfo class might return a *different* set of
descriptors depending on conditions the Introspector can definitely not
anticipate. Yet the Introspector caches descriptors assuming they are
static. Not only is this very poor judgement, NO WHERE in the beans
specification is it documented that the descriptors returned from a BeanInfo
are cached.
(Review ID: 52628)
======================================================================
Name: skT45625 Date: 06/07/2000
java version "1.2.2"
HotSpot VM (1.0.1, mixed mode, build g)
Given a BeanInfo implementing class, if you try to set the 'preferred' flag it
does not get kept by the Introspector in its shell-game of copy-constructing
FeatureDescriptors, due to the fact that the copy-constructor does not transfer
that field. (it does however keep the 'hidden' and 'expert' flag/fields)
What follows is an ultra simple example of the 3 classes I used: MBean.java,
MBeanBeanInfo.java and Test.java
public class MBean
{
public void setA (String arg)
{
}
public void setB (int arg)
{
}
public void setC (long arg)
{
}
}
import java.beans.SimpleBeanInfo;
import java.beans.PropertyDescriptor;
public class MBeanBeanInfo extends SimpleBeanInfo
{
private PropertyDescriptor[] pds = null;
public MBeanBeanInfo ()
{
pds = new PropertyDescriptor[3];
try
{
pds[0] = new PropertyDescriptor("a", MBean.class, null, "setA");
pds[0].setHidden(true);
pds[1] = new PropertyDescriptor("b", MBean.class, null, "setB");
pds[1].setExpert(true);
pds[2] = new PropertyDescriptor("c", MBean.class, null, "setC");
pds[2].setPreferred(true);
System.out.println(" preferred = "+pds[2].isPreferred());
}
catch (Exception e)
{
System.out.println(e);
}
}
public PropertyDescriptor[] getPropertyDescriptors ()
{
return pds;
}
}
import java.beans.BeanInfo;
import java.beans.PropertyDescriptor;
import java.beans.Introspector;
public class Test
{
public static void main (String[] args)
{
try
{
BeanInfo bi = Introspector.getBeanInfo(MBean.class);
PropertyDescriptor[] pds = bi.getPropertyDescriptors();
for (int i = 0; i < pds.length; i++)
{
if (pds[i].getWriteMethod() != null)
{
System.out.println("property = "+pds[i].getName());
System.out.println(" hidden = "+pds[i].isHidden());
System.out.println(" expert = "+pds[i].isExpert());
System.out.println(" preferred = "+pds[i].isPreferred());
}
}
}
catch (Exception e)
{
System.out.println(e);
}
}
}
(Review ID: 105842)
======================================================================