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

Matcher.matches() has infinite loop

    XMLWordPrintable

Details

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

    Description

      FULL PRODUCT VERSION :
      java version "1.6.0_11"
      Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
      Java HotSpot(TM) Client VM (build 11.0-b16, mixed mode, sharing)

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

      A DESCRIPTION OF THE PROBLEM :
      See steps to reproduce and run the code snippet. The thread will hang in an infinite loop.

      The regular expression pattern is invalid as far as I know; I don't think the "?+" is correct. I would think that Pattern.compile() should be throwing an exception.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run this simple 2-line code snippet (full class below).

      Pattern pattern = Pattern.compile("(([0-9A-Z]+)([_]?+)*)*");
      pattern.matcher("FOOOOO_BAAAR_FOOOOOOOOO_BA_ ").matches();


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Should not hang.
      ACTUAL -
      VM hangs in an infinite loop.

      REPRODUCIBILITY :
      This bug can be reproduced always.

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

      public class RegexTest {
          public static void main(String[] args) {
              Pattern pattern = Pattern.compile("(([0-9A-Z]+)([_]?+)*)*");
              pattern.matcher("FOOOOO_BAAAR_FOOOOOOOOO_BA_ ").matches();
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Correct the regex.

      Attachments

        Issue Links

          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: