-
Bug
-
Resolution: Not an Issue
-
P2
-
None
-
1.4.1, 1.4.2
-
None
-
x86, sparc
-
solaris_8, windows_2000
Following is the test program
----------------------------
public class slash {
public static void main (String str[]){
String s = "HixyzHelloxyz";
System.out.println(s);
//s = s.replaceAll("xyz","$");
s = s.replaceAll("xyz","\\");
System.out.println(s);
}
}
$ /net/sqindia/export/disk01/jdk/1.4.1/beta/b12/binaries/solsparc/bin/java -version
java version "1.4.1-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-beta-b12)
Java HotSpot(TM) Client VM (build 1.4.1-beta-b12, mixed mode)
Output:
---------
HixyzHelloxyz
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 1
at java.lang.String.charAt(String.java:455)
at java.util.regex.Matcher.appendReplacement(Matcher.java:532)
at java.util.regex.Matcher.replaceAll(Matcher.java:636)
at java.lang.String.replaceAll(String.java:1706)
at slash.main(slash.java:6)
Spec says 'An invocation of this (replaceAll) method of the form str. replaceAll (regex, repl) yields exactly the same result as the expression
Pattern.compile(regex).matcher(str).replaceAll(repl)
However, this is also results into same error.
For Example:
import java.util.regex.*;
public class t{
public static void main (String str[]){
String s = "HixyzHelloxyz";
Pattern.compile("xyz").matcher(s).replaceAll("$");
System.out.println(s);
}
}
This also exists in Merlin- FCS (b92).
----------------------------
public class slash {
public static void main (String str[]){
String s = "HixyzHelloxyz";
System.out.println(s);
//s = s.replaceAll("xyz","$");
s = s.replaceAll("xyz","\\");
System.out.println(s);
}
}
$ /net/sqindia/export/disk01/jdk/1.4.1/beta/b12/binaries/solsparc/bin/java -version
java version "1.4.1-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-beta-b12)
Java HotSpot(TM) Client VM (build 1.4.1-beta-b12, mixed mode)
Output:
---------
HixyzHelloxyz
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 1
at java.lang.String.charAt(String.java:455)
at java.util.regex.Matcher.appendReplacement(Matcher.java:532)
at java.util.regex.Matcher.replaceAll(Matcher.java:636)
at java.lang.String.replaceAll(String.java:1706)
at slash.main(slash.java:6)
Spec says 'An invocation of this (replaceAll) method of the form str. replaceAll (regex, repl) yields exactly the same result as the expression
Pattern.compile(regex).matcher(str).replaceAll(repl)
However, this is also results into same error.
For Example:
import java.util.regex.*;
public class t{
public static void main (String str[]){
String s = "HixyzHelloxyz";
Pattern.compile("xyz").matcher(s).replaceAll("$");
System.out.println(s);
}
}
This also exists in Merlin- FCS (b92).
- duplicates
-
JDK-4846419 String.replaceAll(String reg,String replacement) not working for reg = "\\"
-
- Closed
-