Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1317001

Summary: replaceAll causes Unexpected internal error
Product: Red Hat Enterprise Linux 7 Reporter: Marko Myllynen <myllynen>
Component: java-1.8.0-openjdkAssignee: jiri vanek <jvanek>
Status: CLOSED NOTABUG QA Contact: BaseOS QE - Apps <qe-baseos-apps>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.2CC: sbaiduzh
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-03-14 13:05:05 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

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.