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

java.util.Locale.getDisplayName(null) works wrong

XMLWordPrintable



      Name: avC70361 Date: 09/24/98



        The java.util.Local.getDisplayName(null) works wrong for the locale with language, country and variant
      fields all empty. It throws NullPointerException but Locale.getDisplayName() spec states "If the language,
      country and variant fields are all empty, this function returns the empty string".

      Here is a test demonstrating the bug.
      ----------------GetDisplayNameTest.java---------------
      import java.util.Locale;

      public class GetDisplayNameTest {
        public static void main(String args[]) {
          Locale l = new Locale("", "", "");

          try {
            String name = l.getDisplayName(null);

            if (l.equals("")) {
              System.out.println("Passed");
            } else {
              System.out.println(
                "Failed. Name returned = " + name + ", expected name = \"\""
              );
            }
          } catch(NullPointerException e) {
            System.out.println("Failed. NullPointerException was thrown");
          }
        }
      }
      ---------------The test output-------------------------
      > java -version
      java version "1.2fcs"
      Classic VM (build JDK-1.2fcs-K, green threads, sunwjit)
      > java GetDisplayNameTest
      Failed. NullPointerException was thrown

      ======================================================================

            aliusunw Alan Liu (Inactive)
            ovlasov Oleksandr Vlasov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: