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

Nashorn bug retrieving array property after key string concatenation

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 9
    • 8u25
    • core-libs
    • b44
    • x86_64
    • 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

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

                Dates

                  Created:
                  Updated:
                  Resolved: