Bug 1317001 - replaceAll causes Unexpected internal error
Summary: replaceAll causes Unexpected internal error
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: java-1.8.0-openjdk
Version: 7.2
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: jiri vanek
QA Contact: BaseOS QE - Apps
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-03-11 16:43 UTC by Marko Myllynen
Modified: 2016-03-15 08:17 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2016-03-14 13:05:05 UTC
Target Upstream Version:


Attachments (Terms of Use)

Description Marko Myllynen 2016-03-11 16:43:58 UTC
Description of problem:
$ cat StrTest.java
public class StrTest {
    public static void main (String[] args) {
        String test = "abc\"def";
        System.out.println("Test string is  :" + test + ":");
        test = test.replaceAll("\\", "");
        System.out.println("Test string now :" + test + ":");
    }
}
$ javac StrTest.java
$ java StrTest
Test string is  :abc"def:
Exception in thread "main" java.util.regex.PatternSyntaxException: Unexpected internal error near index 1
\
 ^
	at java.util.regex.Pattern.error(Pattern.java:1955)
	at java.util.regex.Pattern.compile(Pattern.java:1702)
	at java.util.regex.Pattern.<init>(Pattern.java:1351)
	at java.util.regex.Pattern.compile(Pattern.java:1028)
	at java.lang.String.replaceAll(String.java:2223)
	at StrTest.main(StrTest.java:5)
zsh: exit 1     java StrTest
$ rpm -qf $(readlink -f $(which java))
java-1.8.0-openjdk-headless-1.8.0.71-2.b15.el7_2.x86_64

Comment 2 jiri vanek 2016-03-14 13:05:05 UTC
Yes, the pattern is wrong.
this is only java slash escape.
  test = test.replaceAll("\\", "");
Regeex is second round of escaping. So to escape SINGLE slash, you need
  test = test.replaceAll("\\\\", "");

However, slash is NOT in your original string of
   String test = "abc\"def";

So I'm not sure what was yours goal. 
Maybe;
   public static void main (String[] args) {
        String test = "abc\\\"def";
        System.out.println("Test string is  :" + test + ":");
        test = test.replaceAll("\\\\", "");
        System.out.println("Test string now :" + test + ":");
    }

: Test string is  :abc\"def:
: Test string now :abc"def:

So... this is not a bug. This is very correct behaviour.

Comment 3 Marko Myllynen 2016-03-15 07:08:33 UTC
The regex is wrong, yes, but the issue was "Unexpected internal error," which sounds like a JVM internal issue not a regex pattern issue. Thanks.

Comment 4 jiri vanek 2016-03-15 07:39:06 UTC
Still it is PatternSyntaxException. And although I agree that " Unexpected internal error near index 1\^" is not exactly est message. It is correclty pointing to position in your regex(^\) and also in java code where it happened	(at java.util.regex.Pattern.error(Pattern.java:1955)), So I would not claim it as bug. If you disagree, feel free to reopen.

Comment 5 Marko Myllynen 2016-03-15 08:17:22 UTC
I saw PatternSyntaxException earlier so when I see this "Unexpected internal error" I thought this is something different. I guess it would be better to have consistent error messages in every case possible but I'll leave it up to you to make the final call whether this is worth changing or not. Thanks.


Note You need to log in before you can comment on or make changes to this bug.