< prev index next >

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

Print this page
rev 14210 : 8154231: Simplify access to System properties from JDK code
Reviewed-by: rriggs


 643     }
 644 
 645     /**
 646      * Returns the reference to the default TimeZone object. This
 647      * method doesn't create a clone.
 648      */
 649     static TimeZone getDefaultRef() {
 650         TimeZone defaultZone = defaultTimeZone;
 651         if (defaultZone == null) {
 652             // Need to initialize the default time zone.
 653             defaultZone = setDefaultZone();
 654             assert defaultZone != null;
 655         }
 656         // Don't clone here.
 657         return defaultZone;
 658     }
 659 
 660     private static synchronized TimeZone setDefaultZone() {
 661         TimeZone tz;
 662         // get the time zone ID from the system properties
 663         String zoneID = AccessController.doPrivileged(
 664                 new GetPropertyAction("user.timezone"));
 665 
 666         // if the time zone ID is not set (yet), perform the
 667         // platform to Java time zone ID mapping.
 668         if (zoneID == null || zoneID.isEmpty()) {
 669             String javaHome = AccessController.doPrivileged(
 670                     new GetPropertyAction("java.home"));
 671             try {
 672                 zoneID = getSystemTimeZoneID(javaHome);
 673                 if (zoneID == null) {
 674                     zoneID = GMT_ID;
 675                 }
 676             } catch (NullPointerException e) {
 677                 zoneID = GMT_ID;
 678             }
 679         }
 680 
 681         // Get the time zone for zoneID. But not fall back to
 682         // "GMT" here.
 683         tz = getTimeZone(zoneID, false);
 684 
 685         if (tz == null) {
 686             // If the given zone ID is unknown in Java, try to
 687             // get the GMT-offset-based time zone ID,
 688             // a.k.a. custom time zone ID (e.g., "GMT-08:00").
 689             String gmtOffsetID = getSystemGMTOffsetID();
 690             if (gmtOffsetID != null) {




 643     }
 644 
 645     /**
 646      * Returns the reference to the default TimeZone object. This
 647      * method doesn't create a clone.
 648      */
 649     static TimeZone getDefaultRef() {
 650         TimeZone defaultZone = defaultTimeZone;
 651         if (defaultZone == null) {
 652             // Need to initialize the default time zone.
 653             defaultZone = setDefaultZone();
 654             assert defaultZone != null;
 655         }
 656         // Don't clone here.
 657         return defaultZone;
 658     }
 659 
 660     private static synchronized TimeZone setDefaultZone() {
 661         TimeZone tz;
 662         // get the time zone ID from the system properties
 663         String zoneID = GetPropertyAction.getProperty("user.timezone");

 664 
 665         // if the time zone ID is not set (yet), perform the
 666         // platform to Java time zone ID mapping.
 667         if (zoneID == null || zoneID.isEmpty()) {
 668             String javaHome = GetPropertyAction.getProperty("java.home");

 669             try {
 670                 zoneID = getSystemTimeZoneID(javaHome);
 671                 if (zoneID == null) {
 672                     zoneID = GMT_ID;
 673                 }
 674             } catch (NullPointerException e) {
 675                 zoneID = GMT_ID;
 676             }
 677         }
 678 
 679         // Get the time zone for zoneID. But not fall back to
 680         // "GMT" here.
 681         tz = getTimeZone(zoneID, false);
 682 
 683         if (tz == null) {
 684             // If the given zone ID is unknown in Java, try to
 685             // get the GMT-offset-based time zone ID,
 686             // a.k.a. custom time zone ID (e.g., "GMT-08:00").
 687             String gmtOffsetID = getSystemGMTOffsetID();
 688             if (gmtOffsetID != null) {


< prev index next >