Snap for 4713750 from f586eedb674be4800611d4082c0503ffd34546a8 to pi-release

Change-Id: Ifd45a9a525883d98897e4ede451eac04f71ead5d
diff --git a/tzlookup_generator/src/main/java/com/android/libcore/timezone/tzlookup/Errors.java b/tzlookup_generator/src/main/java/com/android/libcore/timezone/tzlookup/Errors.java
index 2d6ede9..5b01fcb 100644
--- a/tzlookup_generator/src/main/java/com/android/libcore/timezone/tzlookup/Errors.java
+++ b/tzlookup_generator/src/main/java/com/android/libcore/timezone/tzlookup/Errors.java
@@ -37,12 +37,8 @@
     Errors() {
     }
 
-    boolean isEmpty() {
-        return messages.isEmpty();
-    }
-
-    void pushScope(String scope) {
-        scopes.add(scope);
+    void pushScope(String name) {
+        scopes.add(name);
     }
 
     String popScope() {
@@ -50,23 +46,17 @@
     }
 
     void addFatal(String msg) {
-        if (level < LEVEL_FATAL) {
-            level = LEVEL_FATAL;
-        }
+        level = Math.max(level, LEVEL_FATAL);
         add(msg);
     }
 
     void addError(String msg) {
-        if (level < LEVEL_ERROR) {
-            level = LEVEL_ERROR;
-        }
+        level = Math.max(level, LEVEL_ERROR);
         add(msg);
     }
 
     void addWarning(String msg) {
-        if (level < LEVEL_WARNING) {
-            level = LEVEL_WARNING;
-        }
+        level = Math.max(level, LEVEL_WARNING);
         add(msg);
     }
 
@@ -79,6 +69,10 @@
         return sb.toString();
     }
 
+    boolean isEmpty() {
+        return messages.isEmpty();
+    }
+
     boolean hasError() {
         return level >= LEVEL_ERROR;
     }
diff --git a/tzlookup_generator/src/main/java/com/android/libcore/timezone/tzlookup/TzLookupGenerator.java b/tzlookup_generator/src/main/java/com/android/libcore/timezone/tzlookup/TzLookupGenerator.java
index 212280c..703006e 100644
--- a/tzlookup_generator/src/main/java/com/android/libcore/timezone/tzlookup/TzLookupGenerator.java
+++ b/tzlookup_generator/src/main/java/com/android/libcore/timezone/tzlookup/TzLookupGenerator.java
@@ -240,7 +240,7 @@
 
             // Each Country needs a default time zone ID (but we can guess in some cases).
             String defaultTimeZoneId = determineCountryDefaultZoneId(countryIn, processingErrors);
-            if (processingErrors.hasError()) {
+            if (defaultTimeZoneId == null) {
                 // No point in continuing.
                 return null;
             }
@@ -254,15 +254,22 @@
             }
 
             // Validate the other zone IDs.
-            for (String countryTimeZoneId : countryTimeZoneIds) {
-                if (invalidTimeZoneId(countryTimeZoneId)) {
-                    processingErrors.addError("countryTimeZoneId=" + countryTimeZoneId
-                            + " is not a valid zone ID");
+            try {
+                processingErrors.pushScope("validate country zone ids");
+                boolean errors = false;
+                for (String countryTimeZoneId : countryTimeZoneIds) {
+                    if (invalidTimeZoneId(countryTimeZoneId)) {
+                        processingErrors.addError("countryTimeZoneId=" + countryTimeZoneId
+                                + " is not a valid zone ID");
+                        errors = true;
+                    }
                 }
-                if (processingErrors.hasError()) {
+                if (errors) {
                     // No point in continuing.
                     return null;
                 }
+            } finally {
+                processingErrors.popScope();
             }
 
             // Work out the hint for whether the country uses a zero offset from UTC.
@@ -294,8 +301,8 @@
             // Calculate countryZoneUsage.
             CountryZoneUsage countryZoneUsage =
                     calculateCountryZoneUsage(countryIn, processingErrors);
-            if (processingErrors.hasError()) {
-                // No point in continuing.
+            if (countryZoneUsage == null) {
+                // No point in continuing with this country.
                 return null;
             }
 
diff --git a/tzlookup_generator/src/main/java/com/android/libcore/timezone/tzlookup/zonetree/CountryZoneTree.java b/tzlookup_generator/src/main/java/com/android/libcore/timezone/tzlookup/zonetree/CountryZoneTree.java
index eae2053..23c2b0a 100644
--- a/tzlookup_generator/src/main/java/com/android/libcore/timezone/tzlookup/zonetree/CountryZoneTree.java
+++ b/tzlookup_generator/src/main/java/com/android/libcore/timezone/tzlookup/zonetree/CountryZoneTree.java
@@ -572,11 +572,11 @@
                         + "\nFrom=" + fromTimestamp + " to " + toTimestamp
                         + "\nPeriod count=" + node.getPeriodCount();
                 if (node.getPeriodCount() == 1) {
-                    ZoneInfo primaryZoneInfo = node.getPrimaryZoneInfo();
+                    ZoneInfo arbitraryZoneInfo = node.getZoneInfos().get(0);
                     int periodIndex =
-                            primaryZoneInfo.getZoneOffsetPeriodCount() - node.getPeriodOffset();
+                            arbitraryZoneInfo.getZoneOffsetPeriodCount() - node.getPeriodOffset();
                     ZoneOffsetPeriod zoneOffsetPeriod =
-                            primaryZoneInfo.getZoneOffsetPeriod(periodIndex);
+                            arbitraryZoneInfo.getZoneOffsetPeriod(periodIndex);
                     label += "\nrawOffset=" + durationString(zoneOffsetPeriod.getRawOffsetMillis());
                     label += "\ndstOffset=" + durationString(zoneOffsetPeriod.getDstOffsetMillis());
                     label += "\nname=" + zoneOffsetPeriod.getName();
diff --git a/tzlookup_generator/src/main/java/com/android/libcore/timezone/tzlookup/zonetree/ZoneInfo.java b/tzlookup_generator/src/main/java/com/android/libcore/timezone/tzlookup/zonetree/ZoneInfo.java
index 933ae8e..8960b8e 100644
--- a/tzlookup_generator/src/main/java/com/android/libcore/timezone/tzlookup/zonetree/ZoneInfo.java
+++ b/tzlookup_generator/src/main/java/com/android/libcore/timezone/tzlookup/zonetree/ZoneInfo.java
@@ -24,15 +24,15 @@
 import java.util.List;
 
 /**
- * Contains information about a tzdb defined time zone for a period.
+ * Contains information about a tzdb-defined time zone for a time period.
  */
 final class ZoneInfo {
 
     private static final int MIN_PRIORITY = 1;
 
     /**
-     * Priority can be used to establish dominance of one zone over another if they are otherwise
-     * identical for a period.
+     * Priority can be used to establish dominance of one zone info over another if they are
+     * otherwise identical for a zone offset period. Highest numerical priority "wins".
      */
     private final int priority;
 
@@ -51,7 +51,14 @@
         this.zoneId = zoneId;
     }
 
-    /** Creates a ZoneInfo using the supplied ICU data and metadata. */
+    /**
+     * Creates a ZoneInfo using the supplied ICU data and metadata.
+     *
+     * <p>The priority must be >= 1, and startInclusive is expected to be before endExclusive.
+     *
+     * <p>The returned {@link ZoneInfo} will be populated with {@link ZoneOffsetPeriod}s using
+     * the ICU time zone rules and names supplied in the specified period.
+     */
     public static ZoneInfo create(TimeZoneNames timeZoneNames, BasicTimeZone timeZone, int priority,
             Instant startInclusive, Instant endExclusive) {
         List<ZoneOffsetPeriod> zoneOffsetPeriods = new ArrayList<>();
@@ -70,7 +77,8 @@
 
     /**
      * Splits the final {@link ZoneOffsetPeriod} at the specified time and replaces it with two
-     * {@link ZoneOffsetPeriod}s instead.
+     * {@link ZoneOffsetPeriod}s instead, using the supplied ICU names information to help obtain
+     * the name for the later of the two periods.
      */
     public static void splitZoneOffsetPeriodAtTime(
             TimeZoneNames timeZoneNames, ZoneInfo zoneInfo, int index, Instant partitionInstant) {