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

java.util.regex.Matcher utilizes 100% of the CPU

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • 9
    • 5.0
    • core-libs
    • b119
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      Fedora:
      java version "1.4.2_04"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
      Java HotSpot(TM) Client VM (build 1.4.2_04-b05, mixed mode)

      Windows:
      java version "1.5.0_04"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0
      Java HotSpot(TM) Client VM (build 1.5.0_04-b05, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      2.6.12-1.1378_FC3smp #1 SMP Wed Sep 14 04:52:36 EDT 2005 i686 i686 i386 GNU/Linux Fedora Core release 3 (Heidelberg)

      and

      Microsoft Windows XP Professional Version 2002 Service Pack 2
      Pentium(R) 4 CPU 2.80GHz
      1GB of RAM

      A DESCRIPTION OF THE PROBLEM :
      ((<[^>]+>)?(((\\s)?)*(\\&nbsp;)?)*((\\s)?)*)+ pattern causes the matcher to utilize 100% of the CPU when matching against the following pattern:
      "&nbsp;&nbsp; < br/> &nbsp; < / p> <p> <html> <adfasfdasdf>&nbsp; p </p>"

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      See test case.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      GOOD is the expected result.
      ACTUAL -
      Utilizes 100% of CPU

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.regex.Matcher;
      import java.util.regex.Pattern;

      public class RegExp
      {
          public static void main(String[] args)
          {
              String[] exps = new String[] {
                  //"<asdfasdf><x>"
                  //"<p>&nbsp;&nbsp;"
                  "&nbsp;&nbsp; < br/> &nbsp; < / p> <p> <html> <adfasfdasdf>&nbsp; p </p>"
                  //" <xx> <adfasfdasdf>&nbsp; p </p>"
              };
              
              for (int i = 0; i < exps.length; i++)
              {
                  Pattern p = Pattern.compile("((<[^>]+>)?(((\\s)?)*(\\&nbsp;)?)*((\\s)?)*)+");
                  Matcher m = p.matcher(exps[i]);
                  if (m.matches())
                  {
                      System.out.println("replace["+m.replaceAll("REPLACED")+"]");
                  }
                  else
                  {
                      System.out.println("GOOD");
                  }
              }
          }
      }

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

            sherman Xueming Shen
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: