Message4033

Author garyh
Recipients garyh
Date 2009-01-12.15:35:10
SpamBayes Score 0.033168435
Marked as misclassified No
Message-id <1231774512.61.0.267121482928.issue1232@psf.upfronthosting.co.za>
In-reply-to
Content
Jython's java bean property handling seems to be overly restrictive when
the property accessors are split over a class hierarchy.

Consider the java class structure:

public class Parent {
    protected int id;

    public Parent() {}

    public int getId() { return this.id; }
}

public class Child extends Parent {
    public Child() {}

    public void setId(int newid) { this.id = newid; }
}


In this case, obtaining an instance of Child and reading the "id"
property ("print child.id"), will return the error:
    AttributeError: write-only attr: id

With Beta 0, this only occurred with
python.security.respectJavaAccessibility=false.  With Beta 1, this now
occurs regards of the java accessiblity setting.

I've traced this down to the org.python.core.PyJavaType.init() method,
in the first for loop through the class methods.  I see two issues:

1) when respectJavaAccessiblity=false, we call
Class.getDeclaredMethods(), so never see the parent getter in the case
above when building the properties.
2) when respectJavaAccessiblity=true, we immediate continue the loop if
"!declaredOnMember(baseClass, meth)", so again never see the inherited
getter.

The attached patch addresses this by:
* when respectJavaAccessibility=false, including the hierarchy
superclass getDeclaredMethods() in the processing
* limiting the "declaredOnMember(baseClass, meth)" conditional handling
to the PyReflectedFunction setup, so event and bean property setup still
examines inherited methods

Not sure if this is the right approach, or the performance impact of
recursing up the hierarchy for respectJavaAccessibility=false.  If there
are any thoughts on potential problems, or ways of improving the patch,
please let me know.
History
Date User Action Args
2009-01-12 15:35:12garyhsetrecipients: + garyh
2009-01-12 15:35:12garyhsetmessageid: <1231774512.61.0.267121482928.issue1232@psf.upfronthosting.co.za>
2009-01-12 15:35:12garyhlinkissue1232 messages
2009-01-12 15:35:11garyhcreate