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

String.toUpperCase() fails for single sharp s

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.2.0, 1.2.2
    • core-libs
    • merlin
    • generic
    • generic



      Name: dbT83986 Date: 03/11/99

      =20
      The following code is present in the JDK 1.2 FCS version of String.toUpperC=
      ase():

      -----
          scan: {
              for (firstLower =3D 0 ; firstLower < len ; firstLower++) {
                  char c =3D value[off+firstLower];
                  if (c !=3D Character.toUpperCase(c)) break scan;
              }
              return this;
          }
      -----

      The problem with this `optimization' will become apparent when you consider=
       a String containing __only__ the German
      eszett character (i.e. "=DF"). The proper fix for the problem would be to =
      replace the `if' statement with:

      -----
                  if (Character.isLowerCase(c)) break scan;
      -----

      =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
      =3D=3D=3D=3D=3D=3D=3D
      REVIEW NOTE 3/11/99 - User responded with more information

      // ----- BEGIN bugStringToUpperCase.java
      import java.awt.Container;
      import java.awt.FlowLayout;
      import java.util.Locale;

      import javax.swing.JDialog;
      import javax.swing.JTextField;

      public class bugStringToUpperCase
      {
        public static void main(String[] args)
        {
          JDialog d =3D new JDialog();
          Container cp =3D d.getContentPane();

          cp.setLayout(new FlowLayout());

          String s1 =3D "\u00DF"; // "=DF"
          String s2 =3D s1.toUpperCase(Locale.GERMAN);
          String s3 =3D "a\u00DF"; // "a=DF"
          String s4 =3D s3.toUpperCase(Locale.GERMAN);

          cp.add(new JTextField(s1));
          cp.add(new JTextField(s2));
          cp.add(new JTextField(s3));
          cp.add(new JTextField(s4));

          d.pack();

          d.setVisible(true);
        }
      }
      // ----- END bugStringToUpperCase.java

      Notice the different results of String.toUpperCase(Locale) when the=20
      String contains "=DF" instead of "a=DF". The problem is not with the eszet=
      t=20
      character itself (which is already special-cased in=20
      String.toUpperCase(Locale)), but with the scan block improperly doing=20
      the following check:

      -----
      =09=09if (c !=3D Character.toUpperCase(c)) break scan;
      -----

      (Review ID: 54909)
      ======================================================================

      Name: krT82822 Date: 09/30/99


      "\u00DF".toUpperCase( new Locale("tr", "TR") ) should return "SS" but it doesn't. It returns the original string instead.

      The code for String.toUpperCase() loops through the string to see if there are any characters that need to be changed. Turkish has a few special cases that are not handled in this loop so it is possible for the method to return without having changed any of the lower case letters.

      (Transferred from 4125644, norbert@eng, 2000-02-29)

            nlindenbsunw Norbert Lindenberg (Inactive)
            dblairsunw Dave Blair (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: