commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Pl├╝mpe <>
Subject [beanutils] Inherited property can not be read (but written) when superclass is friendly
Date Tue, 09 Sep 2003 19:24:29 GMT

I'm unable to get the property of a bean when the accessor method has
been defined (abstractly or concretely) in a package-private superclass.
Setting the property works fine.

At first I thought this was due to the PropertyDescriptor referencing
the wrong read method -- the one in the superclass, which is abstract:
    Object bean = new MyClass();
    PropertyUtilsBean pub = new PropertyUtilsBean();
    PropertyDescriptor pDesc = pub.getPropertyDescriptor(bean, "id");
    System.out.println("read method = " + pDesc.getReadMethod());
    System.out.println("write method = " + pDesc.getWriteMethod());


    read method =
        public abstract java.lang.String MySuperClass.getId()

    write method =
        public void MyClass.setId(java.lang.String).

[Note that the read method is said to be in MySuperClass and the write
method in MyClass, which is surprising (to me anyway), as both are
abstractly defined in the superclass and implemented in the subclass.]

But when I made the superclass public, getting the property worked
nicely, although the read method is still given as MySuperClass.getId().
I then found the failure to be caused by this check

        // If the declaring class is public, we are done
        Class clazz = method.getDeclaringClass();
        if (Modifier.isPublic(clazz.getModifiers())) {
            return (method);

in MethodUtils.getAccessibleMethod(Method), which obviously fails for a
friendly superclass and works for a public one.

I'm not sure where the bug is: Should the property descriptor return the
declaring class MyClass for the read method (which it does for the
setter's write method and looks like least surprise to me) or should the
above quoted check be more elaborate (which it can hardly be, as it
would have to guess the applicable subclass)?

All of this using Sun's Linux j2sdk-1.4.2_01 and beanutils-1.6.1, same
with cvs as of 9.9.2003. Test classes attached.

Any help greatly appreciated,

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message