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

Nashorn bug retrieving array property after key string concatenation

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 8u25
    • Fix Version/s: 9
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b44
    • CPU:
      x86_64
    • OS:
      windows_7

      Backports

        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

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  hannesw Hannes Wallnoefer
                  Reporter:
                  webbuggrp Webbug Group
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  2 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: