Merge "Port openJdk java.nio.file.attribute tests"
diff --git a/libart/src/main/java/java/lang/AndroidHardcodedSystemProperties.java b/libart/src/main/java/java/lang/AndroidHardcodedSystemProperties.java
index 13e9317..5a84c8e 100644
--- a/libart/src/main/java/java/lang/AndroidHardcodedSystemProperties.java
+++ b/libart/src/main/java/java/lang/AndroidHardcodedSystemProperties.java
@@ -106,6 +106,9 @@
// Hardcode default value for AVA. b/28174137
{ "com.sun.security.preserveOldDCEncoding", null },
+
+ // Hardcode default value for LogManager. b/28174137
+ { "java.util.logging.manager", null },
};
}
diff --git a/luni/src/test/java/libcore/java/lang/OldSystemTest.java b/luni/src/test/java/libcore/java/lang/OldSystemTest.java
index dc5741f..ad7151d 100644
--- a/luni/src/test/java/libcore/java/lang/OldSystemTest.java
+++ b/luni/src/test/java/libcore/java/lang/OldSystemTest.java
@@ -257,13 +257,9 @@
public void test_gc() {
Runtime rt = Runtime.getRuntime();
- Vector<StringBuffer> vec = new Vector<StringBuffer>();
- long beforeTest = rt.totalMemory() - rt.freeMemory();
- while (rt.totalMemory() - rt.freeMemory() < beforeTest * 2) {
- vec.add(new StringBuffer(1000));
- }
+ byte[] data = new byte[2 * 1024 * 1024];
long beforeGC = rt.totalMemory() - rt.freeMemory();
- vec = null;
+ data = null;
System.gc();
System.runFinalization();
long afterGC = rt.totalMemory() - rt.freeMemory();
diff --git a/luni/src/test/java/libcore/java/security/ProviderTest.java b/luni/src/test/java/libcore/java/security/ProviderTest.java
index ac64315..ffba98a 100644
--- a/luni/src/test/java/libcore/java/security/ProviderTest.java
+++ b/luni/src/test/java/libcore/java/security/ProviderTest.java
@@ -35,6 +35,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -45,6 +46,7 @@
import java.util.Objects;
import java.util.Set;
import java.util.TreeMap;
+import java.util.TreeSet;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
@@ -85,6 +87,20 @@
Set<Provider.Service> services = provider.getServices();
assertNotNull(services);
assertFalse(services.isEmpty());
+ if (LOG_DEBUG) {
+ Set<Provider.Service> originalServices = services;
+ services = new TreeSet<Provider.Service>(
+ new Comparator<Provider.Service>() {
+ public int compare(Provider.Service a, Provider.Service b) {
+ int typeCompare = a.getType().compareTo(b.getType());
+ if (typeCompare != 0) {
+ return typeCompare;
+ }
+ return a.getAlgorithm().compareTo(b.getAlgorithm());
+ }
+ });
+ services.addAll(originalServices);
+ }
for (Provider.Service service : services) {
String type = service.getType();
diff --git a/luni/src/test/java/libcore/java/util/DateTest.java b/luni/src/test/java/libcore/java/util/DateTest.java
index 6185f12..df86a38 100644
--- a/luni/src/test/java/libcore/java/util/DateTest.java
+++ b/luni/src/test/java/libcore/java/util/DateTest.java
@@ -81,49 +81,63 @@
}
/**
- * The minimum long value below which {@link Instant#toEpochMilli()} will
- * throw is not clearly documented. This test discovers if that minimum
- * value ever changes, and also checks that it is also the minimum Instant
- * (at a millisecond boundary) that can be converted to a Date.
+ * Test that conversion between Date and Instant works when the
+ * Instant is based on a millisecond value (and thus can be
+ * represented as a Date).
*/
- public void test_convertFromInstant_lowerBound() {
- // smallest millisecond Instant that can be converted to Date
- long minConvertible = -9223372036854775000L;
+ public void test_convertFromAndToInstant_milliseconds() {
+ check_convertFromAndToInstant_milliseconds(Long.MIN_VALUE);
+ check_convertFromAndToInstant_milliseconds(Long.MAX_VALUE);
- // show that this value is < 1 sec away from Long.MIN_VALUE
- assertEquals(Long.MIN_VALUE + 808, minConvertible);
-
- Instant inBound = Instant.ofEpochMilli(minConvertible);
- assertEquals(new Date(minConvertible), Date.from(inBound));
- assertEquals(minConvertible, inBound.toEpochMilli());
-
- Instant outOfBound = Instant.ofEpochMilli(minConvertible - 1);
- try {
- Date.from(outOfBound);
- fail();
- } catch (IllegalArgumentException expected) {
- assertEquals(ArithmeticException.class, expected.getCause().getClass());
- }
-
- try {
- outOfBound.toEpochMilli();
- fail();
- } catch (ArithmeticException expected) {
-
- }
+ check_convertFromAndToInstant_milliseconds(-1);
+ check_convertFromAndToInstant_milliseconds(0);
+ check_convertFromAndToInstant_milliseconds(123456789);
}
- public void test_convertFromInstant_upperBound() {
- Date.from(Instant.ofEpochMilli(Long.MAX_VALUE));
+ private static void check_convertFromAndToInstant_milliseconds(long millis) {
+ assertEquals(new Date(millis), Date.from(Instant.ofEpochMilli(millis)));
+ assertEquals(new Date(millis).toInstant(), Instant.ofEpochMilli(millis));
+ }
- Date.from(Instant.ofEpochSecond(Long.MAX_VALUE / 1000, 0));
- Date.from(Instant.ofEpochSecond(Long.MAX_VALUE / 1000, 999999999));
- Instant outOfBound = Instant.ofEpochSecond(Long.MAX_VALUE / 1000 + 1, 0);
+ /**
+ * Checks the minimum/maximum Instant values (based on seconds and
+ * nanos) that can be converted to a Date, i.e. that can be converted
+ * to milliseconds without overflowing a long. Note that the rounding
+ * is such that the lower bound is exactly Long.MIN_VALUE msec whereas
+ * the upper bound is 999,999 nanos beyond Long.MAX_VALUE msec. This
+ * makes some sense in that the magnitude of the upper/lower bound
+ * nanos differ only by 1, just like the magnitude of Long.MIN_VALUE /
+ * MAX_VALUE differ only by 1.
+ */
+ public void test_convertFromInstant_secondsAndNanos() {
+ // Documentation for how the below bounds relate to long boundaries for milliseconds
+ assertEquals(-808, Long.MIN_VALUE % 1000);
+ assertEquals(807, Long.MAX_VALUE % 1000);
+
+ // Lower bound
+ long minSecond = Long.MIN_VALUE / 1000;
+ Date.from(Instant.ofEpochSecond(minSecond));
+ // This instant exactly corresponds to Long.MIN_VALUE msec because
+ // Long.MIN_VALUE % 1000 == -808 == (-1000 + 192)
+ Date.from(Instant.ofEpochSecond(minSecond - 1, 192000000));
+ assertArithmeticOverflowDateFrom(Instant.ofEpochSecond(minSecond - 1, 0));
+ assertArithmeticOverflowDateFrom(Instant.ofEpochSecond(minSecond - 1, 191999999));
+
+ // Upper bound
+ long maxSecond = Long.MAX_VALUE / 1000;
+ Date.from(Instant.ofEpochSecond(maxSecond, 0));
+ // This Instant is 999,999 nanos beyond Long.MAX_VALUE msec because
+ // (Long.MAX_VALUE % 1000) == 807
+ Date.from(Instant.ofEpochSecond(maxSecond, 807999999));
+ assertArithmeticOverflowDateFrom(Instant.ofEpochSecond(maxSecond + 1, 0));
+ assertArithmeticOverflowDateFrom(Instant.ofEpochSecond(maxSecond, 808000000));
+ }
+
+ private static void assertArithmeticOverflowDateFrom(Instant instant) {
try {
- Date.from(outOfBound);
- fail();
+ Date.from(instant);
+ fail(instant + " should not have been convertible to Date");
} catch (IllegalArgumentException expected) {
- assertEquals(ArithmeticException.class, expected.getCause().getClass());
}
}
diff --git a/luni/src/test/java/libcore/javax/crypto/CipherTest.java b/luni/src/test/java/libcore/javax/crypto/CipherTest.java
index 02afcdd..2b3347c 100644
--- a/luni/src/test/java/libcore/javax/crypto/CipherTest.java
+++ b/luni/src/test/java/libcore/javax/crypto/CipherTest.java
@@ -4626,14 +4626,14 @@
if (s.getType().equals("Cipher")) {
if (s.getAlgorithm().startsWith("AES_128/")) {
Cipher c = Cipher.getInstance(s.getAlgorithm(), p);
- assertTrue(checkAES_keyConstraint(c, 128));
- assertFalse(checkAES_keyConstraint(c, 192));
- assertFalse(checkAES_keyConstraint(c, 256));
+ assertTrue(s.getAlgorithm(), checkAES_keyConstraint(c, 128));
+ assertFalse(s.getAlgorithm(), checkAES_keyConstraint(c, 192));
+ assertFalse(s.getAlgorithm(), checkAES_keyConstraint(c, 256));
} else if (s.getAlgorithm().startsWith("AES_256/")) {
Cipher c = Cipher.getInstance(s.getAlgorithm(), p);
- assertFalse(checkAES_keyConstraint(c, 128));
- assertFalse(checkAES_keyConstraint(c, 192));
- assertTrue(checkAES_keyConstraint(c, 256));
+ assertFalse(s.getAlgorithm(), checkAES_keyConstraint(c, 128));
+ assertFalse(s.getAlgorithm(), checkAES_keyConstraint(c, 192));
+ assertTrue(s.getAlgorithm(), checkAES_keyConstraint(c, 256));
}
}
}
diff --git a/ojluni/src/main/java/java/lang/String.java b/ojluni/src/main/java/java/lang/String.java
index 2d985ca..115890e 100644
--- a/ojluni/src/main/java/java/lang/String.java
+++ b/ojluni/src/main/java/java/lang/String.java
@@ -536,7 +536,7 @@
* object.
*/
public int length() {
- final boolean STRING_COMPRESSION_ENABLED = false;
+ final boolean STRING_COMPRESSION_ENABLED = true;
if (STRING_COMPRESSION_ENABLED) {
// For the compression purposes (save the characters as 8-bit if all characters
// are ASCII), the least significant bit of "count" is used as the compression flag.
diff --git a/ojluni/src/main/java/java/time/Instant.java b/ojluni/src/main/java/java/time/Instant.java
index 91a177c..9b9efa5 100644
--- a/ojluni/src/main/java/java/time/Instant.java
+++ b/ojluni/src/main/java/java/time/Instant.java
@@ -1229,8 +1229,14 @@
* @throws ArithmeticException if numeric overflow occurs
*/
public long toEpochMilli() {
- long millis = Math.multiplyExact(seconds, 1000);
- return millis + nanos / 1000_000;
+ if (seconds < 0 && nanos > 0) {
+ long millis = Math.multiplyExact(seconds+1, 1000);
+ long adjustment = nanos / 1000_000 - 1000;
+ return Math.addExact(millis, adjustment);
+ } else {
+ long millis = Math.multiplyExact(seconds, 1000);
+ return Math.addExact(millis, nanos / 1000_000);
+ }
}
//-----------------------------------------------------------------------
diff --git a/ojluni/src/main/java/java/time/chrono/JapaneseChronology.java b/ojluni/src/main/java/java/time/chrono/JapaneseChronology.java
index 15f7d84..29e503e 100644
--- a/ojluni/src/main/java/java/time/chrono/JapaneseChronology.java
+++ b/ojluni/src/main/java/java/time/chrono/JapaneseChronology.java
@@ -132,7 +132,7 @@
private static final Locale LOCALE = Locale.forLanguageTag("ja-JP-u-ca-japanese");
static Calendar createCalendar() {
- return Calendar.getJapanesImperialInstance(TimeZone.getDefault(), LOCALE);
+ return Calendar.getJapaneseImperialInstance(TimeZone.getDefault(), LOCALE);
}
/**
diff --git a/ojluni/src/main/java/java/util/Calendar.java b/ojluni/src/main/java/java/util/Calendar.java
index 6f8b9a9..8593403 100644
--- a/ojluni/src/main/java/java/util/Calendar.java
+++ b/ojluni/src/main/java/java/util/Calendar.java
@@ -1489,7 +1489,15 @@
setWeekDefinition(MONDAY, 4);
cal = gcal;
break;
- // Android-changed: removed support for "buddhist" and "japanese".
+// Android-changed BEGIN: removed support for "buddhist" and "japanese".
+// case "buddhist":
+// cal = new BuddhistCalendar(zone, locale);
+// cal.clear();
+// break;
+// case "japanese":
+// cal = new JapaneseImperialCalendar(zone, locale, true);
+// break;
+// Android-changed END: removed support for "buddhist" and "japanese".
default:
throw new IllegalArgumentException("unknown calendar type: " + type);
}
@@ -1586,6 +1594,7 @@
*/
protected Calendar(TimeZone zone, Locale aLocale)
{
+ // Android-added BEGIN: Allow aLocale == null
// http://b/16938922.
//
// TODO: This is for backwards compatibility only. Seems like a better idea to throw
@@ -1593,6 +1602,7 @@
if (aLocale == null) {
aLocale = Locale.getDefault();
}
+ // Android-added END: Allow aLocale == null
fields = new int[FIELD_COUNT];
isSet = new boolean[FIELD_COUNT];
stamp = new int[FIELD_COUNT];
@@ -1656,18 +1666,22 @@
return createCalendar(zone, aLocale);
}
+ // Android-added BEGIN: add getJapaneseImperialInstance()
/**
* Create a Japanese Imperial Calendar.
* @hide
*/
- public static Calendar getJapanesImperialInstance(TimeZone zone, Locale aLocale) {
+ public static Calendar getJapaneseImperialInstance(TimeZone zone, Locale aLocale) {
return new JapaneseImperialCalendar(zone, aLocale);
}
+ // Android-added END: add getJapaneseImperialInstance()
private static Calendar createCalendar(TimeZone zone,
Locale aLocale)
{
+ // Android-changed BEGIN: only support GregorianCalendar here
return new GregorianCalendar(zone, aLocale);
+ // Android-changed END: only support GregorianCalendar here
}
/**
@@ -1758,7 +1772,12 @@
public void setTimeInMillis(long millis) {
// If we don't need to recalculate the calendar field values,
// do nothing.
+// Android-changed BEGIN: Removed ZoneInfo support
if (time == millis && isTimeSet && areFieldsSet && areAllFieldsSet) {
+// if (time == millis && isTimeSet && areFieldsSet && areAllFieldsSet
+// && (zone instanceof ZoneInfo) && !((ZoneInfo)zone).isDirty()) {
+// Android-changed END: Removed ZoneInfo support
+
return;
}
time = millis;
@@ -2041,11 +2060,13 @@
* @since 1.6
*/
public String getDisplayName(int field, int style, Locale locale) {
- // Android-changed: Android has traditionally treated ALL_STYLES as SHORT, even though
+ // Android-changed BEGIN: Treat ALL_STYLES as SHORT
+ // Android has traditionally treated ALL_STYLES as SHORT, even though
// it's not documented to be a valid value for style.
if (style == ALL_STYLES) {
style = SHORT;
}
+ // Android-changed END: Treat ALL_STYLES as SHORT
if (!checkDisplayNameParams(field, style, SHORT, NARROW_FORMAT, locale,
ERA_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) {
return null;
@@ -2139,6 +2160,7 @@
ERA_MASK|MONTH_MASK|DAY_OF_WEEK_MASK|AM_PM_MASK)) {
return null;
}
+ // Android-added: Add complete() here to fix leniency, see http://b/35382060
complete();
String calendarType = getCalendarType();
@@ -2186,10 +2208,12 @@
baseStyle < minStyle || baseStyle > maxStyle) {
throw new IllegalArgumentException();
}
- // Android-changed: 3 is not a valid base style (1, 2 and 4 are, though), throw if used.
+ // Android-added BEGIN: Check for invalid baseStyle == 3
+ // 3 is not a valid base style (unlike 1, 2 and 4). Throw if used.
if (baseStyle == 3) {
throw new IllegalArgumentException();
}
+ // Android-added END: Check for invalid baseStyle == 3
if (locale == null) {
throw new NullPointerException();
}
diff --git a/ojluni/src/main/java/java/util/Formatter.java b/ojluni/src/main/java/java/util/Formatter.java
index ca1b990..43d5043 100644
--- a/ojluni/src/main/java/java/util/Formatter.java
+++ b/ojluni/src/main/java/java/util/Formatter.java
@@ -2710,6 +2710,7 @@
if (s != null) {
try {
// Android-changed: FormatSpecifierParser passes in correct String.
+ // index = Integer.parseInt(s.substring(0, s.length() - 1));
index = Integer.parseInt(s);
} catch (NumberFormatException x) {
assert(false);
@@ -2757,6 +2758,8 @@
precision = -1;
if (s != null) {
try {
+ // Android-changed: FormatSpecifierParser passes in correct String.
+ // precision = Integer.parseInt(s.substring(1));
precision = Integer.parseInt(s);
if (precision < 0)
throw new IllegalFormatPrecisionException(precision);
@@ -2789,7 +2792,7 @@
return c;
}
- // Android-changed: FormatSpecifierParser passes in the values instead of a Matcher.
+ // Android-changed BEGIN: FormatSpecifierParser passes in the values instead of a Matcher.
FormatSpecifier(String indexStr, String flagsStr, String widthStr,
String precisionStr, String tTStr, String convStr) {
int idx = 1;
@@ -2806,7 +2809,7 @@
}
conversion(convStr);
-
+ // Android-changed END: FormatSpecifierParser passes in the values instead of a Matcher.
if (dt)
checkDateTime();
else if (Conversion.isGeneral(c))
@@ -2998,6 +3001,7 @@
s = s.substring(0, precision);
if (f.contains(Flags.UPPERCASE)) {
// Android-changed: Use provided locale instead of default, if it is non-null.
+ // s = s.toUpperCase();
s = s.toUpperCase(l != null ? l : Locale.getDefault());
}
a.append(justify(s));
@@ -3369,12 +3373,13 @@
newW = adjustWidth(width - exp.length - 1, f, neg);
localizedMagnitude(sb, mant, f, newW, l);
- // Android-changed: Use localized exponent separator for %e.
+ // Android-changed BEGIN: Use localized exponent separator for %e.
Locale separatorLocale = (l != null) ? l : Locale.getDefault();
LocaleData localeData = LocaleData.get(separatorLocale);
sb.append(f.contains(Flags.UPPERCASE) ?
localeData.exponentSeparator.toUpperCase(separatorLocale) :
localeData.exponentSeparator.toLowerCase(separatorLocale));
+ // Android-changed END: Use localized exponent separator for %e.
Flags flags = f.dup().remove(Flags.GROUP);
char sign = exp[0];
@@ -4455,14 +4460,14 @@
grpSep = dfs.getGroupingSeparator();
DecimalFormat df = (DecimalFormat) NumberFormat.getIntegerInstance(l);
grpSize = df.getGroupingSize();
- // Android-changed: http://b/33245708 : Some locales have a group separator but
- // also patterns without groups. If we do not clear the group separator in these
- // cases a divide by zero is thrown when determining where to place the
- // separators.
+ // Android-changed BEGIN: http://b/33245708
+ // Some locales have a group separator but also patterns without groups.
+ // If we do not clear the group separator in these cases a divide by zero
+ // is thrown when determining where to place the separators.
if (!df.isGroupingUsed() || df.getGroupingSize() == 0) {
grpSep = '\0';
}
- // Android-changed: end http://b/33245708.
+ // Android-changed END: http://b/33245708.
}
}
diff --git a/ojluni/src/main/java/java/util/GregorianCalendar.java b/ojluni/src/main/java/java/util/GregorianCalendar.java
index 3d8a7c79..15c7652 100644
--- a/ojluni/src/main/java/java/util/GregorianCalendar.java
+++ b/ojluni/src/main/java/java/util/GregorianCalendar.java
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2014 The Android Open Source Project
- * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2013, 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
@@ -739,10 +739,12 @@
gdate = (BaseCalendar.Date) gcal.newCalendarDate(getZone());
}
+ // Android-added BEGIN
GregorianCalendar(long milliseconds) {
this();
setTimeInMillis(milliseconds);
}
+ // Android-added END
/////////////////
// Public methods
@@ -1078,8 +1080,7 @@
}
fd += delta; // fd is the expected fixed date after the calculation
-
- // Android changed: move time zone related calculation to separate method.
+ // Android-changed BEGIN: time zone related calculation via helper methods
// Calculate the time in the UTC time zone.
long utcTime = (fd - EPOCH_OFFSET) * ONE_DAY + timeOfDay;
@@ -1092,6 +1093,7 @@
// Update the time and recompute the fields.
setTimeInMillis(millis);
+ // Android-changed END: time zone related calculation via helper methods
}
}
@@ -2344,9 +2346,12 @@
}
if (tzMask != (ZONE_OFFSET_MASK|DST_OFFSET_MASK)) {
if (tz instanceof ZoneInfo) {
- // Android changed: libcore ZoneInfo uses different method to get offsets.
+ // Android changed BEGIN: use libcore.util.ZoneInfo
+ // The method name to get offsets differs from sun.util.calendar.ZoneInfo
+ // zoneOffset = ((ZoneInfo)tz).getOffsets(time, zoneOffsets);
ZoneInfo zoneInfo = (ZoneInfo) tz;
zoneOffset = zoneInfo.getOffsetsByUtcTime(time, zoneOffsets);
+ // Android-changed END: use libcore.util.ZoneInfo
} else {
zoneOffset = tz.getOffset(time);
zoneOffsets[0] = tz.getRawOffset();
@@ -2796,11 +2801,11 @@
// We use the TimeZone object, unless the user has explicitly set the ZONE_OFFSET
// or DST_OFFSET fields; then we use those fields.
TimeZone zone = getZone();
- // Android changed: move time zone related calculation to separate method.
-
+ // Android-changed BEGIN: time zone related calculation via helper methods
int tzMask = fieldMask & (ZONE_OFFSET_MASK|DST_OFFSET_MASK);
millis = adjustForZoneAndDaylightSavingsTime(tzMask, millis, zone);
+ // Android-changed END: time zone related calculation via helper methods
// Set this calendar's time in milliseconds
time = millis;
@@ -2823,6 +2828,7 @@
setFieldsNormalized(mask);
}
+ // Android-added BEGIN: helper methods for time zone related calculation
/**
* Calculates the time in milliseconds that this calendar represents using the UTC time,
* timezone information (specifically Daylight Savings Time (DST) rules, if any) and knowledge
@@ -2992,6 +2998,7 @@
}
return dstOffset;
}
+ // Android-added END: helper methods for time zone related calculation
/**
* Computes the fixed date under either the Gregorian or the
diff --git a/ojluni/src/main/java/java/util/Locale.java b/ojluni/src/main/java/java/util/Locale.java
index 9c75a32..45949c6 100644
--- a/ojluni/src/main/java/java/util/Locale.java
+++ b/ojluni/src/main/java/java/util/Locale.java
@@ -886,7 +886,8 @@
*/
public static Locale getDefault() {
// do not synchronize this method - see 4071298
- return defaultLocale;
+ // Android-changed: Add NoImagePreloadHolder to allow compile-time initialization.
+ return NoImagePreloadHolder.defaultLocale;
}
/**
@@ -972,6 +973,8 @@
}
private static Locale initDefault(Locale.Category category) {
+ // Android-changed: Add NoImagePreloadHolder to allow compile-time initialization.
+ final Locale defaultLocale = NoImagePreloadHolder.defaultLocale;
return getInstance(
System.getProperty(category.languageKey, defaultLocale.getLanguage()),
System.getProperty(category.scriptKey, defaultLocale.getScript()),
@@ -1012,7 +1015,8 @@
public static synchronized void setDefault(Locale newLocale) {
setDefault(Category.DISPLAY, newLocale);
setDefault(Category.FORMAT, newLocale);
- defaultLocale = newLocale;
+ // Android-changed: Add NoImagePreloadHolder to allow compile-time initialization.
+ NoImagePreloadHolder.defaultLocale = newLocale;
// Android-added: Keep ICU state in sync with java.util.
ICU.setDefaultLocale(newLocale.toLanguageTag());
}
@@ -2184,7 +2188,10 @@
*/
private transient volatile int hashCodeValue = 0;
- private volatile static Locale defaultLocale = initDefault();
+ // Android-changed: Add NoImagePreloadHolder to allow compile-time initialization.
+ private static class NoImagePreloadHolder {
+ public volatile static Locale defaultLocale = initDefault();
+ }
private volatile static Locale defaultDisplayLocale = null;
private volatile static Locale defaultFormatLocale = null;
diff --git a/ojluni/src/test/java/time/tck/java/time/TCKInstant.java b/ojluni/src/test/java/time/tck/java/time/TCKInstant.java
index 3d89db5..1b8fea7 100644
--- a/ojluni/src/test/java/time/tck/java/time/TCKInstant.java
+++ b/ojluni/src/test/java/time/tck/java/time/TCKInstant.java
@@ -1931,6 +1931,16 @@
Instant.ofEpochSecond(Long.MIN_VALUE / 1000 - 1).toEpochMilli();
}
+ @Test(expectedExceptions=ArithmeticException.class)
+ public void test_toEpochMillis_overflow() {
+ Instant.ofEpochSecond(Long.MAX_VALUE / 1000, 809_000_000).toEpochMilli();
+ }
+
+ @Test(expectedExceptions=ArithmeticException.class)
+ public void test_toEpochMillis_overflow2() {
+ Instant.ofEpochSecond(-9223372036854776L, 1).toEpochMilli();
+ }
+
//-----------------------------------------------------------------------
// compareTo()
//-----------------------------------------------------------------------
diff --git a/ojluni/src/test/java/time/test/java/time/TestInstant.java b/ojluni/src/test/java/time/test/java/time/TestInstant.java
index cf135a1..203bb57 100644
--- a/ojluni/src/test/java/time/test/java/time/TestInstant.java
+++ b/ojluni/src/test/java/time/test/java/time/TestInstant.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2015, 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
@@ -62,6 +62,8 @@
import java.time.Instant;
import org.testng.annotations.Test;
+import org.testng.annotations.DataProvider;
+import static org.testng.Assert.assertEquals;
/**
* Test Instant.
@@ -74,4 +76,24 @@
assertImmutable(Instant.class);
}
+ @DataProvider(name="sampleEpochMillis")
+ private Object[][] provider_sampleEpochMillis() {
+ return new Object[][] {
+ {"Long.MAX_VALUE", Long.MAX_VALUE},
+ {"Long.MAX_VALUE-1", Long.MAX_VALUE - 1},
+ {"1", 1L},
+ {"0", 0L},
+ {"-1", -1L},
+ {"Long.MIN_VALUE+1", Long.MIN_VALUE + 1},
+ {"Long.MIN_VALUE", Long.MIN_VALUE}
+ };
+ }
+
+ @Test(dataProvider="sampleEpochMillis")
+ public void test_epochMillis(String name, long millis) {
+ Instant t1 = Instant.ofEpochMilli(millis);
+ long m = t1.toEpochMilli();
+ assertEquals(millis, m, name);
+ }
+
}
diff --git a/ojluni/src/test/java/time/test/java/time/chrono/TestJapaneseChronoImpl.java b/ojluni/src/test/java/time/test/java/time/chrono/TestJapaneseChronoImpl.java
index 1ef3a5b..23ef184 100644
--- a/ojluni/src/test/java/time/test/java/time/chrono/TestJapaneseChronoImpl.java
+++ b/ojluni/src/test/java/time/test/java/time/chrono/TestJapaneseChronoImpl.java
@@ -99,7 +99,7 @@
assertEquals(locale.toString(), "ja_JP_#u-ca-japanese", "Unexpected locale");
// Android changed: Android doesn't return the Japanese Imperial Calendar from getInstance.
- Calendar cal = java.util.Calendar.getJapanesImperialInstance(TimeZone.getDefault(), locale);
+ Calendar cal = Calendar.getJapaneseImperialInstance(TimeZone.getDefault(), locale);
assertEquals(cal.getCalendarType(), "japanese", "Unexpected calendar type");
JapaneseDate jDate = JapaneseChronology.INSTANCE.date(isoStartDate);
diff --git a/ojluni/src/test/java/time/test/java/util/TestFormatter.java b/ojluni/src/test/java/time/test/java/util/TestFormatter.java
index afd5fc4..05cb2e7 100644
--- a/ojluni/src/test/java/time/test/java/util/TestFormatter.java
+++ b/ojluni/src/test/java/time/test/java/util/TestFormatter.java
@@ -111,7 +111,7 @@
TimeZone tz = TimeZone.getTimeZone(zdt.getZone());
Calendar cal;
if (calLocale.getLanguage().equals("ja")) {
- cal = Calendar.getJapanesImperialInstance(tz, calLocale);
+ cal = Calendar.getJapaneseImperialInstance(tz, calLocale);
} else {
cal = Calendar.getInstance(tz, calLocale);
}