JDK-8062030 : Nashorn bug retrieving array property after key string concatenation
  • Type: Bug
  • Component: core-libs
  • Sub-Component: javax.script
  • Affected Version: 8u25
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2014-10-23
  • Updated: 2015-09-29
  • Resolved: 2014-12-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u60Fixed 9 b44Fixed
Description
FULL PRODUCT VERSION :
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b18)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Windows 7 x64

A DESCRIPTION OF THE PROBLEM :
Nashorn returns 'null' when externally binded array is called with key concatenated from several strings






ADDITIONAL REGRESSION INFORMATION: 
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b18)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
run the script above

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
array value returned
ACTUAL -
null returned whithout actually calling getMember

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
Java: VarsAdapter is a simple AbstractJSObject binded to the javascript context as "vars"

public class VarsAdapter extends AbstractJSObject
{
    @Override
    public Object getMember(String name)
    {
        return name;
    }
}

javascript:
var o = 6;
print( '1: price_'+o);
print( '2: '+vars['price_'+o]);
print( '3: '+vars['price_6']);                
print( '4: '+vars[('price_'+o).toString()]);                

output:

1: price_6
2: null
3: price_6
4: price_6

line 2 is incorrect. Debugger shows that getMember is never invoked when concatenated string is used as key.

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
use .toString() after string concatenation