Merge changes from topic "reiwa_o_cts" into oreo-cts-dev

* changes:
  DO NOT MERGE [CtsLibcoreOjTestCases] Old Android releases can optionally support the new Japanese era
  DO NOT MERGE New Japanese Era test changes with actual Reiwa name (part 2)
  DO NOT MERGE New Japanese Era test changes with actual Reiwa name
  DO NOT MERGE New Japanese Era test changes in ojluni with a placeholder name
diff --git a/luni/src/test/java/libcore/java/time/chrono/JapaneseChronologyTest.java b/luni/src/test/java/libcore/java/time/chrono/JapaneseChronologyTest.java
index 3c1f0cf..1f36b2c 100644
--- a/luni/src/test/java/libcore/java/time/chrono/JapaneseChronologyTest.java
+++ b/luni/src/test/java/libcore/java/time/chrono/JapaneseChronologyTest.java
@@ -16,6 +16,8 @@
 package libcore.java.time.chrono;
 
 import org.junit.Test;
+import android.icu.util.JapaneseCalendar;
+import java.util.List;
 import java.time.Instant;
 import java.time.LocalDate;
 import java.time.LocalTime;
@@ -23,6 +25,7 @@
 import java.time.ZoneOffset;
 import java.time.ZonedDateTime;
 import java.time.chrono.ChronoZonedDateTime;
+import java.time.chrono.Era;
 import java.time.chrono.JapaneseChronology;
 import java.time.chrono.JapaneseDate;
 import java.time.chrono.JapaneseEra;
@@ -110,4 +113,14 @@
         assertEquals(true, date.isSupported(ChronoField.YEAR));
         assertEquals(true, date.isSupported(ChronoField.YEAR_OF_ERA));
     }
+
+    @Test
+    public void test_eras_isLatestEraConsistency() {
+        List<Era> japaneseEras = JapaneseChronology.INSTANCE.eras();
+        boolean isHeiseiLatestInJavaTime =
+            japaneseEras.get(japaneseEras.size()-1).getValue() <= JapaneseEra.HEISEI.getValue();
+        boolean isHeiseiLatestInIcu = JapaneseCalendar.CURRENT_ERA == JapaneseCalendar.HEISEI;
+        assertEquals("java.time and ICU4J are not consistent in the latest japanese era",
+            isHeiseiLatestInJavaTime, isHeiseiLatestInIcu);
+    }
 }
diff --git a/ojluni/src/test/java/time/tck/java/time/chrono/TCKJapaneseChronology.java b/ojluni/src/test/java/time/tck/java/time/chrono/TCKJapaneseChronology.java
index 2bc1f4c..394d6d5 100644
--- a/ojluni/src/test/java/time/tck/java/time/chrono/TCKJapaneseChronology.java
+++ b/ojluni/src/test/java/time/tck/java/time/chrono/TCKJapaneseChronology.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -111,6 +111,24 @@
  */
 @Test
 public class TCKJapaneseChronology {
+
+    // Android-added: Add a static field to indicate if the device supports the new Japanese era.
+    /**
+     * Indicates if the device support newer Japenese Era than Heisei. Old Android releases can
+     * optionally support new Japanese Era, e.g. Reiwa, and Android test suites, e.g. CTS, can use
+     * this flag to alter the expected result. This flag can be placed in other classes, but
+     * TCKJapaneseChronology is picked arbitrarily.
+     */
+    public static final boolean IS_HEISEI_LATEST;
+    static {
+        List<Era> japaneseEras = JapaneseChronology.INSTANCE.eras();
+        IS_HEISEI_LATEST =
+            japaneseEras.get(japaneseEras.size()-1).getValue() <= JapaneseEra.HEISEI.getValue();
+    }
+
+
+    // Year differences from Gregorian years.
+    private static final int YDIFF_REIWA = 2018;
     private static final int YDIFF_HEISEI = 1988;
     private static final int YDIFF_MEIJI = 1867;
     private static final int YDIFF_SHOWA = 1925;
@@ -173,6 +191,10 @@
     @DataProvider(name="createByEra")
     Object[][] data_createByEra() {
         return new Object[][] {
+                // Android-changed: Old Android releases can optionally support the new Japanese era.
+                IS_HEISEI_LATEST
+                    ? new Object[] {JapaneseEra.HEISEI, 2020 - YDIFF_HEISEI, 2, 29, 60, LocalDate.of(2020, 2, 29)}
+                    : new Object[] {JapaneseEra.of(3), 2020 - YDIFF_REIWA, 2, 29, 60, LocalDate.of(2020, 2, 29)}, // NEWERA
                 {JapaneseEra.HEISEI, 1996 - YDIFF_HEISEI, 2, 29, 60, LocalDate.of(1996, 2, 29)},
                 {JapaneseEra.HEISEI, 2000 - YDIFF_HEISEI, 2, 29, 60, LocalDate.of(2000, 2, 29)},
                 {JapaneseEra.MEIJI, 1874 - YDIFF_MEIJI, 2, 28, 59, LocalDate.of(1874, 2, 28)},
@@ -365,8 +387,16 @@
     @DataProvider(name="prolepticYear")
     Object[][] data_prolepticYear() {
         return new Object[][] {
+                // Android-changed: Old Android releases can optionally support the new Japanese era.
+                IS_HEISEI_LATEST
+                    ? new Object[] {2, JapaneseEra.HEISEI, 1, 1 + YDIFF_HEISEI, false}
+                    : new Object[] {3, JapaneseEra.of(3), 1, 1 + YDIFF_REIWA, false},
+                IS_HEISEI_LATEST
+                    ? new Object[] {2, JapaneseEra.HEISEI, 102, 102 + YDIFF_HEISEI, false}
+                    : new Object[] {3, JapaneseEra.of(3), 102, 102 + YDIFF_REIWA, true},
+
                 {2, JapaneseEra.HEISEI, 1, 1 + YDIFF_HEISEI, false},
-                {2, JapaneseEra.HEISEI, 100, 100 + YDIFF_HEISEI, true},
+                {2, JapaneseEra.HEISEI, 4, 4 + YDIFF_HEISEI, true},
 
                 {-1, JapaneseEra.MEIJI, 9, 9 + YDIFF_MEIJI, true},
                 {-1, JapaneseEra.MEIJI, 10, 10 + YDIFF_MEIJI, false},
@@ -543,6 +573,16 @@
     //-----------------------------------------------------------------------
     @DataProvider(name="japaneseEras")
     Object[][] data_japanseseEras() {
+        // Android-changed: Old Android releases can optionally support the new Japanese era.
+        if (!IS_HEISEI_LATEST) {
+            return new Object[][] {
+                { JapaneseEra.MEIJI, -1, "Meiji"},
+                { JapaneseEra.TAISHO, 0, "Taisho"},
+                { JapaneseEra.SHOWA, 1, "Showa"},
+                { JapaneseEra.HEISEI, 2, "Heisei"},
+                { JapaneseEra.of(3), 3, "Reiwa"},
+            };
+        }
         return new Object[][] {
             { JapaneseEra.MEIJI, -1, "Meiji"},
             { JapaneseEra.TAISHO, 0, "Taisho"},
@@ -562,7 +602,7 @@
 
     @Test
     public void test_Japanese_badEras() {
-        int badEras[] = {-1000, -998, -997, -2, 3, 4, 1000};
+        int badEras[] = {-1000, -998, -997, -2, 4, 5, 1000};
         for (int badEra : badEras) {
             try {
                 Era era = JapaneseChronology.INSTANCE.eraOf(badEra);
@@ -683,6 +723,10 @@
             {JapaneseChronology.INSTANCE.date(1989,  1,  7), "Japanese Showa 64-01-07"},
             {JapaneseChronology.INSTANCE.date(1989,  1,  8), "Japanese Heisei 1-01-08"},
             {JapaneseChronology.INSTANCE.date(2012, 12,  6), "Japanese Heisei 24-12-06"},
+            // Android-changed: Old Android releases can optionally support the new Japanese era.
+            IS_HEISEI_LATEST
+                ? new Object[] {JapaneseChronology.INSTANCE.date(2020,  1,  6), "Japanese Heisei 32-01-06"}
+                : new Object[] {JapaneseChronology.INSTANCE.date(2020,  1,  6), "Japanese Reiwa 2-01-06"},
         };
     }
 
diff --git a/ojluni/src/test/java/time/tck/java/time/chrono/TCKJapaneseEra.java b/ojluni/src/test/java/time/tck/java/time/chrono/TCKJapaneseEra.java
index de83e1d..815517c 100644
--- a/ojluni/src/test/java/time/tck/java/time/chrono/TCKJapaneseEra.java
+++ b/ojluni/src/test/java/time/tck/java/time/chrono/TCKJapaneseEra.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -59,6 +59,7 @@
 import static java.time.temporal.ChronoField.ERA;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertTrue;
+import static tck.java.time.chrono.TCKJapaneseChronology.IS_HEISEI_LATEST;
 
 import java.time.chrono.Era;
 import java.time.chrono.JapaneseChronology;
@@ -76,6 +77,16 @@
 
     @DataProvider(name = "JapaneseEras")
     Object[][] data_of_eras() {
+        // Android-changed: Old Android releases can optionally support the new Japanese era.
+        if (!IS_HEISEI_LATEST) {
+            return new Object[][] {
+                        {JapaneseEra.of(3), "Reiwa", 3},
+                        {JapaneseEra.HEISEI, "Heisei", 2},
+                        {JapaneseEra.SHOWA, "Showa", 1},
+                        {JapaneseEra.TAISHO, "Taisho", 0},
+                        {JapaneseEra.MEIJI, "Meiji", -1},
+            };
+        }
         return new Object[][] {
                     {JapaneseEra.HEISEI, "Heisei", 2},
                     {JapaneseEra.SHOWA, "Showa", 1},
diff --git a/ojluni/src/test/java/time/test/java/time/chrono/TestJapaneseChronology.java b/ojluni/src/test/java/time/test/java/time/chrono/TestJapaneseChronology.java
index 3fbf853..337a8db 100644
--- a/ojluni/src/test/java/time/test/java/time/chrono/TestJapaneseChronology.java
+++ b/ojluni/src/test/java/time/test/java/time/chrono/TestJapaneseChronology.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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
@@ -28,12 +28,15 @@
 import java.time.*;
 import java.time.chrono.*;
 import java.time.temporal.*;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Locale;
 
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static tck.java.time.chrono.TCKJapaneseChronology.IS_HEISEI_LATEST;
 
 /**
  * Tests for the Japanese chronology
@@ -45,7 +48,8 @@
 
     @DataProvider(name="transitions")
     Object[][] transitionData() {
-        return new Object[][] {
+        // Android-changed: Old Android releases can optionally support the new Japanese era.
+        List<Object[]> data = Arrays.asList(new Object[][] {
             // Japanese era, yearOfEra, month, dayOfMonth, gregorianYear
             { JapaneseEra.MEIJI,      6,  1,  1, 1873 },
             // Meiji-Taisho transition isn't accurate. 1912-07-30 is the last day of Meiji
@@ -58,12 +62,20 @@
             { JapaneseEra.SHOWA,      1, 12, 25, 1926 },
             { JapaneseEra.SHOWA,     64,  1,  7, 1989 },
             { JapaneseEra.HEISEI,     1,  1,  8, 1989 },
-        };
+        });
+        if (IS_HEISEI_LATEST) {
+            data.addAll(Arrays.asList(new Object[][] {
+                { JapaneseEra.HEISEI,    31,  4, 30, 2019 },
+                { JapaneseEra.of(3),      1,  5,  1, 2019 },
+            }));
+        }
+        return data.toArray(new Object[data.size()][]);
     }
 
     @DataProvider(name="day_year_data")
     Object[][] dayYearData() {
-        return new Object[][] {
+        // Android-changed: Old Android releases can optionally support the new Japanese era.
+        List<Object[]> data = Arrays.asList(new Object[][] {
             // Japanese era, yearOfEra, dayOfYear, month, dayOfMonth
             { JapaneseEra.MEIJI,  45,  211,  7, 29 },
             { JapaneseEra.TAISHO,  1,    1,  7, 30 },
@@ -74,15 +86,25 @@
             { JapaneseEra.SHOWA,  64,    7,  1,  7 },
             { JapaneseEra.HEISEI,  1,    1,  1,  8 },
             { JapaneseEra.HEISEI,  2,    8,  1,  8 },
-        };
+        });
+        if (IS_HEISEI_LATEST) {
+            data.addAll(Arrays.asList(new Object[][] {
+                { JapaneseEra.HEISEI, 31,  120,  4, 30 },
+                { JapaneseEra.of(3),   1,    1,  5,  1 },
+            }));
+        }
+        return data.toArray(new Object[data.size()][]);
     }
 
     @DataProvider(name="range_data")
     Object[][] rangeData() {
+        // Android-changed: Old Android releases can optionally support the new Japanese era.
+        int maxEra = IS_HEISEI_LATEST ? 2 : 3;
+        int yearOfLatestEra = IS_HEISEI_LATEST ? 1989 : 2019;
         return new Object[][] {
             // field, minSmallest, minLargest, maxSmallest, maxLargest
-            { ChronoField.ERA,         -1, -1, 2, 2},
-            { ChronoField.YEAR_OF_ERA, 1, 1, 15, 999999999-1989 }, // depends on the current era
+            { ChronoField.ERA,         -1, -1, maxEra, maxEra},
+            { ChronoField.YEAR_OF_ERA, 1, 1, 15, 999999999-yearOfLatestEra}, // depends on the current era
             { ChronoField.DAY_OF_YEAR, 1, 1, 7, 366},
             { ChronoField.YEAR, 1873, 1873, 999999999, 999999999},
         };
@@ -105,7 +127,9 @@
             { JapaneseEra.SHOWA,     65,  1,  1 },
             { JapaneseEra.HEISEI,     1,  1,  7 },
             { JapaneseEra.HEISEI,     1,  2, 29 },
-            { JapaneseEra.HEISEI, Year.MAX_VALUE,  12, 31 },
+            { JapaneseEra.HEISEI,    31,  5,  1 },
+            { JapaneseEra.of(3),      1,  4, 30 },
+            { JapaneseEra.of(3), Year.MAX_VALUE,  12, 31 },
         };
     }
 
@@ -124,7 +148,10 @@
             { JapaneseEra.SHOWA,     65 },
             { JapaneseEra.HEISEI,    -1 },
             { JapaneseEra.HEISEI,     0 },
-            { JapaneseEra.HEISEI, Year.MAX_VALUE },
+            { JapaneseEra.HEISEI,    32 },
+            { JapaneseEra.of(3),     -1 },
+            { JapaneseEra.of(3),      0 },
+            { JapaneseEra.of(3), Year.MAX_VALUE },
         };
     }
 
@@ -141,6 +168,22 @@
             { JapaneseEra.SHOWA,  64,   8 },
             { JapaneseEra.HEISEI,  1, 360 },
             { JapaneseEra.HEISEI,  2, 366 },
+            { JapaneseEra.HEISEI, 31, 121 },
+            { JapaneseEra.of(3),   1, 246 },
+            { JapaneseEra.of(3),   2, 367 },
+        };
+    }
+
+    @DataProvider
+    Object[][] eraNameData() {
+        return new Object[][] {
+            // Japanese era, name, exception
+            { "Meiji",  JapaneseEra.MEIJI,      null },
+            { "Taisho", JapaneseEra.TAISHO,     null },
+            { "Showa",  JapaneseEra.SHOWA,      null },
+            { "Heisei", JapaneseEra.HEISEI,     null },
+            { "Reiwa", JapaneseEra.of(3),       null },
+            { "NewEra", null,                   IllegalArgumentException.class},
         };
     }
 
@@ -192,4 +235,13 @@
         JapaneseDate date = JAPANESE.dateYearDay(era, yearOfEra, dayOfYear);
         System.out.printf("No DateTimeException with era=%s, year=%d, dayOfYear=%d%n", era, yearOfEra, dayOfYear);
     }
+
+    @Test(dataProvider="eraNameData")
+    public void test_eraName(String eraName, JapaneseEra era, Class expectedEx) {
+        try {
+            assertEquals(JapaneseEra.valueOf(eraName), era);
+        } catch (Exception ex) {
+            assertTrue(expectedEx.isInstance(ex));
+        }
+    }
 }
diff --git a/ojluni/src/test/java/time/test/java/time/chrono/TestUmmAlQuraChronology.java b/ojluni/src/test/java/time/test/java/time/chrono/TestUmmAlQuraChronology.java
index ab61c71..e2f2b77 100644
--- a/ojluni/src/test/java/time/test/java/time/chrono/TestUmmAlQuraChronology.java
+++ b/ojluni/src/test/java/time/test/java/time/chrono/TestUmmAlQuraChronology.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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
@@ -33,6 +33,7 @@
 import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertTrue;
 import static org.testng.Assert.fail;
+import static tck.java.time.chrono.TCKJapaneseChronology.IS_HEISEI_LATEST;
 
 import java.time.DateTimeException;
 import java.time.DayOfWeek;
@@ -72,6 +73,7 @@
 /**
  * Tests for the Umm alQura chronology and data.
  * Note: The dates used for testing are just a sample of calendar data.
+ * @bug 8067800
  */
 @Test
 public class TestUmmAlQuraChronology {
@@ -548,6 +550,7 @@
         assertFalse(HijrahChronology.INSTANCE.isLeapYear(y), "Out of range leap year");
     }
 
+
     // Date samples to convert HijrahDate to LocalDate and vice versa
     @DataProvider(name="samples")
     Object[][] data_samples() {
@@ -773,8 +776,11 @@
             {HijrahDate.of(1350,5,15), "Japanese Showa 6-09-28"},
             {HijrahDate.of(1434,5,1), "Japanese Heisei 25-03-13"},
             {HijrahDate.of(1436,1,1), "Japanese Heisei 26-10-25"},
-            {HijrahDate.of(1500,6,12), "Japanese Heisei 89-05-05"},
-            {HijrahDate.of(1550,3,11), "Japanese Heisei 137-08-11"},
+            {HijrahDate.of(1440,8,25), "Japanese Heisei 31-04-30"},
+            // Android-changed: Old Android releases can optionally support the new Japanese era.
+            {HijrahDate.of(1440,8,26), IS_HEISEI_LATEST ? "Japanese Heisei 31-05-01" : "Japanese Reiwa 1-05-01"},
+            {HijrahDate.of(1500,6,12), IS_HEISEI_LATEST ? "Japanese Heisei 89-05-05" : "Japanese Reiwa 59-05-05"},
+            {HijrahDate.of(1550,3,11), IS_HEISEI_LATEST ? "Japanese Heisei 137-08-11" : "Japanese Reiwa 107-08-11"},
         };
     }
 
diff --git a/ojluni/src/test/java/time/test/java/time/format/TestNonIsoFormatter.java b/ojluni/src/test/java/time/test/java/time/format/TestNonIsoFormatter.java
index 6609f2c..df74377 100644
--- a/ojluni/src/test/java/time/test/java/time/format/TestNonIsoFormatter.java
+++ b/ojluni/src/test/java/time/test/java/time/format/TestNonIsoFormatter.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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
@@ -20,9 +20,17 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
+
+/*
+ *
+ * @test
+ * @bug 8206120
+ */
+
 package test.java.time.format;
 
 import static org.testng.Assert.assertEquals;
+import static tck.java.time.chrono.TCKJapaneseChronology.IS_HEISEI_LATEST;
 
 import java.time.LocalDate;
 import java.time.chrono.ChronoLocalDate;
@@ -37,6 +45,7 @@
 import java.time.format.DateTimeFormatterBuilder;
 import java.time.format.DateTimeParseException;
 import java.time.format.FormatStyle;
+import java.time.format.ResolverStyle;
 import java.time.format.TextStyle;
 import java.time.temporal.TemporalAccessor;
 import java.time.temporal.TemporalQueries;
@@ -134,6 +143,19 @@
         };
     }
 
+    @DataProvider(name="lenient_eraYear")
+    Object[][] lenientEraYear() {
+        return new Object[][] {
+            // Chronology, lenient era/year, strict era/year
+            { JAPANESE, "Meiji 123", "Heisei 2" },
+            // Android-changed: Eras names have been changed in CLDR data.
+            // { JAPANESE, "Showa 65", "Heisei 2" }
+            { JAPANESE, "Shōwa 65", "Heisei 2" },
+            // Android-changed: Old Android releases can optionally support the new Japanese era.
+            { JAPANESE, "Heisei 32", IS_HEISEI_LATEST ? "Heisei 32" : "Reiwa 2" },
+        };
+    }
+
     @Test(dataProvider="format_data")
     public void test_formatLocalizedDate(Chronology chrono, Locale formatLocale, Locale numberingLocale,
                                          ChronoLocalDate date, String expected) {
@@ -172,4 +194,15 @@
         Chronology cal = ta.query(TemporalQueries.chronology());
         assertEquals(cal, chrono);
     }
+
+    @Test(dataProvider="lenient_eraYear")
+    public void test_lenientEraYear(Chronology chrono, String lenient, String strict) {
+        String mdStr = "-01-01";
+        DateTimeFormatter dtf = new DateTimeFormatterBuilder()
+            .appendPattern("GGGG y-M-d")
+            .toFormatter()
+            .withChronology(chrono);
+        DateTimeFormatter dtfLenient = dtf.withResolverStyle(ResolverStyle.LENIENT);
+        assertEquals(LocalDate.parse(lenient+mdStr, dtfLenient), LocalDate.parse(strict+mdStr, dtf));
+    }
 }