Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-10634

Regular expressions cause groovysh 3.0.10, JDK 17 to crash

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.0.10
    • 3.0.11
    • Groovy Console
    • None
    • Groovy Shell (3.0.10, JVM: 17.0.2)
      Type ':help' or ':h' for help.
      ---------------------------------------------------------------------------
      groovy:000>

    Description

      Running some of these expressions in groovysh will crash the shell.  The expectation is the print the exception to the console, and return to the next prompt without exiting the shell. (see attached for stack trace regular-expression-parsing-exception.txt).

      groovy:000> "billy-bob.7866@aol.info.co".matches(/^([a-zA-Z0-9_-.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/) 

      This however, will NOT crash it (notice the escaping for the hyphen in the first [] expression):

      groovy:000> "billy-bob.7866@aol.info.co".matches(/^([a-zA-Z0-9_\-.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/) 

      This will also crash it (stacktrace regex-matcher-group.txt):

      groovy:000> m = (~/^((\d{4})(\s|-)?){4}$/).matcher( "4199 6238 0343 4807" )
      ===> java.util.regex.Matcher[pattern=^((\d{4})(\s|-)?){4}$ region=0,19 lastmatch=]
      groovy:000> m.group(0) 

      If you don't call `.matches()` before calling `.group()` then it will produce the crash.  However, if you do call `.matches()` the the following will crash it (stacktrace regex-matcher-group-4.txt):

      groovy:000> m = (~/^((\d{4})(\s|-)?){4}$/).matcher( "4199 6238 0343 4807" )
      ===> java.util.regex.Matcher[pattern=^((\d{4})(\s|-)?){4}$ region=0,19 lastmatch=]
      groovy:000> m.matches()
      ===> true
      groovy:000> m.group(0)
      ===> 4199 6238 0343 4807
      groovy:000> m.group(1)
      ===> 4807
      groovy:000> m.group(2)
      ===> 4807
      groovy:000> m.group(3)
      ===> 
      groovy:000> m.group(4)
      ERROR java.lang.IndexOutOfBoundsException: 

      Attachments

        1. regex-matcher-group.txt
          7 kB
          Charlie Hubbard
        2. regex-matcher-group-4.txt
          7 kB
          Charlie Hubbard
        3. regular-expression-parsing-exception.txt
          7 kB
          Charlie Hubbard

        Activity

          People

            paulk Paul King
            chubbard Charlie Hubbard
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: