Bug 9035 - big Latitude Longitude RE causes IndexOutOfBoundsException
Summary: big Latitude Longitude RE causes IndexOutOfBoundsException
Status: CLOSED INVALID
Alias: None
Product: Regexp
Classification: Unclassified
Component: Other (show other bugs)
Version: unspecified
Hardware: All Linux
: P3 major with 1 vote (vote)
Target Milestone: ---
Assignee: Jakarta Notifications Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-05-13 14:16 UTC by Michael Newcomb
Modified: 2004-11-16 19:05 UTC (History)
0 users



Attachments
test case, sorry, didn't see 'attach file' option (2.17 KB, text/plain)
2002-05-13 14:20 UTC, Michael Newcomb
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Newcomb 2002-05-13 14:16:20 UTC
I have two faily big REs dealing with Latitude and Longitude.  When I use them 
separately, no problems.  However, when I combine the 2 REs, so I can pass one 
Latitude-Longitude string to it, it bombs out with an exception (detailed 
below).

Here is the test program.  Refer to the example run for usage:

import java.io.*;
import java.util.*;
import org.apache.regexp.*;

public class LatLonREBug
{
  private static final String LATITUDE_RE_STRING =
    
"-?(([0-8]?[0-9]((\\.[0-9]+)|((([0-5][0-9])|60)((([0-5][0-9])|60))?))?)|90)[nNsS]";
  private static final String LONGITUDE_RE_STRING =
    
"-?(((([0-9]?[0-9])|(1[0-7][0-9]))((\\.[0-9]+)|((([0-5][0-9])|60)(([0-5][0-9])|60)?))?)|180)[eEwW]";

  public static final String LATITUDE_LONGITUDE_RE_STRING =
    "^" + LATITUDE_RE_STRING + LONGITUDE_RE_STRING + "$";

  public static void main(String[] args)
    throws Throwable
  {
    RE latlonRE = new RE(LATITUDE_LONGITUDE_RE_STRING);
    System.out.println("LATITUDE_LONGITUDE_RE_STRING: " +
                       LATITUDE_LONGITUDE_RE_STRING);

    RE latRE = new RE("^" + LATITUDE_RE_STRING + "$");
    System.out.println("LATITUDE_RE_STRING: " + LATITUDE_RE_STRING);

    RE lonRE = new RE("^" + LONGITUDE_RE_STRING + "$");
    System.out.println("LONGITUDE_RE_STRING: " + LONGITUDE_RE_STRING);

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String line = br.readLine();
    while (line != null && !line.equals("quit") && !line.equals("exit"))
    {
      StringTokenizer st = new StringTokenizer(line);
      int tokens = st.countTokens();

      if (tokens > 1)
      {
        String command = st.nextToken();

        if (command.equalsIgnoreCase("lat"))
        {
          String lat = st.nextToken();
          latRE.match(lat);
          System.out.println(lat + " is a properly formatted latitude");
        }
        else if (command.equalsIgnoreCase("lon"))
        {
          String lon = st.nextToken();
          lonRE.match(lon);
          System.out.println(lon + " is a properly formatted longitude");
        }
        else if (command.equalsIgnoreCase("latlon"))
        {
          String latlon = st.nextToken();
          latlonRE.match(latlon);
          System.out.println(latlon + " is a properly formatted lat-lon");
        }
        else
        {
          System.out.println("unknown command: " + command);
        }
      }
      else
      {
        System.out.println("invalid line: " + line);
      }

      line = br.readLine();
    }
  }
}

Here is an example run of the test-case.  As you will see, when just doing 
latitude or longitude, the REs match as expected.  But, when I do a 'latlon' 
string, it pukes...

[mnewcomb@localhost sandbox]$ java -classpath 
/usr/local/regexp/jakarta-regexp-1.2.jar:. LatLonREBug
LATITUDE_LONGITUDE_RE_STRING: 
^-?(([0-8]?[0-9]((\.[0-9]+)|((([0-5][0-9])|60)((([0-5][0-9])|60))?))?)|90)[nNsS]-?(((([0-9]?[0-9])|(1[0-7][0-9]))((\.[0-9]+)|((([0-5][0-9])|60)(([0-5][0-9])|60)?))?)|180)[eEwW]$
LATITUDE_RE_STRING: 
-?(([0-8]?[0-9]((\.[0-9]+)|((([0-5][0-9])|60)((([0-5][0-9])|60))?))?)|90)[nNsS]
LONGITUDE_RE_STRING: 
-?(((([0-9]?[0-9])|(1[0-7][0-9]))((\.[0-9]+)|((([0-5][0-9])|60)(([0-5][0-9])|60)?))?)|180)[eEwW]
lat 55N
55N is a properly formatted latitude
lat 55.454N
55.454N is a properly formatted latitude
lat 5545N
5545N is a properly formatted latitude
lon 123E
123E is a properly formatted longitude
lon 5E
5E is a properly formatted longitude
lon 123.444E
123.444E is a properly formatted longitude
lon 1784532W
1784532W is a properly formatted longitude
latlon 55N44E
55N44E is a properly formatted lat-lon
latlon 55N44.33E
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
	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:933)
	at org.apache.regexp.RE.matchNodes(RE.java:1376)
	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:1376)
	at org.apache.regexp.RE.matchNodes(RE.java:910)
	at org.apache.regexp.RE.matchNodes(RE.java:1376)
	at org.apache.regexp.RE.matchNodes(RE.java:933)
	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:1376)
	at org.apache.regexp.RE.matchNodes(RE.java:910)
	at org.apache.regexp.RE.matchNodes(RE.java:910)
	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:1376)
	at org.apache.regexp.RE.matchNodes(RE.java:933)
	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:1376)
	at org.apache.regexp.RE.matchNodes(RE.java:910)
	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:1376)
	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 LatLonREBug.main(LatLonREBug.java:54)
[mnewcomb@localhost sandbox]$ 


Any help will be greatly appreciated.

Thanks,
Michael
Comment 1 Michael Newcomb 2002-05-13 14:20:48 UTC
Created attachment 1846 [details]
test case, sorry, didn't see 'attach file' option
Comment 2 Michael Newcomb 2002-05-13 16:43:54 UTC
This is a problem caused by too many parentheses.  Please apply the patch 
supplied in bug # 8467 by Vadim Gritsenko (thanks Vadim!).

There is no reason for this to not be applied as is.  I did it on a fresh 
check-out from cvs and my code is working perfectly.

Is there anyone with write-access for REGEX available to apply Vadim's patch?

Michael
Comment 3 Vadim Gritsenko 2002-05-22 17:50:02 UTC
So my patch is useful not only for me :)