Two things:

* Nashorn allows access only to public methods and fields (of exported) classes only.

* With Java.extend, Nashorn adds public overrides of all non-final protected methods of the superclass. ClassLoader.definePackage is non-final protected method. ClassLoader.defineClass is final protected method.
Hence no override of ClassLoader.defineClass added to generated subclass.


On 23/02/18, 7:09 AM, Nathan Faulkner wrote:
When extending java.lang.ClassLoader, I can't seem to execute defineClass.
Here's my test case showing the issue.

var superLoader =  Java.super(new (Java.extend(java.lang.ClassLoader))(){});
// defineClass on the super object doesn't exist for some reason
print("defineClass: " + (superLoader.defineClass !== undefined));
// definePackage is protected, but isn't undefined, so that isn't the issue
print("definePackage: " + (superLoader.definePackage !== undefined));

and here's the output of "java -version":
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

Reply via email to