JDK-8073846 : Javascript for-in loop returned extra keys
  • Type: Bug
  • Component: core-libs
  • Sub-Component: javax.script
  • Affected Version: 8
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2015-02-18
  • Updated: 2016-07-08
  • Resolved: 2015-04-20
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 b62Fixed
Description
FULL PRODUCT VERSION :
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
Linux gbl05159 2.6.32-220.23.1.el6.x86_64 #1 SMP Tue Jun 12 11:20:15 EDT 2012 x86_64 x86_64 x86_64 GNU/Linux


A DESCRIPTION OF THE PROBLEM :
Dynamically inserted numberic key and values into an initially empty javascript object. Afterwards, a for-in loop is used to enumerate the object key / values. During iteration, however, extra keys are returned that appear to be generated incorrectly by the engine.

e.g., inserted keys 300,100,500,200. The for-in loop returns 300, 100, 101, 102, ... [snip]... ,199,200, 500 instead of just the 4 keys added.


REGRESSION.  Last worked in version 7u65

ADDITIONAL REGRESSION INFORMATION: 
java version "1.7.0_60"
Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. cd to %JAVA_HOME%/bin
2. jrunscript -f "for-in loop issue.js"


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The last line shows entry count 457
None of the output values should be null
ACTUAL -
The last line showed entry count 9929
Some of the output values are null because the extra keys were not inserted programmatically.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
var orders = {}

var seqs = [
'2126951',
'2126950',
'2128605',
'2128611',
'2128610',
'2122950',
'2122951',
'2129807',
'2129808',
'2128300',
'2128305',
'2128290',
'2128298',
'2128291',
'2128292',
'2127802',
'2127687',
'2127700',
'2127790',
'2128282',
'2128283',
'2016488',
'2107211',
'2126387',
'2126386',
'2126999',
'2126761',
'2124361',
'2127942',
'2126766',
'2128173',
'2128194',
'2128171',
'2128188',
'2128187',
'2128318',
'2128320',
'2128321',
'2128322',
'2128323',
'2127200',
'2127203',
'2127212',
'2127231',
'2127236',
'2128122',
'2128120',
'2128119',
'2127242',
'2126956',
'2126962',
'2126964',
'2127786',
'2127794',
'2127784',
'2126968',
'2120388',
'2120389',
'2120390',
'2126910',
'2124835',
'2126744',
'2124626',
'2126201',
'2129086',
'2129079',
'2129077',
'2129078',
'2129080',
'2126976',
'2128633',
'1881312',
'2126978',
'2126982',
'2126987',
'2126988',
'2126989',
'2126991',
'2126992',
'649387',
'649386',
'649385',
'1757783',
'1757782',
'1757781',
'1757780',
'1757779',
'1693320',
'2127506',
'1757778',
'1757777',
'1757776',
'1757775',
'1757774',
'1757773',
'1757772',
'1757771',
'1757770',
'1757769',
'2100263',
'1757768',
'1757767',
'1757766',
'1757765',
'2105398',
'2126911',
'2122135',
'2124115',
'2126751',
'2126752',
'2124116',
'2126753',
'2126912',
'2126754',
'2077871',
'2122433',
'2039112',
'2027671',
'2127535',
'2025921',
'1825251',
'2127541',
'1790830',
'2037340',
'2128661',
'1381769',
'1373224',
'2118842',
'1727516',
'2020758',
'2126407',
'667195',
'932000',
'740104',
'1202590',
'1408076',
'1408075',
'1656470',
'2127549',
'2127550',
'2127552',
'2127553',
'2127554',
'2127555',
'2127556',
'2127557',
'2127558',
'2127559',
'2127560',
'2127562',
'2127563',
'2127564',
'2127565',
'2127566',
'1702638',
'2127567',
'2127568',
'2127569',
'2127570',
'2127572',
'2127573',
'2127574',
'1672881',
'2127577',
'2127576',
'2127578',
'2127579',
'2127580',
'2127582',
'2127581',
'1920874',
'2127584',
'2127583',
'2127585',
'2127587',
'2127586',
'2127588',
'1900257',
'2127591',
'2127589',
'2127590',
'1680074',
'2127592',
'2127595',
'2039146',
'2127593',
'2127594',
'2127596',
'2127598',
'2127597',
'2127599',
'2127600',
'2127602',
'1955223',
'2127601',
'2127603',
'2127604',
'2127605',
'2127606',
'2127608',
'2127607',
'2048963',
'2127609',
'2127610',
'2127612',
'2054914',
'1900265',
'2127611',
'2020830',
'2025891',
'2043873',
'2127614',
'2127615',
'2127616',
'2047380',
'2043872',
'2098455',
'2127617',
'2127618',
'2127619',
'2127620',
'1997401',
'2043939',
'2098454',
'2127621',
'2047379',
'2098453',
'2047376',
'2127622',
'2127623',
'2048945',
'2100207',
'2102080',
'2127624',
'2118675',
'2127625',
'2084859',
'2084860',
'2127626',
'2127627',
'2095035',
'2095034',
'2118674',
'2105443',
'2116668',
'2118673',
'2127628',
'2105434',
'2105435',
'2107236',
'2118672',
'2127630',
'2116598',
'2103787',
'2103674',
'2083334',
'2111424',
'2112426',
'2103791',
'2116516',
'2120409',
'2112548',
'2114628',
'2114807',
'2110603',
'2110602',
'2114627',
'2109419',
'2109418',
'2114400',
'2114399',
'2125914',
'2120507',
'2126419',
'2124183',
'2124421',
'2126420',
'2122287',
'2122288',
'2124185',
'2127642',
'2127640',
'2127641',
'2126421',
'2124238',
'2124181',
'2126417',
'2127783',
'2126510',
'2126199',
'2127644',
'2121136',
'2126368',
'2126369',
'2126783',
'2126382',
'2126287',
'2126514',
'2127648',
'2127650',
'2116597',
'2126109',
'2126628',
'2127658',
'2126010',
'2126052',
'2127660',
'2127661',
'2127662',
'2119089',
'2127664',
'2125899',
'1910126',
'2107209',
'2107210',
'2126051',
'2124878',
'2126053',
'1789645',
'2127676',
'1561829',
'2123998',
'2126416',
'1819869',
'2127678',
'1790815',
'2124879',
'2127679',
'2127681',
'1750135',
'2122284',
'1807721',
'2127683',
'2127684',
'2127686',
'1850390',
'1970186',
'1767772',
'1535806',
'2127696',
'2127697',
'2126283',
'2127701',
'2127712',
'2127713',
'2127729',
'2129817',
'2127788',
'2127798',
'2127801',
'2126718',
'2126974',
'2128575',
'2128576',
'1328310',
'2129813',
'2129811',
'2129815',
'2127127',
'1867570',
'2127156',
'2127157',
'1867569',
'2127172',
'1957543',
'1957544',
'1957545',
'1957546',
'2127196',
'2127198',
'1542539',
'1674915',
'2126027',
'2126028',
'2127256',
'2127063',
'2122856',
'2122857',
'1787052',
'2127328',
'2127330',
'1935894',
'2127793',
'2118736',
'2128714',
'2128713',
'2127804',
'2126058',
'2129725',
'2129723',
'2129724',
'2126884',
'2127803',
'2118728',
'2107204',
'2127800',
'2110768',
'1900263',
'1481565',
'1361706',
'1668420',
'1894388',
'2126768',
'2122818',
'2129729',
'2129728',
'2129730',
'2102375',
'2037963',
'1414970',
'2127426',
'2127432',
'1926640',
'1961274',
'2112802',
'2100463',
'2114944',
'2114945',
'2124119',
'2105979',
'2122734',
'2122735',
'2114942',
'2114943',
'2114559',
'2115452',
'2126812',
'2124351',
'2126064',
'2100904',
'2126816',
'2127479',
'2126791',
'1181223',
'2126682',
'2126808',
'1926628',
'1926629',
'429972',
'2124343',
'1877405',
'2126804',
'1926630',
'1581491',
'1164064',
'2126799',
'2028000',
'2106244',
'1926634',
'1926633',
'1926636',
'1926635',
'2100826',
'2126806',
'2056761',
'439445',
'1926638'
]

for (var i = 0; i < seqs.length; i++) {
    orders[seqs[i]] = 'order' + seqs[i]
}

var count = 0;
for (var a in orders) {
    count++;
    println(a + " -> " + orders[a]);
}
println('entry count: ' + count);

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


Comments
Reproducible back to JDK 8 MAHAIRA4+idergali@MAHAIRA4 /cygdrive/d/Projects $ time /cygdrive/d/Projects/jdk1.8.0_b132/bin/jrunscript.exe -f "for-in loop issue.js" ... 2129813 -> order2129813 2129815 -> order2129815 2129817 -> order2129817 entry count: 9929 real 0m1.645s user 0m0.000s sys 0m0.000s
03-11-2015

URL: http://hg.openjdk.java.net/jdk9/jdk9/nashorn/rev/7eab2df7213d User: lana Date: 2015-04-29 18:01:55 +0000
29-04-2015

URL: http://hg.openjdk.java.net/jdk9/dev/nashorn/rev/7eab2df7213d User: hannesw Date: 2015-04-20 08:50:45 +0000
20-04-2015

Rechecked for Linux and Windows (correction: jrunscript is part of JDK 8 and 9 binaries) and here is the finding: 7u76 - OK 8 - Fail 8u31 - Fail 8u40 ea b23 - OK 9 ea b50 - OK Confirms that the issue is reproducible with JDK 8u31 and seems resolved in JDK 8u40 ea and JDK 9 ea. -------------------------------------------------------------------------------- With JDK 8, 8u25, 8u31: ------ ..... ---> null 2129807 -> order2129807 2129808 -> order2129808 2129811 -> order2129811 2129813 -> order2129813 2129815 -> order2129815 2129817 -> order2129817 entry count: 9929 With JDK 8u40 ea b23, JDK 9 ea b50:. .............................................................................. 2129730 -> order2129730 2129807 -> order2129807 2129808 -> order2129808 2129811 -> order2129811 2129813 -> order2129813 2129815 -> order2129815 2129817 -> order2129817 entry count: 457 --------------------------------------------- Received response from the submitter: --------------------------------------------------------------------------------------------------------------------------------- > On 2/25/2015 12:55 PM, .................. wrote: >>>> As described in the bug report, this issue only happened with jdk 8 release. The jrunscript in jdk 7 and jdk 6 was not effected. Are you certain jrunscript is not part of Java 8 SE? We found the jrunscript executable in the bin folder of both jdk 8 windows and linux x64 installation folder. >> >> http://docs.oracle.com/javase/8/docs/technotes/tools/unix/jrunscript.html ----------------------------------------------------------------------------------------------------------------------------------
25-02-2015

There is no clear information about the version against whom this issue is reported. Checked with the mentioned versions, JDK 7u60, 7u65, 7u67 and 7u57 and could never reproduce this issue. Written back to the submitter for clarification. -------------------------------------------------------------------------------------------------------------------------------------------------------------- On 2/25/2015 12:33 PM, Pardeep Kumar Sharma wrote: > Hi Keith, > > The information you have submitted in the report is insufficient for us to evaluate this issue. Can you please confirm the version that you are trying to report this against. In any case, I'm not able to reproduce this issue with JDK 7u57, 7u60, 7u65, and 7u67. Please note that jrunscript utility is limited to JDK 7, whereas you have mentioned 8u31 as affected version. ---------------------------------------------------------------------------------------------------------------------------------------------------------------
25-02-2015