Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6995635

CANON_EQ pattern flag is buggy

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 9
    • 6u22
    • core-libs
    • b119
    • x86
    • windows_xp

    Description

      FULL PRODUCT VERSION :
      java version "1.6.0_14"
      Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
      Java HotSpot(TM) Client VM (build 14.0-b16, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      The following Java code will fail, because the CANON_EQ pattern flag produces the wrong code and therefore causes a PatterSyntaxException. It seems that the wrong code is created due to the parenthesis:

      import java.util.regex.Pattern;
      public class test {
      public static void main(String[] args) {
      Pattern patternThatIsGonnaBug=Pattern.compile("(ë)",Pattern.CANON_EQ);
      }
      }

      Output:
      Exception in thread "main" java.util.regex.PatternSyntaxException: Unmatched closing ')' near index 11
      ((?:e?)|ë)|e)?)
                 ^
      at java.util.regex.Pattern.error(Pattern.java:1713)
      at java.util.regex.Pattern.compile(Pattern.java:1464)
      at java.util.regex.Pattern.<init>(Pattern.java:1133)
      at java.util.regex.Pattern.compile(Pattern.java:847)
      at test.main(test.java:4)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      run the code as described above

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      a valid regular expression with matching group should be created
      ACTUAL -
      a broken regular expression is created

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.util.regex.PatternSyntaxException: Unmatched closing ')' near index 11
      ((?:e?)|ë)|e)?)
                 ^
      at java.util.regex.Pattern.error(Pattern.java:1713)
      at java.util.regex.Pattern.compile(Pattern.java:1464)
      at java.util.regex.Pattern.<init>(Pattern.java:1133)
      at java.util.regex.Pattern.compile(Pattern.java:847)
      at test.main(test.java:4)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.regex.Pattern;
      public class test {
      public static void main(String[] args) {
      Pattern patternThatIsGonnaBug=Pattern.compile("(ë)",Pattern.CANON_EQ);
      }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      A workaround would be to create a function which does the work of the CANON_EQ flag, but that would be very painful

      Attachments

        Activity

          People

            sherman Xueming Shen
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: