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

Implement workaround for JDK 1.4 String.replaceAll bug.

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.6-rc-2, 1.5.8
    • None
    • None

    Description

      There is a bug in JDK 1.4's String.replaceAll in which quoted (\Q..\E) patterns that contain a backslash are not matched correctly.

      This should work, but does not in JDK 1.4 (JDK 1.5 is OK):

      assert "axa".equals("a\\a".replaceAll("\\Q\\\\E", "x"))
      

      The workaround is to have RegexUtils.quote not put backslashes inside the quote, but instead escape out of the quote and use a backslash to escape the backslash.

      So this does work in JDK 1.4 (and JDK 1.5 too of course):

      assert "axa".equals("a\\a".replaceAll("\\Q\\E\\\\\\Q\\E", "x"))
      

      Attachments

        Issue Links

          Activity

            People

              jimwhite James P. White
              jimwhite James P. White
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: