{"id":282,"date":"2010-09-30T11:32:25","date_gmt":"2010-09-30T18:32:25","guid":{"rendered":"http:\/\/www.dragishak.com\/?p=282"},"modified":"2020-08-28T12:59:36","modified_gmt":"2020-08-28T19:59:36","slug":"string-class-broken-in-latest-jdk","status":"publish","type":"post","link":"https:\/\/www.dragishak.com\/?p=282","title":{"rendered":"String class broken in latest JDK"},"content":{"rendered":"<p>Java bug <a href=\"http:\/\/bugs.sun.com\/bugdatabase\/view_bug.do?bug_id=6935535\">6935535<\/a>:<\/p>\n<pre><pre class=\"brush: java; title: ; notranslate\" title=\"\">\npublic class Test {\n    public static void main(String args&#x5B;]) {\n        String str = &quot;1111111111111xx1111111111111xx1x&quot;;\n        str = str.substring(0, 31);\n        String query = &quot;1111111111111xx1x&quot;;\n        int idx = str.indexOf(query);\n        System.out.println(&quot;IndexOf(&quot; + query + &quot;) = &quot; + idx + &quot; in &quot; + str);\n    }\n}\n<\/pre>\n<pre>javac Test.java\n\n# Java interpreter\njava Test\nIndexOf(1111111111111xx1x) = -1 in 1111111111111xx1111111111111xx1\n\n# BUG !! When HotSpot compiler is on\njava -Xcompile Test\nIndexOf(1111111111111xx1x) = 15 in 1111111111111xx1111111111111xx1\n<\/pre>\n<p>Seen on both Sun JDK 1.6.0_20 and OpenJDK 1.6.0_18<\/p>\n<p><strong>Update: This bug is fixed in Sun JDK 1.6.0_22<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java bug 6935535: public class Test { public static void main(String args&#x5B;]) { String str = &quot;1111111111111xx1111111111111xx1x&quot;; str = str.substring(0, 31); String query = &quot;1111111111111xx1x&quot;; int idx = str.indexOf(query); System.out.println(&quot;IndexOf(&quot; + query + &quot;) = &quot; + idx + &quot; in &quot; + str); } } javac Test.java # Java interpreter java Test IndexOf(1111111111111xx1x) = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[32,29,51],"class_list":["post-282","post","type-post","status-publish","format-standard","hentry","category-software","tag-bug","tag-java","tag-string"],"_links":{"self":[{"href":"https:\/\/www.dragishak.com\/index.php?rest_route=\/wp\/v2\/posts\/282","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dragishak.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dragishak.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dragishak.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dragishak.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=282"}],"version-history":[{"count":24,"href":"https:\/\/www.dragishak.com\/index.php?rest_route=\/wp\/v2\/posts\/282\/revisions"}],"predecessor-version":[{"id":403,"href":"https:\/\/www.dragishak.com\/index.php?rest_route=\/wp\/v2\/posts\/282\/revisions\/403"}],"wp:attachment":[{"href":"https:\/\/www.dragishak.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=282"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dragishak.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=282"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dragishak.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=282"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}