Closed Bug 175383 Opened 22 years ago Closed 22 years ago

ArrayIndexOutOfBoundsException in string.replace()

Categories

(Rhino Graveyard :: Core, defect)

x86
Windows 2000
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED WORKSFORME

People

(Reporter: kalakhr, Assigned: norrisboyd)

Details

I got an ArrayIndexOutOfBoundsException while using the replace method of the string object. Please see the screen dump below: C:\rhino1_5R3>java org.mozilla.javascript.tools.shell.Main js> re = new RegExp('b(d+)b', 'g') /b(d+)b/g js> str = 'xxbdbxxbddbxxbdddbxx' xxbdbxxbddbxxbdddbxx js> str.replace(re, 'vvv') xxvvvxxvvvxxvvvxx js> str.replace(re, '$$$') Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException at org.mozilla.javascript.regexp.ReplaceData.interpretDollar (RegExpImpl.java:400) at org.mozilla.javascript.regexp.ReplaceData.findReplen (RegExpImpl.java:502) at org.mozilla.javascript.regexp.ReplaceData.doGlobal (RegExpImpl.java:362) at org.mozilla.javascript.regexp.RegExpImpl.matchOrReplace (RegExpImpl.java:187) at org.mozilla.javascript.regexp.RegExpImpl.replace(RegExpImpl.java:106) at org.mozilla.javascript.NativeString.execMethod(NativeString.java:266) at org.mozilla.javascript.IdFunction.call(IdFunction.java:78) at org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1222) at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:1950) at org.mozilla.javascript.InterpretedScript.call (InterpretedScript.java:68) at org.mozilla.javascript.InterpretedScript.exec (InterpretedScript.java:59) at org.mozilla.javascript.Context.evaluateReader(Context.java:773) at org.mozilla.javascript.tools.shell.Main.evaluateReader(Main.java:293) at org.mozilla.javascript.tools.shell.Main.processSource(Main.java:217) at org.mozilla.javascript.tools.shell.Main.exec(Main.java:104) at org.mozilla.javascript.tools.shell.Main.main(Main.java:66)
This was fixed by the big RegExp patch to bug 125562, and the example code no longer crashes in Rhino: [ ] java org.mozilla.javascript.tools.shell.Main Rhino 1.5 release 4 0000 00 00 (in progress) js> re = new RegExp('b(d+)b', 'g') /b(d+)b/g js> str = 'xxbdbxxbddbxxbdddbxx' xxbdbxxbddbxxbdddbxx js> str.replace(re, 'vvv') xxvvvxxvvvxxvvvxx js> str.replace(re, '$$$') xx$$xx$$xx$$xx The fix for bug 125562 was checked in on 2002-06-20, after Rhino 1.5 RC3 was released on 2002-01-27. The fix should be contained in rhinoLatest.zip, however, available at ftp://ftp.mozilla.org/pub/js/ and dated 2002-07-07. Let me resolve this bug as WORKSFORME. Khaled: could you try rhinoLatest.zip and see if the bug is fixed for you, too? If so, please mark this bug "Verified". Otherwise, you can reopen it; thanks -
Status: NEW → RESOLVED
Closed: 22 years ago
Resolution: --- → WORKSFORME
Targeting as resolved against 1.5R4
Target Milestone: --- → 1.5R4
You need to log in before you can comment on or make changes to this bug.