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

java.util.regex.Matcher: group access by [] operator broken in jsr-03

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Won't Fix
    • 1.0-JSR-3
    • 1.0-JSR-4
    • None
    • None
    • Debian 3.1

    Description

      This code works with jsr-02 but not anymore with jsr-03:

      def m = ("Hallo_1_3" =~ "^(.*)(\\d+)(
      d+)")
      if (m) {
      println "m.pattern().pattern() = ${m.pattern().pattern()}"
      println "m.matches() = ${m.matches()}"
      println "m.groupCount() = ${m.groupCount()}"
      println "m.group(1) = ${m.group(1)}"
      println "m.group(2) = ${m.group(2)}"
      println "m.group(3) = ${m.group(3)}"
      println "m[1] = ${m[1]}"
      println "m[2] = ${m[2]}"
      println "m[3] = ${m[3]}"
      }

      The output with jsr-03 is:

      m.pattern().pattern() = ^(.*)(\d+)(\d+)
      m.matches() = true
      m.groupCount() = 3
      m.group(1) = Hallo
      m.group(2) = 1
      m.group(3) = 3
      Exception in thread "main" java.lang.IndexOutOfBoundsException: index is out of range -1..0 (index = 1)
      at org.codehaus.groovy.runtime.DefaultGroovyMethods.getAt(DefaultGroovyMethods.java:1434)
      at gjdk.java.util.regex.Matcher_GroovyReflector.invoke(Unknown Source)
      at groovy.lang.MetaMethod.invoke(MetaMethod.java:110)
      at org.codehaus.groovy.runtime.NewInstanceMetaMethod.invoke(NewInstanceMetaMethod.java:99)
      at groovy.lang.MetaClass.doMethodInvoke(MetaClass.java:1455)
      at groovy.lang.MetaClass.invokeMethod(MetaClass.java:318)
      at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:145)
      at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
      at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
      at matcher.run(Unknown Source)
      at gjdk.matcher_GroovyReflector.invoke(Unknown Source)
      at groovy.lang.MetaMethod.invoke(MetaMethod.java:110)
      at groovy.lang.MetaClass.doMethodInvoke(MetaClass.java:1455)
      at groovy.lang.MetaClass.invokeMethod(MetaClass.java:318)
      at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:165)
      at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
      at org.codehaus.groovy.runtime.InvokerHelper.runScript(InvokerHelper.java:504)
      at gjdk.org.codehaus.groovy.runtime.InvokerHelper_GroovyReflector.invoke(Unknown Source)
      at groovy.lang.MetaMethod.invoke(MetaMethod.java:110)
      at groovy.lang.MetaClass.doMethodInvoke(MetaClass.java:1455)
      at groovy.lang.MetaClass.invokeStaticMethod(MetaClass.java:464)
      at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:137)
      at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
      at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
      at matcher.main(Unknown Source)

      Attachments

        Activity

          People

            Unassigned Unassigned
            tkong Thipor Kong
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: