src/share/classes/java/util/TimeZone.java

Print this page

        

@@ -41,16 +41,16 @@
 import java.io.Serializable;
 import java.lang.ref.SoftReference;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.concurrent.ConcurrentHashMap;
-import sun.misc.SharedSecrets;
 import sun.misc.JavaAWTAccess;
+import sun.misc.SharedSecrets;
 import sun.security.action.GetPropertyAction;
-import sun.util.locale.provider.TimeZoneNameUtility;
 import sun.util.calendar.ZoneInfo;
 import sun.util.calendar.ZoneInfoFile;
+import sun.util.locale.provider.TimeZoneNameUtility;
 
 /**
  * <code>TimeZone</code> represents a time zone offset, and also figures out daylight
  * savings.
  *

@@ -397,14 +397,16 @@
      */
     public String getDisplayName(boolean daylight, int style, Locale locale) {
         if (style != SHORT && style != LONG) {
             throw new IllegalArgumentException("Illegal style: " + style);
         }
-
         String id = getID();
-        String[] names = getDisplayNames(id, locale);
-        if (names == null) {
+        String name = TimeZoneNameUtility.retrieveDisplayName(id, daylight, style, locale);
+        if (name != null) {
+            return name;
+        }
+
             if (id.startsWith("GMT") && id.length() > 3) {
                 char sign = id.charAt(3);
                 if (sign == '+' || sign == '-') {
                     return id;
                 }

@@ -414,26 +416,22 @@
                 offset += getDSTSavings();
             }
             return ZoneInfoFile.toCustomID(offset);
         }
 
-        int index = daylight ? 3 : 1;
-        if (style == SHORT) {
-            index++;
-        }
-        return names[index];
-    }
-
     private static class DisplayNames {
         // Cache for managing display names per timezone per locale
         // The structure is:
         //   Map(key=id, value=SoftReference(Map(key=locale, value=displaynames)))
         private static final Map<String, SoftReference<Map<Locale, String[]>>> CACHE =
             new ConcurrentHashMap<>();
+
+        private DisplayNames() {
+        }
     }
 
-    private static final String[] getDisplayNames(String id, Locale locale) {
+    private static String[] getDisplayNames(String id, Locale locale) {
         Map<String, SoftReference<Map<Locale, String[]>>> displayNames = DisplayNames.CACHE;
 
         SoftReference<Map<Locale, String[]>> ref = displayNames.get(id);
         if (ref != null) {
             Map<Locale, String[]> perLocale = ref.get();

@@ -629,18 +627,18 @@
         // Don't clone here.
         return defaultZone;
     }
 
     private static synchronized TimeZone setDefaultZone() {
-        TimeZone tz = null;
+        TimeZone tz;
         // get the time zone ID from the system properties
         String zoneID = AccessController.doPrivileged(
                 new GetPropertyAction("user.timezone"));
 
         // if the time zone ID is not set (yet), perform the
         // platform to Java time zone ID mapping.
-        if (zoneID == null || zoneID.equals("")) {
+        if (zoneID == null || zoneID.isEmpty()) {
             String country = AccessController.doPrivileged(
                     new GetPropertyAction("user.country"));
             String javaHome = AccessController.doPrivileged(
                     new GetPropertyAction("java.home"));
             try {

@@ -668,12 +666,13 @@
             tz = getTimeZone(zoneID, true);
         }
         assert tz != null;
 
         final String id = zoneID;
-        AccessController.doPrivileged(new PrivilegedAction<Object>() {
-                public Object run() {
+        AccessController.doPrivileged(new PrivilegedAction<Void>() {
+            @Override
+                public Void run() {
                     System.setProperty("user.timezone", id);
                     return null;
                 }
             });