java.lang.IllegalArgumentException: Illegal group reference at java.util.regex.Matcher.appendExpandedReplacement(java.base@9-ea/Matcher.java:1068) at java.util.regex.Matcher.appendReplacement(java.base@9-ea/Matcher.java:998) at java.util.regex.Matcher.replaceAll(java.base@9-ea/Matcher.java:1181) at java.lang.String.replaceAll(java.base@9-ea/String.java:2162)

JDK Bug System | Webbug Group | 8 months ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    FULL PRODUCT VERSION : java version "1.8.0_73" Java(TM) SE Runtime Environment (build 1.8.0_73-b02) Java HotSpot(TM) Client VM (build 25.73-b02, mixed mode, sharing) ADDITIONAL OS VERSION INFORMATION : Windows 10 EXTRA RELEVANT SYSTEM CONFIGURATION : In Matcher.java line 854 is written: // The first number is always a group refNum = (int)nextChar - '0'; if ((refNum < 0)||(refNum > 9)) throw new IllegalArgumentException( "Illegal group reference"); That the first character after $ is always a number is not correct. A DESCRIPTION OF THE PROBLEM : That the first character after $ is always a number is not correct. STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : public static void main(String[] args) { final String k = "1234"; System.out.println(k.replaceAll("23", "$&")); } ACTUAL - Exception in thread "main" java.lang.IllegalArgumentException: Illegal group reference at java.util.regex.Matcher.appendReplacement(Matcher.java:857) at java.util.regex.Matcher.replaceAll(Matcher.java:955) at java.lang.String.replaceAll(String.java:2210) at overlay.StartupTest.main(StartupTest.java:52) ERROR MESSAGES/STACK TRACES THAT OCCUR : Exception in thread "main" java.lang.IllegalArgumentException: Illegal group reference at java.util.regex.Matcher.appendReplacement(Matcher.java:857) at java.util.regex.Matcher.replaceAll(Matcher.java:955) at java.lang.String.replaceAll(String.java:2210) at overlay.StartupTest.main(StartupTest.java:52) REPRODUCIBILITY : This bug can be reproduced always. ---------- BEGIN SOURCE ---------- public static void main(String[] args) { final String k = "1234"; System.out.println(k.replaceAll("23", "$&")); } ---------- END SOURCE ----------

    JDK Bug System | 8 months ago | Webbug Group
    java.lang.IllegalArgumentException: Illegal group reference at java.util.regex.Matcher.appendExpandedReplacement(java.base@9-ea/Matcher.java:1068) at java.util.regex.Matcher.appendReplacement(java.base@9-ea/Matcher.java:998) at java.util.regex.Matcher.replaceAll(java.base@9-ea/Matcher.java:1181) at java.lang.String.replaceAll(java.base@9-ea/String.java:2162)

    Root Cause Analysis

    1. java.lang.IllegalArgumentException

      Illegal group reference at java.util.regex.Matcher.appendExpandedReplacement(java.base@9-ea/Matcher.java:1068) at java.util.regex.Matcher.appendReplacement(java.base@9-ea/Matcher.java:998) at java.util.regex.Matcher.replaceAll(java.base@9-ea/Matcher.java:1181) at java.lang.String.replaceAll(java.base@9-ea/String.java:2162)

      at JI9042279.main()
    2. Unknown
      JI9042279.main
      1. JI9042279.main(JI9042279.java:6)
      1 frame