8164669: Lazier initialization of java.time
authorredestad
Wed, 24 Aug 2016 13:54:17 +0200
changeset 40541 8850531a2beb
parent 40540 49fd4217ac48
child 40542 e7be26f852fa
8164669: Lazier initialization of java.time Reviewed-by: scolebourne, chegar, alanb
jdk/src/java.base/share/classes/java/time/Duration.java
jdk/src/java.base/share/classes/sun/util/calendar/ZoneInfo.java
--- a/jdk/src/java.base/share/classes/java/time/Duration.java	Wed Aug 24 13:32:00 2016 +0800
+++ b/jdk/src/java.base/share/classes/java/time/Duration.java	Wed Aug 24 13:54:17 2016 +0200
@@ -150,10 +150,12 @@
     /**
      * The pattern for parsing.
      */
-    private static final Pattern PATTERN =
+    private static class Lazy {
+        static final Pattern PATTERN =
             Pattern.compile("([-+]?)P(?:([-+]?[0-9]+)D)?" +
                     "(T(?:([-+]?[0-9]+)H)?(?:([-+]?[0-9]+)M)?(?:([-+]?[0-9]+)(?:[.,]([0-9]{0,9}))?S)?)?",
                     Pattern.CASE_INSENSITIVE);
+    }
 
     /**
      * The number of seconds in the duration.
@@ -387,7 +389,7 @@
      */
     public static Duration parse(CharSequence text) {
         Objects.requireNonNull(text, "text");
-        Matcher matcher = PATTERN.matcher(text);
+        Matcher matcher = Lazy.PATTERN.matcher(text);
         if (matcher.matches()) {
             // check for letter T but no time sections
             if (!charMatch(text, matcher.start(3), matcher.end(3), 'T')) {
--- a/jdk/src/java.base/share/classes/sun/util/calendar/ZoneInfo.java	Wed Aug 24 13:32:00 2016 +0800
+++ b/jdk/src/java.base/share/classes/sun/util/calendar/ZoneInfo.java	Wed Aug 24 13:54:17 2016 +0200
@@ -27,15 +27,8 @@
 
 import java.io.IOException;
 import java.io.ObjectInputStream;
-import java.lang.ref.SoftReference;
-import java.security.AccessController;
-import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Date;
-import java.util.List;
-import java.util.Locale;
 import java.util.Map;
-import java.util.Set;
 import java.util.SimpleTimeZone;
 import java.util.TimeZone;
 
@@ -80,8 +73,6 @@
     private static final long ABBR_MASK = 0xf00L;
     private static final int TRANSITION_NSHIFT = 12;
 
-    private static final CalendarSystem gcal = CalendarSystem.getGregorianCalendar();
-
     /**
      * The raw GMT offset in milliseconds between this zone and GMT.
      * Negative offsets are to the west of Greenwich.  To obtain local
@@ -379,6 +370,7 @@
             throw new IllegalArgumentException();
         }
 
+        Gregorian gcal = CalendarSystem.getGregorianCalendar();
         CalendarDate date = gcal.newCalendarDate(null);
         date.setDate(year, month + 1, day);
         if (gcal.validate(date) == false) {