--- a/jdk/src/share/classes/java/util/regex/Matcher.java Thu Apr 12 10:55:51 2012 -0700
+++ b/jdk/src/share/classes/java/util/regex/Matcher.java Thu Apr 12 15:01:41 2012 -0700
@@ -759,16 +759,19 @@
char nextChar = replacement.charAt(cursor);
if (nextChar == '\\') {
cursor++;
+ if (cursor == replacement.length())
+ throw new IllegalArgumentException(
+ "character to be escaped is missing");
nextChar = replacement.charAt(cursor);
result.append(nextChar);
cursor++;
} else if (nextChar == '$') {
// Skip past $
cursor++;
- // A StringIndexOutOfBoundsException is thrown if
- // this "$" is the last character in replacement
- // string in current implementation, a IAE might be
- // more appropriate.
+ // Throw IAE if this "$" is the last character in replacement
+ if (cursor == replacement.length())
+ throw new IllegalArgumentException(
+ "Illegal group reference: group index is missing");
nextChar = replacement.charAt(cursor);
int refNum = -1;
if (nextChar == '{') {