String class broken in latest JDK

Java bug 6935535:

  1. public class Test {
  2.   public static void main(String args[]) {
  3.  
  4.     String str = "1111111111111xx1111111111111xx1x";
  5.     str = str.substring(0, 31);
  6.     String query = "1111111111111xx1x";
  7.     int idx = str.indexOf(query);
  8.     System.out.println("IndexOf(" + query + ") = " + idx + " in " + str);
  9.   }
  10. }
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

Category: Software | Tags: , , Comment »


Leave a Reply



 

Back to top