You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Mikhail Fursov (JIRA)" <ji...@apache.org> on 2006/07/27 15:33:13 UTC

[jira] Created: (HARMONY-997) String.replaceAll method does not work like RI if replacement string contains a backslash

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

        

[jira] Closed: (HARMONY-997) String.replaceAll method does not work like RI if replacement string contains a backslash

Posted by "Nathan Beyer (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HARMONY-997?page=all ]

Nathan Beyer closed HARMONY-997.
--------------------------------


Verified.

> 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
>         Attachments: patch_src.diff, patch_tests.diff
>
>
> 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

        

[jira] Commented: (HARMONY-997) String.replaceAll method does not work like RI if replacement string contains a backslash

Posted by "Nikolay Kuznetsov (JIRA)" <ji...@apache.org>.
    [ 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

        

[jira] Assigned: (HARMONY-997) String.replaceAll method does not work like RI if replacement string contains a backslash

Posted by "Nathan Beyer (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HARMONY-997?page=all ]

Nathan Beyer reassigned HARMONY-997:
------------------------------------

    Assignee: Nathan Beyer

> 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

        

[jira] Resolved: (HARMONY-997) String.replaceAll method does not work like RI if replacement string contains a backslash

Posted by "Nathan Beyer (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HARMONY-997?page=all ]

Nathan Beyer resolved HARMONY-997.
----------------------------------

    Resolution: Fixed

Patch applied. Please verify. Thanks.

> 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
>         Attachments: patch_src.diff, patch_tests.diff
>
>
> 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

        

[jira] Commented: (HARMONY-997) String.replaceAll method does not work like RI if replacement string contains a backslash

Posted by "Nathan Beyer (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/HARMONY-997?page=comments#action_12424453 ] 
            
Nathan Beyer commented on HARMONY-997:
--------------------------------------

Do you have some documentation or code to assert that this is a bug in Harmony and not a bug in the RI? Based on my quick read of the API, it would seem that doing a replacement with a '\' character, if properly escaped should work. Even if it's not meant to, then a StringIndexOutOfBoundsException seems like a weird error.

In any case, the underlying difference is in the regex module, so any further examples should be expressed with the underlying APIs.

Thanks.

> 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

        

[jira] Commented: (HARMONY-997) String.replaceAll method does not work like RI if replacement string contains a backslash

Posted by "Anton Ivanov (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/HARMONY-997?page=comments#action_12431246 ] 
            
Anton Ivanov commented on HARMONY-997:
--------------------------------------

Thanks. Looks good.

> 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
>         Attachments: patch_src.diff, patch_tests.diff
>
>
> 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

        

[jira] Updated: (HARMONY-997) String.replaceAll method does not work like RI if replacement string contains a backslash

Posted by "Anton Ivanov (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HARMONY-997?page=all ]

Anton Ivanov updated HARMONY-997:
---------------------------------

    Attachment: patch_src.diff
                patch_tests.diff

Patch for the problem.

> 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
>         Attachments: patch_src.diff, patch_tests.diff
>
>
> 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