harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alexei Zakharov" <alexei.zakha...@gmail.com>
Subject Re: [classlib][beans] RI violates the spec in DefaultPersistenceDelegate
Date Wed, 20 Sep 2006 11:19:22 GMT
Thanks for the feedback Tim. HARMONY-1503 has been rised.

Regards,

2006/9/20, Tim Ellison <t.p.ellison@gmail.com>:
> I agree that it should use the BeanInfo.  Leave Harmony code as-is and
> file a non-bug difference JIRA.
>
> Regards,
> Tim
>
> Alexei Zakharov wrote:
> > <to whom it may concern>
> > Greetings to Harmony java beans experts.
> >
> > It seems I found another place where RI fails. The behavior of its
> > java.beans.DefaultPersistenceDelegate#DefaultPersistenceDelegate(String[])
> > IMHO violates at least 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
> > patterns.
> >  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 our 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) {
> >            super(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 (current):
> > ---
> > 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);
> >
> > I vote for ignoring RI and following the spec here.
> > Thanks for your attention,
> >
> >
>
> --
>
> Tim Ellison (t.p.ellison@gmail.com)
> IBM Java technology centre, UK.


-- 
Alexei Zakharov,
Intel Middleware Product Division

---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Mime
View raw message