Message11630

Author alexgobbo
Recipients alexgobbo
Date 2017-10-23.09:39:50
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1508751592.19.0.213398074469.issue2634@psf.upfronthosting.co.za>
In-reply-to
Content
Jython cannot access final protected methods. For example the code:


package test;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;

public class Final {
    public static class TestClass {
        protected void method1() {
            System.out.println("On protected");
        }
        final public void method2() {
            System.out.println("On final public");
        }        
        final protected void method3() {
            System.out.println("On final protected");
        }        
    }

    public static void main(String[] args) throws Exception {
        ScriptEngine engine = new ScriptEngineManager().getEngineByName("python");

        engine.eval("import test.Final.TestClass");
        
        engine.eval("class MyClass(test.Final.TestClass):\n"
                + "   def m1(self):\n"
                + "       self.method1()\n"
                + "   def m2(self):\n"
                + "       self.method2()\n"
                + "   def m3(self):\n"
                + "       self.method3()\n");
        engine.eval("o = MyClass()");        
        
        engine.eval("o.m1()");
        engine.eval("o.m2()");
        engine.eval("o.m3()");
    }
}


Outputs:

On protected
On final public
Exception in thread "main" javax.script.ScriptException: AttributeError: 'MyClass' object has no attribute 'method3' in <script> at line number 1
	at org.python.jsr223.PyScriptEngine.scriptException(PyScriptEngine.java:202)
	at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:42)
	at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:31)
	at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
	at test.Final.main(Final.java:44)
Caused by: Traceback (most recent call last):
  File "<script>", line 1, in <module>
  File "<script>", line 7, in m3
AttributeError: 'MyClass' object has no attribute 'method3'

	at org.python.core.Py.AttributeError(Py.java:205)
	at org.python.core.PyObject.noAttributeError(PyObject.java:1013)
	at org.python.core.PyObject.__getattr__(PyObject.java:1008)
	at org.python.pycode._pyx1.m3$4(<script>:7)
	at org.python.pycode._pyx1.call_function(<script>)
	at org.python.core.PyTableCode.call(PyTableCode.java:167)
	at org.python.core.PyBaseCode.call(PyBaseCode.java:138)
	at org.python.core.PyFunction.__call__(PyFunction.java:413)
	at org.python.core.PyMethod.__call__(PyMethod.java:126)
	at org.python.pycode._pyx5.f$0(<script>:1)
	at org.python.pycode._pyx5.call_function(<script>)
	at org.python.core.PyTableCode.call(PyTableCode.java:167)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.Py.runCode(Py.java:1386)
	at org.python.core.__builtin__.eval(__builtin__.java:497)
	at org.python.core.__builtin__.eval(__builtin__.java:501)
	at org.python.util.PythonInterpreter.eval(PythonInterpreter.java:259)
	at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:40)
	... 3 more
History
Date User Action Args
2017-10-23 09:39:52alexgobbosetrecipients: + alexgobbo
2017-10-23 09:39:52alexgobbosetmessageid: <1508751592.19.0.213398074469.issue2634@psf.upfronthosting.co.za>
2017-10-23 09:39:51alexgobbolinkissue2634 messages
2017-10-23 09:39:50alexgobbocreate