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

Internal error in java.util.regex if string ends with backslash

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.2
    • core-libs
    • x86
    • windows_2000



      Name: gm110360 Date: 01/27/2004


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

      ADDITIONAL OS VERSION INFORMATION :
      win 2000, build 2195, sp4

      A DESCRIPTION OF THE PROBLEM :
      when you try to match a string that ENDS with a backslash, the runtime will crash.

      String test = "c:\test";
      System.out.println(test.replaceAll("\\", "repl"));

      will give:


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Replace the backslash in c:\test with 'repl'

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.util.regex.PatternSyntaxException: Unexpected internal error near index 1
       ^
      at java.util.regex.Pattern.error(Unknown Source)
      at java.util.regex.Pattern.compile(Unknown Source)
      at java.util.regex.Pattern.<init>(Unknown Source)
      at java.util.regex.Pattern.compile(Unknown Source)
      at java.lang.String.replaceAll(Unknown Source)
      at TestDriver.main(TestDriver.java:9)
      Exception in thread "main"

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class TestDriver
      {
        public static void main(String[] args)
        {
             String test = "c:\test";
             System.out.println(test.replaceAll("\\", "repl"));
        }
      }
      ---------- END SOURCE ----------
      (Incident Review ID: 230841)
      ======================================================================

            mmcclosksunw Michael Mccloskey (Inactive)
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: