graaljs icon indicating copy to clipboard operation
graaljs copied to clipboard

Access to static Java members via subclass [interop]

Open tporeba opened this issue 4 years ago • 1 comments

I can't access public static fields, while I can access public static methods:

console.log(Java.type('java.util.Calendar').getInstance());          // OK, prints the instance
console.log(Java.type('java.util.GregorianCalendar').getInstance()); // OK, prints the instance
console.log(Java.type('java.util.Calendar').DAY_OF_MONTH);           // OK, prints "5"
console.log(Java.type('java.util.GregorianCalendar').DAY_OF_MONTH);  // undefined

Is this deliberate?

For comparison with graal.js ancestors:

  • Rhino allowed both access to fields and methods via subclasses.
  • Nashorn allowed none - only directly declaring class could be used, see https://stackoverflow.com/questions/38226309/inherited-static-methods-not-available-in-java-nashorn

tporeba avatar Apr 24 '20 15:04 tporeba

Thanks for the report! I think this inconsistency is not deliberate and we should change it (I'd prefer to disallow access via subclass). Either way, I'd highly recommend to always refer to static members via the declaring class.

Internally tracked as GR-22868.

woess avatar Apr 27 '20 14:04 woess