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

String: Matches hangs at short and easy Strings containing \r \n

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 5.0
    • Fix Version/s: 9
    • Component/s: core-libs
    • Labels:

      Description

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

      ADDITIONAL OS VERSION INFORMATION :
      Linux ncc-1701-e 2.6.11.4-21.9-smp #1 SMP Fri Aug 19 11:58:59 UTC 2005 i686 i686 i386 GNU/Linux SuSE Linux 9.3 (i586)
      Linux dauntless 2.6.11 #5 Tue Mar 15 17:45:56 CET 2005 i686 Mobile Intel(R) Celeron(R) CPU 2.40GHz GenuineIntel GNU/Linux Gentoo Base System version 1.4.16
      WinXP SP2

      A DESCRIPTION OF THE PROBLEM :
      There have been a couple of bugs filed about java.lang.String.matches hangs on specific expression. Always the only comment was that their expression is to comprehensive. I've found an example which proves that this is a bug that may occur at any time.

      The expression (.*\n*)* works on most Strings but crashes on some. Adding \r* is a workaround but in my opinion not neccessary.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      I wasn't able to find out how the given String has to look like but matching the String "this little fine string lets\r\njava.lang.String.matches\r\ncrash\r\n(We don't know why but adding \r* to the regex makes it work again)" against "(.*\r*\n*)*" works while "(.*\n*)*" crashes

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      System Output as:
      true|false
      true|false
      ACTUAL -
      true
      - HANGS -

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class MatchesCrash {
          
          public MatchesCrash() {
          }
          
          public static void main(String[] args) {
              String str="this little fine string lets\r\njava.lang.String.matches\r\ncrash\r\n(We don't know why but adding \r* to the regex makes it work again)";
              /* works */
              System.out.println(str.matches("(.*\r*\n*)*"));
              /* crashes */
              System.out.println(str.matches("(.*\n*)*"));
          }
          
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      adding the \r*

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                sherman Xueming Shen
                Reporter:
                gmanwanisunw Girish Manwani (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: