harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alexei Zakharov (JIRA)" <j...@apache.org>
Subject [jira] Created: (HARMONY-1503) [classlib][beans] Harmony uses standard introspection procedure for DefaultPersistenceDelegate constructor
Date Wed, 20 Sep 2006 10:55:23 GMT
[classlib][beans] Harmony uses standard introspection procedure for DefaultPersistenceDelegate

                 Key: HARMONY-1503
                 URL: http://issues.apache.org/jira/browse/HARMONY-1503
             Project: Harmony
          Issue Type: Improvement
          Components: Non-bug differences from RI
         Environment: win
            Reporter: Alexei Zakharov

The behavior of RI's implementations of java.beans.DefaultPersistenceDelegate#DefaultPersistenceDelegate(String[])
violates the following part of the spec (JavaBeans spec v1.01 page 57):

8.7. Analyzing a Bean

 We allow both explicit specification of a bean's exposed
properties/methods/events and also implicit analysis using design
 To simplify access to this information, and to make sure that all
tools apply the same analysis rules, we provide a class
java.beans.Introspector that should be used to analyze a bean class.
It allows you to obtain a BeanInfo object that comprehensively
describes a target bean class.
 The Introspector class walks over the class/superclass chain of the
target class. At each level it checks if there is a matching BeanInfo
class which provides explicit information about the bean, and if so
uses that explicit information. Otherwise it uses the low level
reflection APIs to study the target class and uses design patterns to
analyze its behaviour and then proceeds to continue the introspection
with its baseclass. (See the Introspector class definition for a full
description of the analysis rules.)

The test below illustrates that RI does not care about explicitly
specified BeanInfo class and uses the reflection API instead. Please
note that Harmony implementation behaves correctly in this situation. This
is the reason why some tests from DefaultPersistenceDelegateTest fail
- they are "optimized" for this RI behavior.

The test case:
import java.beans.*;

public class DefaultPDtest {

   public static class MyFoo {
       String ugh;

       public MyFoo(String str) {
           ugh = str;

       public String myget() {
           return ugh;

       public void myset(String val) {
           ugh = val;

   public static class MyFooBeanInfo extends SimpleBeanInfo {
       public PropertyDescriptor[] getPropertyDescriptors() {
           PropertyDescriptor pd;

           try {
               pd = new PropertyDescriptor("prop1",
                       MyFoo.class, "myget", "myset");
           } catch (IntrospectionException e) {
               throw new RuntimeException(e);
           return new PropertyDescriptor[] { pd };

   public static class MyPersistenceDelegate
           extends DefaultPersistenceDelegate {
       public MyPersistenceDelegate(String[] propNames) {

       protected Expression instantiate(Object oldInstance, Encoder out) {
           return super.instantiate(oldInstance, out);

   public static void main(String argv[]) {
       Encoder enc = new Encoder();
       MyPersistenceDelegate pd;
       MyFoo oldBean = new MyFoo("harmony");
       Expression expr;

       System.out.println("Test1: arg should be \"harmony\"");
       pd = new MyPersistenceDelegate(new String[] {"prop1"});
       expr = pd.instantiate(oldBean, enc);
       System.out.println("Constructor to call: " + expr);

       System.out.println("Test2: arg should be null");
       pd = new MyPersistenceDelegate(new String[] {"ugh"});
       expr = pd.instantiate(oldBean, enc);
       System.out.println("Constructor to call: " + expr);



Output on RI (Sun 1.5.0_06):
Test1: arg should be "harmony"
java.lang.NoSuchMethodException: DefaultPDtest$MyFoo.getProp1
Continuing ...
Constructor to call: DefaultPDtest$MyFoo=Class.new(null);
Test2: arg should be null
Constructor to call: DefaultPDtest$MyFoo=Class.new("harmony");

Output on Harmony (r447840):
Test1: arg should be "harmony"
Constructor to call: DefaultPDtest$MyFoo=Class.new("harmony");
Test2: arg should be null
class java.lang.NoSuchMethodException: no property for name ugh is found
Constructor to call: DefaultPDtest$MyFoo=Class.new(null);

It was decided in the mailing list [1] that we should ignore RI and follow the spec here.

[1] http://mail-archives.apache.org/mod_mbox/incubator-harmony-dev/200609.mbox/%3c4510FACC.8080109@gmail.com%3e

This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira


View raw message