changeset 54452:7f01a85f2710

8219890: Calendar.getDisplayName() returns empty string for new Japanese Era on some locales Reviewed-by: lancea
author naoto
date Thu, 28 Feb 2019 14:03:04 -0800
parents e5b461681b88
children 393348e562c1
files src/java.base/share/classes/java/util/JapaneseImperialCalendar.java test/jdk/java/util/Calendar/JapaneseEraNameTest.java
diffstat 2 files changed, 8 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/util/JapaneseImperialCalendar.java	Thu Feb 28 22:11:46 2019 +0100
+++ b/src/java.base/share/classes/java/util/JapaneseImperialCalendar.java	Thu Feb 28 14:03:04 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -1022,9 +1022,11 @@
 
         String name = CalendarDataUtility.retrieveFieldValueName(getCalendarType(), field,
                                                                  fieldValue, style, locale);
-        // If the ERA value is null, then
+        // If the ERA value is null or empty, then
         // try to get its name or abbreviation from the Era instance.
-        if (name == null && field == ERA && fieldValue < eras.length) {
+        if ((name == null || name.isEmpty()) &&
+                field == ERA &&
+                fieldValue < eras.length) {
             Era era = eras[fieldValue];
             name = (style == SHORT) ? era.getAbbreviation() : era.getName();
         }
--- a/test/jdk/java/util/Calendar/JapaneseEraNameTest.java	Thu Feb 28 22:11:46 2019 +0100
+++ b/test/jdk/java/util/Calendar/JapaneseEraNameTest.java	Thu Feb 28 14:03:04 2019 -0800
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8202088 8207152 8217609
+ * @bug 8202088 8207152 8217609 8219890
  * @summary Test the localized Japanese new era name (May 1st. 2019-)
  *      is retrieved no matter CLDR provider contains the name or not.
  * @modules jdk.localedata
@@ -53,8 +53,10 @@
             // type,    locale,  name
             { LONG,     JAPAN,   "\u5143\u53f7" }, // NewEra
             { LONG,     US,      "NewEra" },
+            { LONG,     CHINA,   "NewEra" },
             { SHORT,    JAPAN,   "\u5143\u53f7" },
             { SHORT,    US,      "NewEra" },
+            { SHORT,    CHINA,   "N" },
         };
     }