Title: Cannot access final protected methods
Type: behaviour Severity: normal
Components: Core Versions: Jython 2.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: alexgobbo, jon4than
Priority: Keywords:

Created on 2017-10-23.09:39:52 by alexgobbo, last changed 2017-11-20.07:39:53 by alexgobbo.

msg11630 (view) Author: A. Gobbo (alexgobbo) Date: 2017-10-23.09:39:50
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()");        


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(
	at org.python.jsr223.PyScriptEngine.eval(
	at org.python.jsr223.PyScriptEngine.eval(
	at javax.script.AbstractScriptEngine.eval(
	at test.Final.main(
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(
	at org.python.core.PyObject.noAttributeError(
	at org.python.core.PyObject.__getattr__(
	at org.python.pycode._pyx1.m3$4(<script>:7)
	at org.python.pycode._pyx1.call_function(<script>)
	at org.python.core.PyFunction.__call__(
	at org.python.core.PyMethod.__call__(
	at org.python.pycode._pyx5.f$0(<script>:1)
	at org.python.pycode._pyx5.call_function(<script>)
	at org.python.core.Py.runCode(
	at org.python.core.__builtin__.eval(
	at org.python.core.__builtin__.eval(
	at org.python.util.PythonInterpreter.eval(
	at org.python.jsr223.PyScriptEngine.eval(
	... 3 more
msg11658 (view) Author: Jonathan Beavers (jon4than) Date: 2017-11-17.20:46:02
Apologies if this isn't the correct place to put this sort of reply, but did you try setting to false?

Running the following reproduced your problem:
  java -cp .:jython-standalone-2.7.0.jar test.Final

I was able to fix it by running:
  java -cp .:jython-standalone-2.7.0.jar test.Final
msg11664 (view) Author: A. Gobbo (alexgobbo) Date: 2017-11-20.07:39:53
I believe it is not a solution. Setting respectJavaAccessibility to false makes all members accessible, including the private ones, and that's not what I'd expect if extending a Java class.
Date User Action Args
2017-11-20 07:39:54alexgobbosetmessages: + msg11664
2017-11-17 20:46:03jon4thansetnosy: + jon4than
messages: + msg11658
2017-10-23 09:39:52alexgobbocreate