[ https://issues.apache.org/jira/browse/GROOVY-10634?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17540348#comment-17540348 ]
Paul King commented on GROOVY-10634: ------------------------------------ Workarounds are to use an earlier JDK (8-16) or Groovy 4+. > Regular expressions cause groovysh 3.0.10, JDK 17 to crash > ---------------------------------------------------------- > > Key: GROOVY-10634 > URL: https://issues.apache.org/jira/browse/GROOVY-10634 > Project: Groovy > Issue Type: Bug > Components: Groovy Console > Affects Versions: 3.0.10 > Environment: Groovy Shell (3.0.10, JVM: 17.0.2) > Type ':help' or ':h' for help. > --------------------------------------------------------------------------- > groovy:000> > Reporter: Charlie Hubbard > Priority: Major > Attachments: regex-matcher-group-4.txt, regex-matcher-group.txt, > regular-expression-parsing-exception.txt > > > 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). > {code:java} > groovy:000> > "billy-bob.7...@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})(\]?)$/) > {code} > This however, will NOT crash it (notice the escaping for the hyphen in the > first [] expression): > {code:java} > groovy:000> > "billy-bob.7...@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})(\]?)$/) > {code} > This will also crash it (stacktrace regex-matcher-group.txt): > {code:java} > 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) {code} > 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): > {code:java} > 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: {code} -- This message was sent by Atlassian Jira (v8.20.7#820007)