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

Negation on nested character classes does not work

    XMLWordPrintable

Details

    Description

      ADDITIONAL SYSTEM INFORMATION :
      Win 10 / Java 1.8.0_181

      A DESCRIPTION OF THE PROBLEM :
      Negation on nested character classes does not work
      Pattern.compile("[^[a]]").matcher("a").matches();
      provides true, but should provide false

      (same for more complicated expressions)
      if this should not be supported I would expect a proper exception for an invalid syntax

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
              // shows version 1.8.0_181
              System.out.println(System.getProperty("java.version"));

              // OK: runs through => matches a => fine
              assert Pattern.compile("[[a]]").matcher("a").matches();

              // OK: does not match a
              assert ! Pattern.compile("[^a]").matcher("a").matches();

              // NOT OK: does still match a = > assertion fails
              assert ! Pattern.compile("[^[a]]").matcher("a").matches();


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      expected

      [^[a]] should have same semantic as [a]

      =>
      Pattern.compile("[^[a]]").matcher("a").matches();
      should result in false, not true
      ACTUAL -
      Pattern.compile("[^[a]]").matcher("a").matches();

      => false

      ---------- BEGIN SOURCE ----------
      s. above
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      avoid nested character classes and negation

      FREQUENCY : always


      Attachments

        Issue Links

          Activity

            People

              psonal Pallavi Sonal (Inactive)
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: