Message6611

Author richardfearn
Recipients dominik, richardfearn
Date 2011-08-24.19:20:52
SpamBayes Score 2.4970026e-12
Marked as misclassified No
Message-id <1314213653.7.0.456450226107.issue1785@psf.upfronthosting.co.za>
In-reply-to
Content
Dominik is right - 2.2.1 did throw an AttributeError, but 2.5.* doesn't.

This seems to be due to a change in org.python.compiler.ProxyMaker.

When ProxyMaker adds a method to the proxy class it is building (in its addMethod method), it knows when the method is abstract.

In 2.2.1, the proxy called Py.jgetattr, which would end up throwing the AttributeError.

In 2.5.*, the proxy calls ProxyMaker.findPython to get, from the underlying PyObjectDerived object, the attribute that corresponds to the invoked method's name. Since that attribute is not set on the object (i.e. the method is not overridden), it gets back the PyMethod corresponding to the proxy method currently being invoked. But it recognises this, and returns null. Since the proxy then has no method to invoke, it skips over the code generated by callMethod, to the code generated by doNullReturn - which returns a zero/false/null value, as appropriate for the return type of the method being invoked.

So the end result of this is that the proxy knows the method is abstract, knows it hasn't been overridden by the object, but returns zero/false/null.

Adding this before the doNullReturn call:

    throwNotImplementedException(code, name);

and adding these two methods to ProxyMaker:

    protected static void throwNotImplementedException(Code code, String name) {
        code.ldc(name);
        code.invokestatic("org/python/compiler/ProxyMaker", "throwNotImplementedException", "(Ljava/lang/String;)V");
    }

    public static void throwNotImplementedException(String name) throws PyException {
        String msg = "abstract method \"" + name + "\" not implemented";
        throw new PyException(Py.AttributeError, new PyString(msg));
    }

seems to work. Patch attached.

(Disclaimer: not extensively tested, I'm not a Jython developer, etc. etc.)
History
Date User Action Args
2011-08-24 19:20:53richardfearnsetmessageid: <1314213653.7.0.456450226107.issue1785@psf.upfronthosting.co.za>
2011-08-24 19:20:53richardfearnsetrecipients: + richardfearn, dominik
2011-08-24 19:20:53richardfearnlinkissue1785 messages
2011-08-24 19:20:53richardfearncreate