diff options
-rw-r--r-- | ojluni/src/main/java/java/util/ArrayList.java | 7 | ||||
-rw-r--r-- | ojluni/src/main/java/java/util/Calendar.java | 14 | ||||
-rw-r--r-- | ojluni/src/main/java/java/util/Collections.java | 7 | ||||
-rw-r--r-- | ojluni/src/main/java/java/util/Currency.java | 5 | ||||
-rw-r--r-- | ojluni/src/main/java/java/util/Date.java | 2 | ||||
-rw-r--r-- | ojluni/src/main/java/java/util/Deque.java | 7 | ||||
-rw-r--r-- | ojluni/src/main/java/java/util/LinkedHashMap.java | 4 | ||||
-rw-r--r-- | ojluni/src/main/java/java/util/Locale.java | 26 | ||||
-rw-r--r-- | ojluni/src/main/java/java/util/Map.java | 10 | ||||
-rw-r--r-- | ojluni/src/main/java/java/util/Observable.java | 3 | ||||
-rw-r--r-- | ojluni/src/main/java/java/util/ServiceLoader.java | 12 | ||||
-rw-r--r-- | ojluni/src/main/java/java/util/TreeMap.java | 43 |
12 files changed, 76 insertions, 64 deletions
diff --git a/ojluni/src/main/java/java/util/ArrayList.java b/ojluni/src/main/java/java/util/ArrayList.java index f1895ef14c..dd465c9f5f 100644 --- a/ojluni/src/main/java/java/util/ArrayList.java +++ b/ojluni/src/main/java/java/util/ArrayList.java @@ -106,7 +106,11 @@ import java.util.function.UnaryOperator; /* * Android-changed: * - AOSP commit 3be987f0f18648b3c532c8b89d09505e18594241 - * Inline ArrayList rangeCheck&elementData methods + * Inline for improved performance: + * - checkForComodification + * - elementData() + * - rangeCheck() + * - rangeCheckForAdd() * - AOSP commit b10b2a3ab693cfd6156d06ffe4e00ce69b9c9194 * Fix ConcurrentModificationException in ArrayList iterators. * - AOSP commit a68b1a5ba82ef8cc19aafdce7d9c7f9631943f84 @@ -834,6 +838,7 @@ public class ArrayList<E> extends AbstractList<E> * An optimized version of AbstractList.Itr */ private class Itr implements Iterator<E> { + // Android-changed: Add "limit" field to detect end of iteration. // The "limit" of this iterator. This is the size of the list at the time the // iterator was created. Adding & removing elements will invalidate the iteration // anyway (and cause next() to throw) so saving this value will guarantee that the diff --git a/ojluni/src/main/java/java/util/Calendar.java b/ojluni/src/main/java/java/util/Calendar.java index 0da59e4431..20091230f6 100644 --- a/ojluni/src/main/java/java/util/Calendar.java +++ b/ojluni/src/main/java/java/util/Calendar.java @@ -1465,7 +1465,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca type = locale.getUnicodeLocaleType("ca"); } if (type == null) { - // Android-changed: don't switch to buddhist calendar based on locale. + // BEGIN Android-changed: don't switch to buddhist calendar based on locale. // See http://b/35138741 /* if (locale.getCountry() == "TH" @@ -1476,6 +1476,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca } */ type = "gregory"; + // END Android-changed: don't switch to buddhist calendar based on locale. } switch (type) { case "gregory": @@ -1773,9 +1774,9 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca // If we don't need to recalculate the calendar field values, // do nothing. // BEGIN Android-changed: Removed ZoneInfo support - if (time == millis && isTimeSet && areFieldsSet && areAllFieldsSet) { // if (time == millis && isTimeSet && areFieldsSet && areAllFieldsSet // && (zone instanceof ZoneInfo) && !((ZoneInfo)zone).isDirty()) { + if (time == millis && isTimeSet && areFieldsSet && areAllFieldsSet) { // END Android-changed: Removed ZoneInfo support return; @@ -2627,6 +2628,8 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca Set<String> set = new HashSet<>(3); set.add("gregory"); // Android-changed: removed "buddhist" and "japanese". + // set.add("buddhist"); + // set.add("japanese"); SET = Collections.unmodifiableSet(set); } private AvailableCalendarTypes() { @@ -3371,11 +3374,14 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca /* try to get the Locale data from the cache */ int[] data = cachedLocaleData.get(desiredLocale); if (data == null) { /* cache miss */ - // Android-changed: Use ICU4C to get week data. - LocaleData localeData = LocaleData.get(desiredLocale); data = new int[2]; + // BEGIN Android-changed: Use ICU4C to get week data. + // data[0] = CalendarDataUtility.retrieveFirstDayOfWeek(desiredLocale); + // data[1] = CalendarDataUtility.retrieveMinimalDaysInFirstWeek(desiredLocale); + LocaleData localeData = LocaleData.get(desiredLocale); data[0] = localeData.firstDayOfWeek.intValue(); data[1] = localeData.minimalDaysInFirstWeek.intValue(); + // END Android-changed: Use ICU4C to get week data. cachedLocaleData.putIfAbsent(desiredLocale, data); } firstDayOfWeek = data[0]; diff --git a/ojluni/src/main/java/java/util/Collections.java b/ojluni/src/main/java/java/util/Collections.java index c10a213b63..4818ee6faa 100644 --- a/ojluni/src/main/java/java/util/Collections.java +++ b/ojluni/src/main/java/java/util/Collections.java @@ -152,8 +152,8 @@ public class Collections { public static <T extends Comparable<? super T>> void sort(List<T> list) { // Android-changed: Call sort(list, null) here to be consistent // with that method's (Android-changed) behavior. - sort(list, null); // list.sort(null); + sort(list, null); } // Android-changed: Warn about Collections.sort() being built on top @@ -194,8 +194,8 @@ public class Collections { */ @SuppressWarnings({"unchecked", "rawtypes"}) public static <T> void sort(List<T> list, Comparator<? super T> c) { - // Android-changed: Introduced compatibility behavior for apps - // targeting API levels <= 25. + // BEGIN Android-changed: Compat behavior for apps targeting APIs <= 25. + // list.sort(c); int targetSdkVersion = VMRuntime.getRuntime().getTargetSdkVersion(); if (targetSdkVersion > 25) { list.sort(c); @@ -214,6 +214,7 @@ public class Collections { i.set((T) a[j]); } } + // END Android-changed: Compat behavior for apps targeting APIs <= 25. } diff --git a/ojluni/src/main/java/java/util/Currency.java b/ojluni/src/main/java/java/util/Currency.java index 9e76ec4a0f..88606aadca 100644 --- a/ojluni/src/main/java/java/util/Currency.java +++ b/ojluni/src/main/java/java/util/Currency.java @@ -32,6 +32,8 @@ import java.util.concurrent.ConcurrentMap; import libcore.icu.ICU; +// BEGIN Android-changed: Removed docs about superseding runtime currency data. +// Doing so via a properties file is not supported on Android. /** * Represents a currency. Currencies are identified by their ISO 4217 currency * codes. Visit the <a href="http://www.iso.org/iso/home/standards/currency_codes.htm"> @@ -44,8 +46,7 @@ import libcore.icu.ICU; * * @since 1.4 */ -// Android-changed: Superseding runtime currency data via a properties file is not -// supported on Android. +// END Android-changed: Removed docs about superseding runtime currency data. public final class Currency implements Serializable { private static final long serialVersionUID = -158308464356906721L; diff --git a/ojluni/src/main/java/java/util/Date.java b/ojluni/src/main/java/java/util/Date.java index 5a7c02fca1..f7a576d0da 100644 --- a/ojluni/src/main/java/java/util/Date.java +++ b/ojluni/src/main/java/java/util/Date.java @@ -522,7 +522,7 @@ public class Date if (prevc == '+') // plus means east of GMT n = -n; - // END Android-changed + // END Android-changed: Android specific time zone logic tzoffset = n; } else if (n >= 70) diff --git a/ojluni/src/main/java/java/util/Deque.java b/ojluni/src/main/java/java/util/Deque.java index 3520f535ce..dbd3d6f0e6 100644 --- a/ojluni/src/main/java/java/util/Deque.java +++ b/ojluni/src/main/java/java/util/Deque.java @@ -35,10 +35,7 @@ package java.util; -// BEGIN android-note -// removed link to collections framework docs -// END android-note - +// Android-changed: removed link to collections framework docs /** * A linear collection that supports element insertion and removal at * both ends. The name <i>deque</i> is short for "double ended queue" @@ -190,6 +187,8 @@ package java.util; * @since 1.6 * @param <E> the type of elements held in this deque */ +// Android-changed: fix framework docs link to "Collection#optional-restrictions" +// Several occurrences of the link have been fixed throughout. public interface Deque<E> extends Queue<E> { /** * Inserts the specified element at the front of this deque if it is diff --git a/ojluni/src/main/java/java/util/LinkedHashMap.java b/ojluni/src/main/java/java/util/LinkedHashMap.java index c1b0d236f1..3b5c3af4cf 100644 --- a/ojluni/src/main/java/java/util/LinkedHashMap.java +++ b/ojluni/src/main/java/java/util/LinkedHashMap.java @@ -488,11 +488,9 @@ public class LinkedHashMap<K,V> head = tail = null; } + // Android-added: eldest(), for internal use in LRU caches /** * Returns the eldest entry in the map, or {@code null} if the map is empty. - * - * Android-added. - * * @hide */ public Map.Entry<K, V> eldest() { diff --git a/ojluni/src/main/java/java/util/Locale.java b/ojluni/src/main/java/java/util/Locale.java index 03a2b9e339..437cc66964 100644 --- a/ojluni/src/main/java/java/util/Locale.java +++ b/ojluni/src/main/java/java/util/Locale.java @@ -59,6 +59,7 @@ import sun.util.locale.LocaleSyntaxException; import sun.util.locale.LocaleUtils; import sun.util.locale.ParseStatus; +// Android-added: documentation about ICU data & warning of default locale. /** * A <code>Locale</code> object represents a specific geographical, political, * or cultural region. An operation that requires a <code>Locale</code> to perform @@ -638,9 +639,7 @@ public final class Locale implements Cloneable, Serializable { */ static public final Locale CANADA_FRENCH = createConstant("fr", "CA"); - /** - * ISO 639-3 generic code for undetermined languages. - */ + // Android-added: (internal only): ISO 639-3 generic code for undetermined languages. private static final String UNDETERMINED_LANGUAGE = "und"; /** @@ -887,6 +886,7 @@ public final class Locale implements Cloneable, Serializable { public static Locale getDefault() { // do not synchronize this method - see 4071298 // Android-changed: Add NoImagePreloadHolder to allow compile-time initialization. + // return defaultLocale; return NoImagePreloadHolder.defaultLocale; } @@ -933,7 +933,7 @@ public final class Locale implements Cloneable, Serializable { return getDefault(); } - // BEGIN Android-changed: + // BEGIN Android-changed: initDefault changes // 1.) In initDefault(), user.locale gets priority // 2.) In both initDefault methods, use System.getProperty() instead // of legacy AccessController / GetPropertyAction security code. @@ -982,7 +982,7 @@ public final class Locale implements Cloneable, Serializable { System.getProperty(category.variantKey, defaultLocale.getVariant()), null); } - // END Android-changed + // END Android-changed: initDefault changes /** * Sets the default locale for this instance of the Java Virtual Machine. @@ -1016,6 +1016,7 @@ public final class Locale implements Cloneable, Serializable { setDefault(Category.DISPLAY, newLocale); setDefault(Category.FORMAT, newLocale); // Android-changed: Add NoImagePreloadHolder to allow compile-time initialization. + // defaultLocale = newLocale; NoImagePreloadHolder.defaultLocale = newLocale; // Android-added: Keep ICU state in sync with java.util. ICU.setDefaultLocale(newLocale.toLanguageTag()); @@ -1071,14 +1072,15 @@ public final class Locale implements Cloneable, Serializable { } } - // Android-changed: Removed references to LocaleServiceProvider. + // Android-changed: Removed documentation references to LocaleServiceProvider. /** * Returns an array of all installed locales. * * @return An array of installed locales. */ public static Locale[] getAvailableLocales() { - // Android-changed: Removed used of LocaleServiceProviderPool. Switched to use ICU. + // Android-changed: Switched to use ICU. + // return LocaleServiceProviderPool.getAllAvailableLocales(); return ICU.getAvailableLocales(); } @@ -1945,7 +1947,7 @@ public final class Locale implements Cloneable, Serializable { return true; } - // END Android-changed + // END Android-changed: Use ICU; documentation; added private helper methods. /** * Returns a name for the locale's variant code that is appropriate for display to the @@ -2119,7 +2121,7 @@ public final class Locale implements Cloneable, Serializable { } return buffer.toString(); } - // END Android-changed + // END Android-changed: Use ICU. /** * Overrides Cloneable. @@ -2332,7 +2334,7 @@ public final class Locale implements Cloneable, Serializable { String extStr = (String)fields.get("extensions", ""); baseLocale = BaseLocale.getInstance(convertOldISOCodes(language), script, country, variant); // Android-changed: Handle null for backwards compatible deserialization. http://b/26387905 - // was: if (extStr.length() > 0) { + // if (extStr.length() > 0) { if (extStr != null && extStr.length() > 0) { try { InternalLocaleBuilder bldr = new InternalLocaleBuilder(); @@ -2761,11 +2763,11 @@ public final class Locale implements Cloneable, Serializable { * @see #setExtension(char, String) */ public Builder removeUnicodeLocaleAttribute(String attribute) { - // BEGIN Android-added + // BEGIN Android-added: removeUnicodeLocaleAttribute(null) is documented to throw NPE if (attribute == null) { throw new NullPointerException("attribute == null"); } - // END Android-added + // END Android-added: removeUnicodeLocaleAttribute(null) is documented to throw NPE try { localeBuilder.removeUnicodeLocaleAttribute(attribute); diff --git a/ojluni/src/main/java/java/util/Map.java b/ojluni/src/main/java/java/util/Map.java index 74ba7012ce..2715b15076 100644 --- a/ojluni/src/main/java/java/util/Map.java +++ b/ojluni/src/main/java/java/util/Map.java @@ -30,11 +30,8 @@ import java.util.function.BiFunction; import java.util.function.Function; import java.io.Serializable; -// BEGIN android-note -// removed link to collections framework docs -// removed java 9 methods -// END android-note - +// Android-changed: removed docs for removed OpenJDK 9 Immutable Map static methods +// Android-changed: removed link to collections framework docs /** * An object that maps keys to values. A map cannot contain duplicate keys; * each key can map to at most one value. @@ -127,6 +124,7 @@ import java.io.Serializable; * @see Set * @since 1.2 */ +// Android-changed: fix doc links to Collection#optional-restrictions public interface Map<K, V> { // Query Operations @@ -1246,4 +1244,6 @@ public interface Map<K, V> { } return newValue; } + + // Android-removed: OpenJDK 9 Immutable Map static methods } diff --git a/ojluni/src/main/java/java/util/Observable.java b/ojluni/src/main/java/java/util/Observable.java index 1f21aaa7e9..be01640169 100644 --- a/ojluni/src/main/java/java/util/Observable.java +++ b/ojluni/src/main/java/java/util/Observable.java @@ -150,6 +150,9 @@ public class Observable { * wrongly notified when it doesn't care */ // Android-changed: Call out to hasChanged() to figure out if something changes. + // Upstream code avoids calling the nonfinal hasChanged() from the synchronized block, + // but that would break compatibility for apps that override that method. + // if (!changed) if (!hasChanged()) return; arrLocal = obs.toArray(); diff --git a/ojluni/src/main/java/java/util/ServiceLoader.java b/ojluni/src/main/java/java/util/ServiceLoader.java index e7ca50579d..44582e7fa6 100644 --- a/ojluni/src/main/java/java/util/ServiceLoader.java +++ b/ojluni/src/main/java/java/util/ServiceLoader.java @@ -193,7 +193,7 @@ public final class ServiceLoader<S> private final ClassLoader loader; // The access control context taken when the ServiceLoader is created - // Android-changed: do not use legacy security code + // Android-changed: do not use legacy security code. // private final AccessControlContext acc; // Cached providers, in instantiation order @@ -221,8 +221,8 @@ public final class ServiceLoader<S> private ServiceLoader(Class<S> svc, ClassLoader cl) { service = Objects.requireNonNull(svc, "Service interface cannot be null"); loader = (cl == null) ? ClassLoader.getSystemClassLoader() : cl; - // Android-changed: Do not use legacy security code (System.getSecurtiyManager() - // is always null). + // Android-changed: Do not use legacy security code. + // On Android, System.getSecurityManager() is always null. // acc = (System.getSecurityManager() != null) ? AccessController.getContext() : null; reload(); } @@ -588,8 +588,8 @@ public final class ServiceLoader<S> return ServiceLoader.load(service, prev); } - // BEGIN Android-changed: Add a method to instantiate a class from a system - // property (used in other parts of libcore). + // BEGIN Android-added: loadFromSystemProperty(), for internal use. + // Instantiates a class from a system property (used elsewhere in libcore). /** * Internal API to support built-in SPIs that check a system property first. * Returns an instance specified by a property with the class' binary name, or null if @@ -608,7 +608,7 @@ public final class ServiceLoader<S> throw new Error(e); } } - // END Android-changed + // END Android-added: loadFromSystemProperty(), for internal use. /** * Returns a string describing this service. diff --git a/ojluni/src/main/java/java/util/TreeMap.java b/ojluni/src/main/java/java/util/TreeMap.java index 0f3272b52f..65848e4d3d 100644 --- a/ojluni/src/main/java/java/util/TreeMap.java +++ b/ojluni/src/main/java/java/util/TreeMap.java @@ -1901,12 +1901,11 @@ public class TreeMap<K,V> } public NavigableMap<K,V> headMap(K toKey, boolean inclusive) { - /* BEGIN Android-changed - Fix for edge cases - if (!inRange(toKey, inclusive)) */ + // BEGIN Android-changed: Fix for edge cases + // if (!inRange(toKey, inclusive)) if (!inRange(toKey) && !(!toEnd && m.compare(toKey, hi) == 0 && !hiInclusive && !inclusive)) - // END Android-changed + // END Android-changed: Fix for edge cases throw new IllegalArgumentException("toKey out of range"); return new AscendingSubMap<>(m, fromStart, lo, loInclusive, @@ -1914,12 +1913,11 @@ public class TreeMap<K,V> } public NavigableMap<K,V> tailMap(K fromKey, boolean inclusive) { - /* BEGIN Android-changed - Fix for edge cases - if (!inRange(fromKey, inclusive)) */ + // BEGIN Android-changed: Fix for edge cases + // if (!inRange(fromKey, inclusive)) if (!inRange(fromKey) && !(!fromStart && m.compare(fromKey, lo) == 0 && !loInclusive && !inclusive)) - // END Android-changed + // END Android-changed: Fix for edge cases throw new IllegalArgumentException("fromKey out of range"); return new AscendingSubMap<>(m, false, fromKey, inclusive, @@ -1996,12 +1994,11 @@ public class TreeMap<K,V> } public NavigableMap<K,V> headMap(K toKey, boolean inclusive) { - /* BEGIN Android-changed - Fix for edge cases - if (!inRange(toKey, inclusive)) */ + // BEGIN Android-changed: Fix for edge cases + // if (!inRange(toKey, inclusive)) if (!inRange(toKey) && !(!fromStart && m.compare(toKey, lo) == 0 && !loInclusive && !inclusive)) - // END Android-changed + // END Android-changed: Fix for edge cases throw new IllegalArgumentException("toKey out of range"); return new DescendingSubMap<>(m, false, toKey, inclusive, @@ -2009,9 +2006,8 @@ public class TreeMap<K,V> } public NavigableMap<K,V> tailMap(K fromKey, boolean inclusive) { - /* BEGIN Android-changed - Fix for edge cases - if (!inRange(fromKey, inclusive)) */ + // BEGIN Android-changed: Fix for edge cases + // if (!inRange(fromKey, inclusive)) if (!inRange(fromKey) && !(!toEnd && m.compare(fromKey, hi) == 0 && !hiInclusive && !inclusive)) // END Android-changed @@ -2099,14 +2095,15 @@ public class TreeMap<K,V> * Node in the Tree. Doubles as a means to pass key-value pairs back to * user (see Map.Entry). */ - /* - * BEGIN Android-changed - * TreeMapEntry should not be renamed, specifically it must not - * be called "Entry" because that would hide Map.Entry and break - * source compatibility with earlier versions of Android. - * See LinkedHashMap$LinkedHashMapEntry for more details. - * END Android-changed - */ + // BEGIN Android-changed: Renamed Entry -> TreeMapEntry. + // Code references to "TreeMap.Entry" must mean Map.Entry + // + // This mirrors the corresponding rename of LinkedHashMap's + // Entry->LinkedHashMapEntry. + // + // This is for source compatibility with earlier versions of Android. + // Otherwise, it would hide Map.Entry. + // END Android-changed: Renamed Entry -> TreeMapEntry. static final class TreeMapEntry<K,V> implements Map.Entry<K,V> { K key; V value; |