Bug 22997 - RE throws ArrayIndexOutOfBounds when grouping repetition is >= 16
Summary: RE throws ArrayIndexOutOfBounds when grouping repetition is >= 16
Status: CLOSED WORKSFORME
Alias: None
Product: Regexp
Classification: Unclassified
Component: Other (show other bugs)
Version: unspecified
Hardware: All All
: P3 normal (vote)
Target Milestone: ---
Assignee: Jakarta Notifications Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-09-08 17:02 UTC by lichade xun
Modified: 2004-11-16 19:05 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description lichade xun 2003-09-08 17:02:48 UTC
For the following code snippet:

String s = "1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 ";
org.apache.regexp.RE re = new org.apache.regexp.RE("([0-9]+ ){17}");
System.out.println(re.match(s));

Basically i have a string s that consists of a number followed by a whitespace,
repeated 17 times. To verify this pattern, my RE uses "[0-9]+" to denote the 
number, followed by a whitespace " ", and the 2 are grouped by "()", then 
followed by the repetition operator {n} (shown above n=17).

The match result should be "true" for n=1 to 17. it does return "true" if you 
start n from 1 and increase all the way to 15. But as soon as n >= 16, an 
ArrayIndexOutOfBounds will be thrown with the number "n", which seems to 
indicate some hard-coding of capacity somewhere in the code.

I tried this on both REGEXP 1.2 and 1.3. same results.
Comment 1 Vadim Gritsenko 2003-09-09 01:33:48 UTC
Sorry, can't reproduce. I patched RETest:

Index: src/java/org/apache/regexp/RETest.java
===================================================================
RCS file: /home/cvs/jakarta-regexp/src/java/org/apache/regexp/RETest.java,v
retrieving revision 1.7
diff -u -r1.7 RETest.java
--- src/java/org/apache/regexp/RETest.java      7 Sep 2003 15:04:14 -0000       1.7
+++ src/java/org/apache/regexp/RETest.java      9 Sep 2003 01:27:56 -0000
@@ -619,5 +619,8 @@
             fail("Wrong subst() result: " + s);
         }

+        r = new RE("([0-9]+ ){17}");
+        System.out.println(r.match("1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 "));
+        System.exit(0);
     }
 }


Then, I ran "ant test". Have not seen any exception and got "true" on the
console. I tested against CVS version.

Please provide more details on how to reproduce this issue.

Vadim
Comment 2 lichade xun 2003-09-09 18:53:18 UTC
OK. I was running the snippet from Eclipse's JPage and got the error. I tried 
the same code in a standalone class file and ran from java commandline (outside 
Eclipse), and did not get the error. so i guess the apache regexp library is 
OK. but still i cannot explain the error from JPage, which looked like it's 
from RE. here's the stack trace when n=17, strictly FYI - i don't expect 
developers from this group to debug, if it's an eclipse problem.

java.lang.ArrayIndexOutOfBoundsException: 17
	at org.apache.regexp.RE.getParenEnd(RE.java:724)
	at org.apache.regexp.RE.matchNodes(RE.java:942)
	at org.apache.regexp.RE.matchNodes(RE.java:1376)
	at org.apache.regexp.RE.matchNodes(RE.java:910)
	at org.apache.regexp.RE.matchNodes(RE.java:933)
	at org.apache.regexp.RE.matchNodes(RE.java:1376)
	at org.apache.regexp.RE.matchNodes(RE.java:910)
	at org.apache.regexp.RE.matchNodes(RE.java:933)
	at org.apache.regexp.RE.matchNodes(RE.java:1376)
	at org.apache.regexp.RE.matchNodes(RE.java:910)
	at org.apache.regexp.RE.matchNodes(RE.java:933)
	at org.apache.regexp.RE.matchNodes(RE.java:1376)
	at org.apache.regexp.RE.matchNodes(RE.java:910)
	at org.apache.regexp.RE.matchNodes(RE.java:933)
	at org.apache.regexp.RE.matchNodes(RE.java:1376)
	at org.apache.regexp.RE.matchNodes(RE.java:910)
	at org.apache.regexp.RE.matchNodes(RE.java:933)
	at org.apache.regexp.RE.matchNodes(RE.java:1376)
	at org.apache.regexp.RE.matchNodes(RE.java:910)
	at org.apache.regexp.RE.matchNodes(RE.java:933)
	at org.apache.regexp.RE.matchNodes(RE.java:1376)
	at org.apache.regexp.RE.matchNodes(RE.java:910)
	at org.apache.regexp.RE.matchNodes(RE.java:933)
	at org.apache.regexp.RE.matchNodes(RE.java:1376)
	at org.apache.regexp.RE.matchNodes(RE.java:910)
	at org.apache.regexp.RE.matchNodes(RE.java:933)
	at org.apache.regexp.RE.matchNodes(RE.java:1376)
	at org.apache.regexp.RE.matchNodes(RE.java:910)
	at org.apache.regexp.RE.matchNodes(RE.java:933)
	at org.apache.regexp.RE.matchNodes(RE.java:1376)
	at org.apache.regexp.RE.matchNodes(RE.java:910)
	at org.apache.regexp.RE.matchNodes(RE.java:933)
	at org.apache.regexp.RE.matchNodes(RE.java:1376)
	at org.apache.regexp.RE.matchNodes(RE.java:910)
	at org.apache.regexp.RE.matchNodes(RE.java:933)
	at org.apache.regexp.RE.matchNodes(RE.java:1376)
	at org.apache.regexp.RE.matchNodes(RE.java:910)
	at org.apache.regexp.RE.matchNodes(RE.java:933)
	at org.apache.regexp.RE.matchNodes(RE.java:1376)
	at org.apache.regexp.RE.matchNodes(RE.java:910)
	at org.apache.regexp.RE.matchNodes(RE.java:933)
	at org.apache.regexp.RE.matchNodes(RE.java:1376)
	at org.apache.regexp.RE.matchNodes(RE.java:910)
	at org.apache.regexp.RE.matchNodes(RE.java:933)
	at org.apache.regexp.RE.matchNodes(RE.java:1376)
	at org.apache.regexp.RE.matchNodes(RE.java:910)
	at org.apache.regexp.RE.matchNodes(RE.java:933)
	at org.apache.regexp.RE.matchNodes(RE.java:1376)
	at org.apache.regexp.RE.matchNodes(RE.java:910)
	at org.apache.regexp.RE.matchNodes(RE.java:933)
	at org.apache.regexp.RE.matchNodes(RE.java:1376)
	at org.apache.regexp.RE.matchNodes(RE.java:910)
	at org.apache.regexp.RE.matchAt(RE.java:1448)
	at org.apache.regexp.RE.match(RE.java:1498)
	at org.apache.regexp.RE.match(RE.java:1468)
	at org.apache.regexp.RE.match(RE.java:1561)
	at CodeSnippet_2.run(CodeSnippet_2.java:5)
	at org.eclipse.jdt.internal.debug.ui.snippeteditor.ScrapbookMain1.eval
(ScrapbookMain1.java:14)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:324)
	at 
org.eclipse.jdt.internal.debug.ui.snippeteditor.ScrapbookMain.evalLoop
(ScrapbookMain.java:48)
	at org.eclipse.jdt.internal.debug.ui.snippeteditor.ScrapbookMain.main
(ScrapbookMain.java:29)
Comment 3 Vadim Gritsenko 2003-09-09 20:00:06 UTC
You've got somewhere a 1.2 version of the regexp library, and 1.2 version has
the error you mentioned, it was limited to 16 parens. This error was since then
fixed, and fix was released as part of version 1.3.

You can see the source code for version 1.2 here:
http://cvs.apache.org/viewcvs.cgi/jakarta-regexp/src/java/org/apache/regexp/RE.java?annotate=1.6

(closing the bug)