Author richardfearn
Recipients dominik, richardfearn
Date 2011-08-24.19:20:52
SpamBayes Score 2.4970026e-12
Marked as misclassified No
Message-id <>
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.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.)
Date User Action Args
2011-08-24 19:20:53richardfearnsetmessageid: <>
2011-08-24 19:20:53richardfearnsetrecipients: + richardfearn, dominik
2011-08-24 19:20:53richardfearnlinkissue1785 messages
2011-08-24 19:20:53richardfearncreate