harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nikolay Kuznetsov (JIRA)" <j...@apache.org>
Subject [jira] Commented: (HARMONY-997) String.replaceAll method does not work like RI if replacement string contains a backslash
Date Mon, 31 Jul 2006 11:58:15 GMT
    [ http://issues.apache.org/jira/browse/HARMONY-997?page=comments#action_12424520 ] 
            
Nikolay Kuznetsov commented on HARMONY-997:
-------------------------------------------

Guys, frankly and honestly we do have a bug here any how. I've checked whith the source code
and have found that
we miss slash character at all. And this needs to be fixed.

While looking for similar problem in Sun's bug parade I've found nearly the same bug stated
over there:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4684543

This one is in fixed state with the following fix (updated JavaDoc for replace methods):

"Dollar signs may be treated as references to captured subsequences as described above, _and
backslashes are used to escape literal characters in the replacement string_."

This could be read as _all_ "backslashes are used to escape literal characters in the replacement
string", then RI's implementation simply looks for the next character after slash, and it
turns out that error like "StringIndexOutOfBoundsException" is more or less appropriate exception
in this case.

Note that example with double slash (\\\\), works as expected.

> String.replaceAll method does not work like RI if replacement string contains a backslash
> -----------------------------------------------------------------------------------------
>
>                 Key: HARMONY-997
>                 URL: http://issues.apache.org/jira/browse/HARMONY-997
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Mikhail Fursov
>         Assigned To: Nathan Beyer
>            Priority: Minor
>
> This test:
> "replace me".replaceAll("me", "\\");
> produces different  results when runned on Harmony or RI
> RI fails with a message:
> Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out
of range: 1
>         at java.lang.String.charAt(String.java:558)
>         at java.util.regex.Matcher.appendReplacement(Matcher.java:696)
>         at java.util.regex.Matcher.replaceAll(Matcher.java:806)
>         at java.lang.String.replaceAll(String.java:2000)
>         at Test.main(Test.java:13)
> while Harmony allows such replacement.
> I think this is Harmony bug.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message