Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8160312

ArrayIndexOutOfBoundsException when comparing strings case insensitive

    Details

    • Subcomponent:
    • Introduced In Version:
      9
    • Resolved In Build:
      b126
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      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 ----------

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                sherman Xueming Shen
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: