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

Creating Pattern from declared String variable with pattern = ~stringvariable fails

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.8.0
    • 1.8.1, 1.7.11
    • None
    • None
    • Windows 7 64bit, 32 bit jvm 1.6.0_26

    Description

      An attempt to create a java.util.regex.Pattern from a variable that is declared as a String fails with a java.lang.ClassCastException: java.util.regex.Pattern cannot be cast to java.lang.String

      The code below worked with Groovy 1.7.8 but fails with Groovy 1.8.0
      String value="test"
      String s = "^\\S+$value\$"
      def p = ~s <==Fails here

      A workaround is to change the last statement to:
      def p = ~/$s/
      but that adds clutter

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            ola.mattsson Ola Mattsson
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: