String.lastIndexOf confused by unpaired trailing surrogate

Martin Buchholz martinrb at
Sat Mar 20 18:36:22 UTC 2010

For a change, here's an actual plain old "incorrect result" bug fix
for String.lastIndexOf

Sherman, please file a bug and review.

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
==> java -esa -ea LastIndexOf

More information about the core-libs-dev mailing list