Archive for September 2010


String class broken in latest JDK

September 30th, 2010 — 11:32am

Java bug 6935535:

public class Test {
    public static void main(String args[]) {
        String str = "1111111111111xx1111111111111xx1x";
        str = str.substring(0, 31);
        String query = "1111111111111xx1x";
        int idx = str.indexOf(query);
        System.out.println("IndexOf(" + query + ") = " + idx + " in " + str);
    }
}
javac Test.java

# Java interpreter
java Test
IndexOf(1111111111111xx1x) = -1 in 1111111111111xx1111111111111xx1

# BUG !! When HotSpot compiler is on
java -Xcompile Test
IndexOf(1111111111111xx1x) = 15 in 1111111111111xx1111111111111xx1

Seen on both Sun JDK 1.6.0_20 and OpenJDK 1.6.0_18

Update: This bug is fixed in Sun JDK 1.6.0_22

Comment » | Software

Back to top