Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8146152

Nashorn - JavaLinker property lookup fails when key is a ConsString

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • None
    • 8u65, 9
    • core-libs

      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

            sundar Sundararajan Athijegannathan
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: