Closed Bug 77856 Opened 24 years ago Closed 24 years ago

Enumerating Java arrays via (for..in) loops is failing

Categories

(Core Graveyard :: Java: Live Connect, defect)

x86
Windows NT
defect
Not set
normal

Tracking

(Not tracked)

VERIFIED FIXED
mozilla0.9.1

People

(Reporter: pschwartau, Assigned: beard)

Details

Attachments

(2 files)

These testcases are failing in the debug and optimized LiveConnect shells: lc2/Arrays/array-003.js lc2/Arrays/array-005.js lc3/forin/array-001.js This looks similar to bug 55114, "for... in loops not behaving as expected on Java strings" However, in that bug the test failures were confined to two of the above tests, and looked like this: Testcase lc2/Arrays/array-003.js failed Failure messages were: number of elements enumerated: = 0 FAILED! expected: 5 number of elements enumerated: = 0 FAILED! expected: 5 Testcase lc3/forin/array-001.js failed [ Previous Failure | Next Failure | Top of Page ] Failure messages were: new java.lang.String("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789").getBytes(); length = 1 FAILED! expected: 36 [1] = undefined FAILED! expected: 66 [2] = undefined FAILED! expected: 67 [3] = undefined FAILED! expected: 68 [4] = undefined FAILED! expected: 69 [5] = undefined FAILED! expected: 70 [6] = undefined FAILED! expected: 71 [7] = undefined FAILED! expected: 72 [8] = undefined FAILED! expected: 73 [9] = undefined FAILED! expected: 74 etc. etc. In the present case, the test failures look like this: Testcase lc2/Arrays/array-003.js failed Expected exit code 0, got 3 Testcase terminated with signal 0 Complete testcase output was: ./lc2/Arrays/array-003.js:94: InternalError: Java class [B has no public field or method named "PropertyIterator" Testcase lc2/Arrays/array-005.js failed Expected exit code 0, got 3 Testcase terminated with signal 0 Complete testcase output was: ./lc2/Arrays/array-005.js:75: InternalError: Java class [B has no public field or method named "PropertyIterator" Testcase lc3/forin/array-001.js failed Expected exit code 0, got 3 Testcase terminated with signal 0 Complete testcase output was: ./lc3/forin/array-001.js:107: InternalError: Java class [B has no public field or method named "PropertyIterator" These three testcases all use for..in loops to iterate Java arrays.
The line numbers in the error messages are found at: http://lxr.mozilla.org/mozilla/source/js/tests/lc2/Arrays/array-003.js#94 http://lxr.mozilla.org/mozilla/source/js/tests/lc2/Arrays/array-005.js#75 http://lxr.mozilla.org/mozilla/source/js/tests/lc3/forin/array-001.js#107 I only see a reference to the a class named "[B" in lc2/Arrays/array-003.js. So I'm confused why it's mentioned in the error messages for all three tests.
Patrick or Roger, are you able to duplicate this bug? Here's the way I'm running the tests on my WinNT box: ("shell.js" is a utility file) [/d/JS_TRUNK/mozilla/js/src/liveconnect/WINNT4.0_OPT.OBJ] ./lcshell.exe js> load('../../../tests/lc2/shell.js') js> load('../../../tests/lc2/Arrays/array-003.js') js> load('../../../tests/lc2/Arrays/array-005.js') js> load('../../../tests/lc3/forin/array-001.js')
Reduced testcase: js> var byte_array = (new java.lang.String("hi")).getBytes() js> getClass(byte_array) [JavaClass [B] js> typeof(byte_array) object js> byte_array.toString() [B@246bc4 js> byte_array[0] 104 js> byte_array.length 2 js> for (var p in byte_array) {print(p)} 12: InternalError: Java class [B has no public field or method named "PropertyIterator"
Evidently, something in the way enumeration is handled as changed, and when LiveConnect is asked to look up the "PropertyIterator" property on a Java array, its failure mode is too strict. I tried having it return undefined rather than signalling an exception, and all is well. I'm guessing that enumerating properties in regular Java objects may also exhibit this problem.
Assignee: rogerl → beard
Ah, the reason this works for non-array Java objects in general is that JavaObject_lookupProperty() assigns NULL to its *objp and *propp parameters, and always returns JS_TRUE. A simpler change might be to do the same thing in JavaArray_lookupProperty. Opinions?
Both patches work, but the second one is a more general solution.
Status: NEW → ASSIGNED
Target Milestone: --- → mozilla0.9.1
Whiteboard: looking for r/sr
One additional observation, JS_ReportErrorNumber() gets called from various places in both JSJ_JavaObject.c and JSJ_JavaArray.c, which seems unnecessary in the case of many property lookups, given the behavior of JavaObject_lookupProperty() and JavaArray_lookupProperty(), which just map these to undefined. Perhaps an error should only be signalled when setting a property, not when reading a property.
r/sr=brendan@mozilla.org on the second patch, it's necessary. It's wrong to return JS_TRUE but fail to set *objp and *propp, end of story. Any other bad JSObjectOps impls in liveconnect? /be
shaver, care to provide an additional review?
Need one more review to get this in for 0.9.1 ...
Keywords: mozilla0.9.1, review
Fix checked in.
Status: ASSIGNED → RESOLVED
Closed: 24 years ago
Resolution: --- → FIXED
Whiteboard: looking for r/sr
VERIFIED FIXED on WinNT - the three testcases above no longer fail -
Status: RESOLVED → VERIFIED
Product: Core → Core Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: