String.lastIndexOf confused by unpaired trailing surrogate

Ulf Zibis Ulf.Zibis at gmx.de
Sat Mar 20 22:50:49 UTC 2010


Oops, later I looked in your webrev and saw your same idea at same time 
while I was composing my before-last email.

Why don't you outsource indexOfBMP, lastIndexOfBMP, or to be sincere IMO 
to much source code + byte code overhead for a only once used 3-liner.

I suspect if all the finals will have any benefit. Some time ago I too 
felt in that trap, or am I wrong. Examine the disassambly.

-Ulf


Am 20.03.2010 23:05, schrieb Ulf Zibis:
> Good catch!
> Additionally consider my additional twiddling on indexOf.
>
> -Ulf
>
>
> Am 20.03.2010 19:36, schrieb Martin Buchholz:
>> For a change, here's an actual plain old "incorrect result" bug fix
>> for String.lastIndexOf
>>
>> Sherman, please file a bug and review.
>>
>> http://cr.openjdk.java.net/~martin/webrevs/openjdk7/lastIndexOf/
>>
>> Also includes our usual performance-oriented fiddling.
>>
>> public class LastIndexOf {
>>      public static void main(String[] args) {
>>          int ch = 0x10042;
>>          char[] bug = new char[3];
>>          Character.toChars(ch, bug, 0);
>>          bug[2] = bug[0];
>>          System.out.println(new String(bug).lastIndexOf(ch));
>>          bug[2] = '!';
>>          System.out.println(new String(bug).lastIndexOf(ch));
>>      }
>> }
>> ==>  javac -source 1.6 -Xlint:all LastIndexOf.java
>> ==>  java -esa -ea LastIndexOf
>> -1
>> 0
>>
>>
>
>




More information about the core-libs-dev mailing list