JDK-8146152 : Nashorn - JavaLinker property lookup fails when key is a ConsString
  • Type: Bug
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Affected Version: 8u65,9
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2015-12-22
  • Updated: 2015-12-29
  • Resolved: 2015-12-29
Related Reports
Duplicate :  
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_65"
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
Java method / property resolution using a constructed property key fails in Nashorn when the value of the constructed key is represented internally as a ConsString instead of a String.

The jdk.internal.dynalink.beans.AbstractJavaLinker.getPropertyGetterHandle(Object) operation performs a lookup into a String-keyed property getter map using the id parameter. Neither in the getPropertyGetter operation that works with the method handle to getPropertyGetterHandle nor in the operation itself is the parameter checked for potentially being a ConsString or converted into a String for the sake of the lookup.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute the following script via jjs

var nr = Packages.java.lang.Double.valueOf(2.3);
var prop = 'int';
print(nr.intValue); // works
print(nr['intValue']); // works
print(nr['int' + 'Value']); // works
print(nr[prop + 'Value']); // doesn't work

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Each print operation should result in a line output of "[jdk.internal.dynalink.beans.SimpleDynamicMethod int java.lang.Double.intValue()]" for the resolved intValue() method.
ACTUAL -
Only the first three print operations output the correct result. The last outputs "undefined" as the value of the property.

REPRODUCIBILITY :
This bug can be reproduced always.

CUSTOMER SUBMITTED WORKAROUND :
In order to ensure property lookup works correct, a developer that uses constructed keys should currently force ConsString into a String.

Modifying the last line of the "steps to reproduce" script from

print(nr[prop + 'Value']);

into

print(nr[String(prop + 'Value')]);

circumvents the issue


Comments
This is not a Java linker issue. This is an issue with linking JS primitive values (of which Double is one case). There is already a bug filed to track JDK-8146151
29-12-2015

Following is the output on JDK 9ea b93 and JDK 8u66: jjs> var nr = Packages.java.lang.Double.valueOf(2.3); jjs> var prop = 'int'; jjs> print(nr.intValue); [jdk.internal.dynalink.beans.SimpleDynamicMethod int java.lang.Double.intValue()] jjs> print(nr['intValue']); [jdk.internal.dynalink.beans.SimpleDynamicMethod int java.lang.Double.intValue()] jjs> print(nr['int' + 'Value']); [jdk.internal.dynalink.beans.SimpleDynamicMethod int java.lang.Double.intValue()] jjs> print(nr[prop + 'Value']); undefined jjs> print(nr[String(prop + 'Value')]); undefined
24-12-2015