JDK-8223386 : JSObject.getMember is not called if name contains parentheses
  • Type: Bug
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Affected Version: 8u60,11,13
  • Priority: P3
  • Status: Resolved
  • Resolution: Won't Fix
  • OS: generic
  • CPU: x86_64
  • Submitted: 2019-05-02
  • Updated: 2019-05-07
  • Resolved: 2019-05-07
Related Reports
Relates :  
Description
A DESCRIPTION OF THE PROBLEM :
When a property lookup is performed on an object backed by a JSObject (or AbstractJSObject) implementation, and the property name contains at least a left parenthesis, the corresponding getMember method is not called by the engine.

In JSObjectLinker, the presence of a left parenthesis seems to be treated as an indication that an exact method with a certain signature should be called on the JSObject instead. However, the main point for implementing a custom JSObject (instead of just exposing a plain Java object) is to control exactly how the object behaves in script code.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
* Extend from AbstractJSObject and override the getMember method.
* Put an instance of that implementation into a Bindings.
* Evaluate a script that tries to access a property name with parentheses.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The custom getMember method is called.
ACTUAL -
The custom getMember method is not called. Instead, the property access expression simply returns null in the script.

---------- BEGIN SOURCE ----------
import javax.script.ScriptEngine;

import jdk.nashorn.api.scripting.AbstractJSObject;
import jdk.nashorn.api.scripting.NashornScriptEngineFactory;

public class ParenthesisInPropertyName {

    public static class TestJsObject extends AbstractJSObject {

        @Override
        public Object getMember(String name) {
            System.out.println("Member called: " + name);
            return null;
        }
    }

    public static void main(String[] args) throws Exception {
        ScriptEngine engine = new NashornScriptEngineFactory().getScriptEngine();
        engine.put("test", new TestJsObject());
        engine.eval("test['foo bar']"); // Member called: foo bar
        engine.eval("test['foo(bar)']"); // Nothing happens
    }
}
---------- END SOURCE ----------

FREQUENCY : always



Comments
Resolving as "won't fix" as fixing this would require removing of method lookup via signature.
07-05-2019

This is a consequence of JDK-8055796 which introduced lookup of public JSObject methods via method signature.
07-05-2019

This issue is a regression, i could see expectd result in 8u31 and start failing from 8u60. Could not verify versions in between. 8u33 - Pass 8u60 - Fail 8u212 - Fail 11.0.3 - Fail 13 ea b17 - Fail
06-05-2019