JDK-8160312 : ArrayIndexOutOfBoundsException when comparing strings case insensitive
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 9
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2016-06-25
  • Updated: 2022-08-10
  • Resolved: 2016-06-27
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9 b126Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "9-ea"
Java(TM) SE Runtime Environment (build 9-ea+124)
Java HotSpot(TM) 64-Bit Server VM (build 9-ea+124, mixed mode)

A DESCRIPTION OF THE PROBLEM :
With JDK 9, some strings can't be compared using compareToIgnoreCase, because of an error in StringLatin1 which produces an exception: StringLatin1.compareToCI  assumes that  an upper case variant of a Latin1 character is a Latin1 character (see line 140 in StringLatin1.java), but the upper-case variant of character 181 is 924. 

We can't use JFileChooser even, see the second stack trace. 

REGRESSION.  Last worked in version 8u92

ADDITIONAL REGRESSION INFORMATION: 
java version "9-ea"
Java(TM) SE Runtime Environment (build 9-ea+124)
Java HotSpot(TM) 64-Bit Server VM (build 9-ea+124, mixed mode)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
execute this statement: System.out.println(new String(new char[]{181}).compareToIgnoreCase("X"))


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
print a non-zero number (e.g. 836 as in JDK 8)
ACTUAL -
the stack trace appears

ERROR MESSAGES/STACK TRACES THAT OCCUR :
jshell> new String(new char[]{181}).compareToIgnoreCase("X")
|  java.lang.ArrayIndexOutOfBoundsException thrown: 924
|        at CharacterDataLatin1.getProperties (CharacterDataLatin1.java:72)
|        at CharacterDataLatin1.toLowerCase (CharacterDataLatin1.java:134)
|        at StringLatin1.compareToCI (StringLatin1.java:140)
|        at String$CaseInsensitiveComparator.compare (String.java:1244)
|        at String$CaseInsensitiveComparator.compare (String.java:1235)
|        at String.compareToIgnoreCase (String.java:1275)
|        at (#1:1)





java.lang.ArrayIndexOutOfBoundsException: 924
        at java.lang.CharacterDataLatin1.getProperties(java.base@9-ea/CharacterDataLatin1.java:72)
        at java.lang.CharacterDataLatin1.toLowerCase(java.base@9-ea/CharacterDataLatin1.java:134)
        at java.lang.StringLatin1.compareToCI(java.base@9-ea/StringLatin1.java:140)
        at java.lang.String$CaseInsensitiveComparator.compare(java.base@9-ea/String.java:1244)
        at java.lang.String$CaseInsensitiveComparator.compare(java.base@9-ea/String.java:1235)
        at java.lang.String.compareToIgnoreCase(java.base@9-ea/String.java:1275)
        at sun.awt.shell.Win32ShellFolderManager2.compareNames(java.desktop@9-ea/Win32ShellFolderManager2.java:499)
        at sun.awt.shell.Win32ShellFolderManager2.compareShellFolders(java.desktop@9-ea/Win32ShellFolderManager2.java:494)
        at sun.awt.shell.Win32ShellFolder2.compareTo(java.desktop@9-ea/Win32ShellFolder2.java:1156)
        at sun.awt.shell.Win32ShellFolder2.compareTo(java.desktop@9-ea/Win32ShellFolder2.java:72)
        at java.util.ComparableTimSort.gallopRight(java.base@9-ea/ComparableTimSort.java:598)
        at java.util.ComparableTimSort.mergeAt(java.base@9-ea/ComparableTimSort.java:462)
        at java.util.ComparableTimSort.mergeCollapse(java.base@9-ea/ComparableTimSort.java:406)
        at java.util.ComparableTimSort.sort(java.base@9-ea/ComparableTimSort.java:213)
        at java.util.Arrays.sort(java.base@9-ea/Arrays.java:1248)
        at sun.awt.shell.Win32ShellFolderManager2.get(java.desktop@9-ea/Win32ShellFolderManager2.java:281)
        at sun.awt.shell.ShellFolder.get(java.desktop@9-ea/ShellFolder.java:258)
        at com.sun.java.swing.plaf.windows.WindowsFileChooserUI$DirectoryComboBoxModel.addItem(java.desktop@9-ea/WindowsFileChooserUI.java:1087)
        at com.sun.java.swing.plaf.windows.WindowsFileChooserUI$DirectoryComboBoxModel.access$800(java.desktop@9-ea/WindowsFileChooserUI.java:1055)
        at com.sun.java.swing.plaf.windows.WindowsFileChooserUI.doDirectoryChanged(java.desktop@9-ea/WindowsFileChooserUI.java:741)
        at com.sun.java.swing.plaf.windows.WindowsFileChooserUI.access$1100(java.desktop@9-ea/WindowsFileChooserUI.java:55)
        at com.sun.java.swing.plaf.windows.WindowsFileChooserUI$11.propertyChange(java.desktop@9-ea/WindowsFileChooserUI.java:832)
        at java.beans.PropertyChangeSupport.fire(java.desktop@9-ea/PropertyChangeSupport.java:341)
        at java.beans.PropertyChangeSupport.firePropertyChange(java.desktop@9-ea/PropertyChangeSupport.java:333)
        at java.beans.PropertyChangeSupport.firePropertyChange(java.desktop@9-ea/PropertyChangeSupport.java:266)
        at java.awt.Component.firePropertyChange(java.desktop@9-ea/Component.java:8531)
        at javax.swing.JFileChooser.setCurrentDirectory(java.desktop@9-ea/JFileChooser.java:595)
        at javax.swing.JFileChooser.<init>(java.desktop@9-ea/JFileChooser.java:349)
        at javax.swing.JFileChooser.<init>(java.desktop@9-ea/JFileChooser.java:295)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class A {

    public static void main(String[] args) {
        System.out.println(new String(new char[]{181}).compareToIgnoreCase("X"));
    }
}

---------- END SOURCE ----------


Comments
URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/44327147adc2 User: lana Date: 2016-07-06 20:17:35 +0000
06-07-2016

URL: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/44327147adc2 User: sherman Date: 2016-06-27 20:57:40 +0000
27-06-2016

started to fail from jdk9 b110, probably jdk-8151384
27-06-2016

Attached test case executed on : JDK 8u92 - Pass JDK 9 - Fail Output on JDK 9: ----------------------- java version "9-ea" Java(TM) SE Runtime Environment (build 9-ea+122) Java HotSpot(TM) 64-Bit Server VM (build 9-ea+122, mixed mode) Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 924 at java.lang.CharacterDataLatin1.getProperties(java.base@9-ea/CharacterDataLatin1.java:72) at java.lang.CharacterDataLatin1.toLowerCase(java.base@9-ea/CharacterDataLatin1.java:134) at java.lang.StringLatin1.compareToCI(java.base@9-ea/StringLatin1.java:140) at java.lang.String$CaseInsensitiveComparator.compare(java.base@9-ea/String.java:1244) at java.lang.String$CaseInsensitiveComparator.compare(java.base@9-ea/String.java:1235) at java.lang.String.compareToIgnoreCase(java.base@9-ea/String.java:1275) at JI9040771.main(JI9040771.java:5) Output on JDK 8u92 ----------------------------- java version "1.8.0_92" Java(TM) SE Runtime Environment (build 1.8.0_92-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode) 836
27-06-2016