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

replaceAll("\u20ac", "$"); causses java.lang.StringIndexOutOfBoundsExceptio

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 8
    • 6, 6u10
    • core-libs
    • b36
    • x86
    • windows_xp
    • Verified

      FULL PRODUCT VERSION :
      java version "1.6.0_24"
      Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
      Java HotSpot(TM) Client VM (build 19.1-b02, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
        public void test(){
          String s1 = "\u20ac";
      // or
      // String s1 = "€";
          s1 = s1.replaceAll("\u20ac", "$");
      // or
      // s1 = s1.replaceAll("€", "$");
          System.out.println(s1);
        }

      causes
      Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 1

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      run:

        public void test(){
          String s1 = "\u20ac";
      // or
      // String s1 = "€";
          s1 = s1.replaceAll("\u20ac", "$");
      // or
      // s1 = s1.replaceAll("€", "$");
          System.out.println(s1);
        }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      output of $ not an exception
      ACTUAL -
      Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 1
      at java.lang.String.charAt(Unknown Source)
      at java.util.regex.Matcher.appendReplacement(Unknown Source)
      at java.util.regex.Matcher.replaceAll(Unknown Source)
      at java.lang.String.replaceAll(Unknown Source)
      ...

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

        public void test(){
          String s1 = "\u20ac";
      // or
      // String s1 = "€";
          s1 = s1.replaceAll("\u20ac", "$");
      // or
      // s1 = s1.replaceAll("€", "$");
          System.out.println(s1);
        }
      ---------- END SOURCE ----------

            sherman Xueming Shen
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: