Message11868

Author jeff.allen
Recipients jeff.allen, zyasoft
Date 2018-04-02.18:57:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1522695471.18.0.467229070634.issue2662@psf.upfronthosting.co.za>
In-reply-to
Content
I tried an isolated experiment with reflection on the same method. It appears that if the method we were trying to call was:
  public abstract java.nio.charset.CharsetEncoder java.nio.charset.Charset.newEncoder()
and not:
  public java.nio.charset.CharsetEncoder sun.nio.cs.GBK.newEncoder()
then we'd be ok. This even though the second is the implementation of the first. Demonstration attached.

In compiled Java, the object that is the target of the call is declared as a Charset, and so the compiler emits an invokevirtual of Charset.newEncoder whereas in the reflective call we find the method in the actual class of the object.

In asking how to deal with this in Jython, where there are only actual types, not declared types, I believe we are really considering the semantics of attribute access. In this case, we would like to call the abstract method. This suggests that when constructing the PyJavaType, we should insert a Method object found by chasing the Java or Python MRO, not the one we find in the class itself. But is this always right?

As a counter-example, I think it would be possible to arrange that the base class be inaccessible while a derived class is not. And checking accessibility from PyJavaType does not necessarily reflect accessibility to the user application.
History
Date User Action Args
2018-04-02 18:57:51jeff.allensetmessageid: <1522695471.18.0.467229070634.issue2662@psf.upfronthosting.co.za>
2018-04-02 18:57:51jeff.allensetrecipients: + jeff.allen, zyasoft
2018-04-02 18:57:50jeff.allenlinkissue2662 messages
2018-04-02 18:57:50jeff.allencreate