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

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

    XMLWordPrintable

Details

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

    Description

      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 ----------

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: