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

String.replaceAll(String reg,String replacement) not working for reg = "\\"

XMLWordPrintable

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



      Name: gm110360 Date: 04/10/2003


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

      FULL OS VERSION :
      Linux srv1.xenia.access.com.au 2.4.18-3 #1 Thu Apr 18 07:37:53 EDT 2002 i686 unknown

      A DESCRIPTION OF THE PROBLEM :
      My application is running under linux box, and I was tring to replace the windows file seperator with a solaris/linux file seperator for a path String,

      Code likes:
      String serverPath = tempPath.replaceAll("\\",File.separator);

      I got exception:

      java.util.regex.PatternSyntaxException: Unexpected internal error near index 1
       ^
              at java.util.regex.Pattern.error(Pattern.java:1489)
              at java.util.regex.Pattern.compile(Pattern.java:1281)
              at java.util.regex.Pattern.<init>(Pattern.java:1030)
              at java.util.regex.Pattern.compile(Pattern.java:777)
              at java.lang.String.replaceAll(String.java:1710)
              at au.com.access.deploy.agent.AgentThread.processSetFileRequest(AgentThread.java
      :270)
              at au.com.access.deploy.agent.AgentThread.processMessage(AgentThread.java:134)
              at au.com.access.deploy.agent.AgentThread.run(AgentThread.java:594)

      au.com.access.deploy.agent.AgentThread.processSetFileRequest : Unexpected internal error
       near index 1

       

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      String tempPath = "\\root\\temp";

      String serverPath = tempPath.replaceAll("\\",File.separator);


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      no exception caught and serverPath = "/root/temp" as expected.
      I got exception:

      java.util.regex.PatternSyntaxException: Unexpected internal error near index 1
       ^
              at java.util.regex.Pattern.error(Pattern.java:1489)
              at java.util.regex.Pattern.compile(Pattern.java:1281)
              at java.util.regex.Pattern.<init>(Pattern.java:1030)
              at java.util.regex.Pattern.compile(Pattern.java:777)
              at java.lang.String.replaceAll(String.java:1710)
              at au.com.access.deploy.agent.AgentThread.processSetFileRequest(AgentThread.java
      :270)
              at au.com.access.deploy.agent.AgentThread.processMessage(AgentThread.java:134)
              at au.com.access.deploy.agent.AgentThread.run(AgentThread.java:594)

      au.com.access.deploy.agent.AgentThread.processSetFileRequest : Unexpected internal error
       near index 1



      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      I got exception:

      java.util.regex.PatternSyntaxException: Unexpected internal error near index 1
       ^
              at java.util.regex.Pattern.error(Pattern.java:1489)
              at java.util.regex.Pattern.compile(Pattern.java:1281)
              at java.util.regex.Pattern.<init>(Pattern.java:1030)
              at java.util.regex.Pattern.compile(Pattern.java:777)
              at java.lang.String.replaceAll(String.java:1710)
              at au.com.access.deploy.agent.AgentThread.processSetFileRequest(AgentThread.java
      :270)
              at au.com.access.deploy.agent.AgentThread.processMessage(AgentThread.java:134)
              at au.com.access.deploy.agent.AgentThread.run(AgentThread.java:594)

      au.com.access.deploy.agent.AgentThread.processSetFileRequest : Unexpected internal error
       near index 1



      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.*;

      public class test {
      public static void main(String[] args) {
      String tempPath = "\\test\\server\\test.txt";
      String serverPath = tempPath.replaceAll("\\",File.separator);
      }
      }
      ---------- END SOURCE ----------
      (Review ID: 183842)
      ======================================================================

            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: