Codereview request 7067045: replaceAll("\u20ac", "$"); causses java.lang.StringIndexOutOfBoundsExceptio

Roger Riggs Roger.Riggs at Oracle.com
Wed Apr 18 10:33:23 UTC 2012


There may be a bug in the test at RegExTest:L860, since the IAE is expected
the second test for "\\" will not occur. Perhaps there should be a 
comment in the empty
block at L863.

Static strings should usually be sufficient and can be localized if needed
though the core libs exception messages have no requirement to be 
localizable.
If the arguments are needed, I would prefer String.format over implicit 
concatenation.

Calls to String.format are easier to maintain and easier to read in the 
source.
Keep in mind that any computation of the message will be done every time the
exception is thrown whether anyone ever sees the message or not.

$.02, Roger


On 4/18/12 4:12 AM, Paul Sandoz wrote:
> On Apr 17, 2012, at 9:35 PM, Xueming Shen wrote:
>
>> Hi Paul, I'm fine with the more detailed the exception messages.  Though personally I don't
>> see the necessity of using String.format(...) for those String and integer arguments,
> Yeah, a habit of mine, when editing I find it easier to modify rather than shuffling string concatenations.
>
>
>> a simple
>> concatenation might be good enough here. Are you interested to start from filing a new bug
>> on this issue and then go through the whole process to update these exception message?
>>
> Yes, except i cannot file a bug yet... still sorting out access.
>
> Thanks,
> Paul.
>
>> Thanks!
>> -Sherman
>>
>> On 04/17/2012 10:02 AM, Paul Sandoz wrote:
>>> Hi Sherman,
>>>
>>> Here is an example:
>>>
>>> http://cr.openjdk.java.net/~psandoz/errors-in-matcher/webrev.0/<http://cr.openjdk.java.net/%7Epsandoz/errors-in-matcher/webrev.0/>
>>>
>>> I am not sure what, if any, are the JDK guidelines for stuffing information in exception messages.
>>>
>>> Paul.
>>>
>>> On Apr 16, 2012, at 10:24 AM, Paul Sandoz wrote:
>>>
>>>> Hi Sherman,
>>>>
>>>> IMHO it is worth spending a little time getting the exception messages a little more accurate. I have spent too many a time staring at such messages wondering what the heck is going on :-)
>>>>
>>>> e.g.
>>>>
>>>> Syntax error parsing replacement string: escaped literal character is missing at the end of the string.
>>>>
>>>> Syntax error parsing replacement string: group reference is missing at the end of the string.
>>>>
>>>>
>>>> Since i am proposing this i will send a patch. It will help me get familiar with the whole OpenJDK process.
>>>>
>>>> Pau;.
>>>>
>>>> On Apr 12, 2012, at 10:09 PM, Xueming Shen wrote:
>>>>
>>>>> Hi
>>>>>
>>>>> Please help review the change for 7067045.
>>>>>
>>>>> The change is to throw a more meaningful IAE instead of the StringIndexoutputOfBoundsException
>>>>> if backslash or $ is the last character in the replacement string. (as the API indicated, the backslash
>>>>> and $ character in String's regex replacement and Matcher class have special meanings, backslash
>>>>> is for literal character escape and the $ is the capturing group reference, which needs a group index).
>>>>>
>>>>> http://cr.openjdk.java.net/~sherman/7067045/webrev/<http://cr.openjdk.java.net/%7Esherman/7067045/webrev/>
>>>>>
>>>>> Thanks,
>>>>> -Sherman



More information about the core-libs-dev mailing list