--- old/src/java.base/share/classes/java/lang/module/ModuleFinder.java 2016-09-15 14:53:51.043859141 +0000 +++ new/src/java.base/share/classes/java/lang/module/ModuleFinder.java 2016-09-15 14:53:50.846891520 +0000 @@ -33,7 +33,6 @@ import java.security.AccessController; import java.security.Permission; import java.security.PrivilegedAction; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -333,7 +332,7 @@ * *

When locating modules then any exceptions or errors thrown by the * {@code find} or {@code findAll} methods of the underlying module finders - * will be propogated to the caller of the resulting module finder's + * will be propagated to the caller of the resulting module finder's * {@code find} or {@code findAll} methods.

* * @param finders @@ -342,8 +341,7 @@ * @return A {@code ModuleFinder} that composes a sequence of module finders */ static ModuleFinder compose(ModuleFinder... finders) { - final List finderList = Arrays.asList(finders); - finderList.forEach(Objects::requireNonNull); + final List finderList = List.of(finders); return new ModuleFinder() { private final Map nameToModule = new HashMap<>(); --- old/src/java.base/share/classes/java/net/CookieManager.java 2016-09-15 14:53:51.768739981 +0000 +++ new/src/java.base/share/classes/java/net/CookieManager.java 2016-09-15 14:53:51.637761512 +0000 @@ -201,10 +201,9 @@ throw new IllegalArgumentException("Argument is null"); } - Map> cookieMap = new java.util.HashMap<>(); // if there's no default CookieStore, no way for us to get any cookie if (cookieJar == null) - return Collections.unmodifiableMap(cookieMap); + return Map.of(); boolean secureLink = "https".equalsIgnoreCase(uri.getScheme()); List cookies = new java.util.ArrayList<>(); @@ -244,8 +243,7 @@ // apply sort rule (RFC 2965 sec. 3.3.4) List cookieHeader = sortByPath(cookies); - cookieMap.put("Cookie", cookieHeader); - return Collections.unmodifiableMap(cookieMap); + return Map.of("Cookie", cookieHeader); } public void --- old/src/java.base/share/classes/java/nio/file/FileTreeIterator.java 2016-09-15 14:53:52.135679661 +0000 +++ new/src/java.base/share/classes/java/nio/file/FileTreeIterator.java 2016-09-15 14:53:52.019698727 +0000 @@ -28,10 +28,9 @@ import java.io.Closeable; import java.io.IOException; import java.io.UncheckedIOException; -import java.util.Arrays; import java.util.Iterator; +import java.util.List; import java.util.NoSuchElementException; -import java.util.Objects; import java.nio.file.FileTreeWalker.Event; /** @@ -62,13 +61,15 @@ * @throws SecurityException * if the security manager denies access to the starting file * @throws NullPointerException - * if {@code start} or {@code options} is {@ocde null} or + * if {@code start} or {@code options} is {@code null} or * the options array contains a {@code null} element */ FileTreeIterator(Path start, int maxDepth, FileVisitOption... options) throws IOException { - this.walker = new FileTreeWalker(Arrays.asList(options), maxDepth); + // Since options may be a mutable array, use List.of to copy the array + // and prevent TOCTOU. + this.walker = new FileTreeWalker(List.of(options), maxDepth); this.next = walker.walk(start); assert next.type() == FileTreeWalker.EventType.ENTRY || next.type() == FileTreeWalker.EventType.START_DIRECTORY; --- old/src/java.base/share/classes/java/nio/file/FileTreeWalker.java 2016-09-15 14:53:52.492620985 +0000 +++ new/src/java.base/share/classes/java/nio/file/FileTreeWalker.java 2016-09-15 14:53:52.388638078 +0000 @@ -171,7 +171,7 @@ * if {@code options} contains an element that is not a * {@code FileVisitOption} * @throws NullPointerException - * if {@code options} is {@ocde null} or the options + * if {@code options} is {@code null} or the options * array contains a {@code null} element */ FileTreeWalker(Collection options, int maxDepth) { --- old/src/java.base/share/classes/java/security/Signature.java 2016-09-15 14:53:52.855561322 +0000 +++ new/src/java.base/share/classes/java/security/Signature.java 2016-09-15 14:53:52.748578909 +0000 @@ -37,7 +37,6 @@ import java.security.Provider.Service; import javax.crypto.Cipher; -import javax.crypto.CipherSpi; import javax.crypto.IllegalBlockSizeException; import javax.crypto.BadPaddingException; import javax.crypto.NoSuchPaddingException; @@ -180,15 +179,12 @@ private static final String RSA_CIPHER = "RSA/ECB/PKCS1Padding"; // all the services we need to lookup for compatibility with Cipher - private static final List rsaIds = Arrays.asList( - new ServiceId[] { - new ServiceId("Signature", "NONEwithRSA"), - new ServiceId("Cipher", "RSA/ECB/PKCS1Padding"), - new ServiceId("Cipher", "RSA/ECB"), - new ServiceId("Cipher", "RSA//PKCS1Padding"), - new ServiceId("Cipher", "RSA"), - } - ); + private static final List rsaIds = List.of( + new ServiceId("Signature", "NONEwithRSA"), + new ServiceId("Cipher", "RSA/ECB/PKCS1Padding"), + new ServiceId("Cipher", "RSA/ECB"), + new ServiceId("Cipher", "RSA//PKCS1Padding"), + new ServiceId("Cipher", "RSA")); /** * Returns a Signature object that implements the specified signature --- old/src/java.base/share/classes/java/time/Duration.java 2016-09-15 14:53:53.211502811 +0000 +++ new/src/java.base/share/classes/java/time/Duration.java 2016-09-15 14:53:53.059527793 +0000 @@ -88,8 +88,6 @@ import java.time.temporal.TemporalAmount; import java.time.temporal.TemporalUnit; import java.time.temporal.UnsupportedTemporalTypeException; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.regex.Matcher; @@ -578,8 +576,7 @@ * the simple initialization in Duration. */ private static class DurationUnits { - static final List UNITS = - Collections.unmodifiableList(Arrays.asList(SECONDS, NANOS)); + static final List UNITS = List.of(SECONDS, NANOS); } //----------------------------------------------------------------------- --- old/src/java.base/share/classes/java/time/Period.java 2016-09-15 14:53:53.604438217 +0000 +++ new/src/java.base/share/classes/java/time/Period.java 2016-09-15 14:53:53.448463858 +0000 @@ -83,8 +83,6 @@ import java.time.temporal.TemporalQueries; import java.time.temporal.TemporalUnit; import java.time.temporal.UnsupportedTemporalTypeException; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.regex.Matcher; @@ -152,8 +150,7 @@ /** * The set of supported units. */ - private static final List SUPPORTED_UNITS = - Collections.unmodifiableList(Arrays.asList(YEARS, MONTHS, DAYS)); + private static final List SUPPORTED_UNITS = List.of(YEARS, MONTHS, DAYS); /** * The number of years. --- old/src/java.base/share/classes/java/time/ZoneId.java 2016-09-15 14:53:53.967378555 +0000 +++ new/src/java.base/share/classes/java/time/ZoneId.java 2016-09-15 14:53:53.860396142 +0000 @@ -76,14 +76,14 @@ import java.time.zone.ZoneRules; import java.time.zone.ZoneRulesException; import java.time.zone.ZoneRulesProvider; -import java.util.Collections; -import java.util.HashMap; import java.util.Locale; import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.TimeZone; +import static java.util.Map.entry; + /** * A time-zone ID, such as {@code Europe/Paris}. *

@@ -220,39 +220,36 @@ * * The map is unmodifiable. */ - public static final Map SHORT_IDS; - static { - Map map = new HashMap<>(64); - map.put("ACT", "Australia/Darwin"); - map.put("AET", "Australia/Sydney"); - map.put("AGT", "America/Argentina/Buenos_Aires"); - map.put("ART", "Africa/Cairo"); - map.put("AST", "America/Anchorage"); - map.put("BET", "America/Sao_Paulo"); - map.put("BST", "Asia/Dhaka"); - map.put("CAT", "Africa/Harare"); - map.put("CNT", "America/St_Johns"); - map.put("CST", "America/Chicago"); - map.put("CTT", "Asia/Shanghai"); - map.put("EAT", "Africa/Addis_Ababa"); - map.put("ECT", "Europe/Paris"); - map.put("IET", "America/Indiana/Indianapolis"); - map.put("IST", "Asia/Kolkata"); - map.put("JST", "Asia/Tokyo"); - map.put("MIT", "Pacific/Apia"); - map.put("NET", "Asia/Yerevan"); - map.put("NST", "Pacific/Auckland"); - map.put("PLT", "Asia/Karachi"); - map.put("PNT", "America/Phoenix"); - map.put("PRT", "America/Puerto_Rico"); - map.put("PST", "America/Los_Angeles"); - map.put("SST", "Pacific/Guadalcanal"); - map.put("VST", "Asia/Ho_Chi_Minh"); - map.put("EST", "-05:00"); - map.put("MST", "-07:00"); - map.put("HST", "-10:00"); - SHORT_IDS = Collections.unmodifiableMap(map); - } + public static final Map SHORT_IDS = Map.ofEntries( + entry("ACT", "Australia/Darwin"), + entry("AET", "Australia/Sydney"), + entry("AGT", "America/Argentina/Buenos_Aires"), + entry("ART", "Africa/Cairo"), + entry("AST", "America/Anchorage"), + entry("BET", "America/Sao_Paulo"), + entry("BST", "Asia/Dhaka"), + entry("CAT", "Africa/Harare"), + entry("CNT", "America/St_Johns"), + entry("CST", "America/Chicago"), + entry("CTT", "Asia/Shanghai"), + entry("EAT", "Africa/Addis_Ababa"), + entry("ECT", "Europe/Paris"), + entry("IET", "America/Indiana/Indianapolis"), + entry("IST", "Asia/Kolkata"), + entry("JST", "Asia/Tokyo"), + entry("MIT", "Pacific/Apia"), + entry("NET", "Asia/Yerevan"), + entry("NST", "Pacific/Auckland"), + entry("PLT", "Asia/Karachi"), + entry("PNT", "America/Phoenix"), + entry("PRT", "America/Puerto_Rico"), + entry("PST", "America/Los_Angeles"), + entry("SST", "Pacific/Guadalcanal"), + entry("VST", "Asia/Ho_Chi_Minh"), + entry("EST", "-05:00"), + entry("MST", "-07:00"), + entry("HST", "-10:00") + ); /** * Serialization version. */ --- old/src/java.base/share/classes/java/time/chrono/ChronoPeriodImpl.java 2016-09-15 14:53:54.315321358 +0000 +++ new/src/java.base/share/classes/java/time/chrono/ChronoPeriodImpl.java 2016-09-15 14:53:54.213338123 +0000 @@ -77,8 +77,6 @@ import java.time.temporal.TemporalUnit; import java.time.temporal.UnsupportedTemporalTypeException; import java.time.temporal.ValueRange; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Objects; @@ -105,8 +103,7 @@ /** * The set of supported units. */ - private static final List SUPPORTED_UNITS = - Collections.unmodifiableList(Arrays.asList(YEARS, MONTHS, DAYS)); + private static final List SUPPORTED_UNITS = List.of(YEARS, MONTHS, DAYS); /** * The chronology. --- old/src/java.base/share/classes/java/time/chrono/HijrahChronology.java 2016-09-15 14:53:54.608273201 +0000 +++ new/src/java.base/share/classes/java/time/chrono/HijrahChronology.java 2016-09-15 14:53:54.503290459 +0000 @@ -59,10 +59,7 @@ import static java.time.temporal.ChronoField.EPOCH_DAY; -import java.io.File; -import java.io.FileInputStream; import java.io.FilePermission; -import java.io.IOException; import java.io.InputStream; import java.io.InvalidObjectException; import java.io.ObjectInputStream; @@ -83,7 +80,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.Properties; import sun.util.logging.PlatformLogger; @@ -512,7 +508,7 @@ @Override public List eras() { - return Arrays.asList(HijrahEra.values()); + return List.of(HijrahEra.values()); } //----------------------------------------------------------------------- --- old/src/java.base/share/classes/java/time/chrono/IsoChronology.java 2016-09-15 14:53:54.945217812 +0000 +++ new/src/java.base/share/classes/java/time/chrono/IsoChronology.java 2016-09-15 14:53:54.833236220 +0000 @@ -90,7 +90,6 @@ import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalField; import java.time.temporal.ValueRange; -import java.util.Arrays; import java.util.List; import java.util.Locale; import java.util.Map; @@ -492,7 +491,7 @@ @Override public List eras() { - return Arrays.asList(IsoEra.values()); + return List.of(IsoEra.values()); } //----------------------------------------------------------------------- --- old/src/java.base/share/classes/java/time/chrono/JapaneseChronology.java 2016-09-15 14:53:55.269164559 +0000 +++ new/src/java.base/share/classes/java/time/chrono/JapaneseChronology.java 2016-09-15 14:53:55.165181653 +0000 @@ -81,7 +81,6 @@ import java.time.temporal.TemporalField; import java.time.temporal.UnsupportedTemporalTypeException; import java.time.temporal.ValueRange; -import java.util.Arrays; import java.util.Calendar; import java.util.List; import java.util.Locale; @@ -379,7 +378,7 @@ @Override public List eras() { - return Arrays.asList(JapaneseEra.values()); + return List.of(JapaneseEra.values()); } JapaneseEra getCurrentEra() { --- old/src/java.base/share/classes/java/time/chrono/MinguoChronology.java 2016-09-15 14:53:55.574114430 +0000 +++ new/src/java.base/share/classes/java/time/chrono/MinguoChronology.java 2016-09-15 14:53:55.471131359 +0000 @@ -72,7 +72,6 @@ import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalField; import java.time.temporal.ValueRange; -import java.util.Arrays; import java.util.List; import java.util.Locale; import java.util.Map; @@ -306,7 +305,7 @@ @Override public List eras() { - return Arrays.asList(MinguoEra.values()); + return List.of(MinguoEra.values()); } //----------------------------------------------------------------------- --- old/src/java.base/share/classes/java/time/chrono/ThaiBuddhistChronology.java 2016-09-15 14:53:55.874065122 +0000 +++ new/src/java.base/share/classes/java/time/chrono/ThaiBuddhistChronology.java 2016-09-15 14:53:55.768082544 +0000 @@ -342,7 +342,7 @@ @Override public List eras() { - return Arrays.asList(ThaiBuddhistEra.values()); + return List.of(ThaiBuddhistEra.values()); } //----------------------------------------------------------------------- --- old/src/java.base/share/classes/java/time/format/DateTimeFormatter.java 2016-09-15 14:53:56.170016472 +0000 +++ new/src/java.base/share/classes/java/time/format/DateTimeFormatter.java 2016-09-15 14:53:56.066033565 +0000 @@ -1685,6 +1685,8 @@ public DateTimeFormatter withResolverFields(TemporalField... resolverFields) { Set fields = null; if (resolverFields != null) { + // An unmodifiable set wrapper is used instead of Set.of because resolverFields may + // contain null and Set.of is null-hostile. fields = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(resolverFields))); } if (Objects.equals(this.resolverFields, fields)) { --- old/src/java.base/share/classes/java/time/zone/ZoneOffsetTransition.java 2016-09-15 14:53:56.565951386 +0000 +++ new/src/java.base/share/classes/java/time/zone/ZoneOffsetTransition.java 2016-09-15 14:53:56.418975547 +0000 @@ -387,9 +387,9 @@ */ List getValidOffsets() { if (isGap()) { - return Collections.emptyList(); + return List.of(); } - return Arrays.asList(getOffsetBefore(), getOffsetAfter()); + return List.of(getOffsetBefore(), getOffsetAfter()); } //----------------------------------------------------------------------- --- old/src/java.base/share/classes/java/time/zone/ZoneRules.java 2016-09-15 14:53:56.959886628 +0000 +++ new/src/java.base/share/classes/java/time/zone/ZoneRules.java 2016-09-15 14:53:56.798913090 +0000 @@ -303,7 +303,6 @@ * Creates an instance of ZoneRules that has fixed zone rules. * * @param offset the offset this fixed zone rules is based on, not null - * @return the zone rules, not null * @see #isFixedOffset() */ private ZoneRules(ZoneOffset offset) { @@ -970,7 +969,7 @@ * @return an immutable list of transition rules, not null */ public List getTransitionRules() { - return Collections.unmodifiableList(Arrays.asList(lastRules)); + return List.of(lastRules); } /** --- old/src/java.base/share/classes/java/util/ResourceBundle.java 2016-09-15 14:53:57.354821706 +0000 +++ new/src/java.base/share/classes/java/util/ResourceBundle.java 2016-09-15 14:53:57.225842909 +0000 @@ -2491,34 +2491,29 @@ /** * The default format List, which contains the strings * "java.class" and "java.properties", in - * this order. This List is {@linkplain - * Collections#unmodifiableList(List) unmodifiable}. + * this order. This List is unmodifiable. * * @see #getFormats(String) */ - public static final List FORMAT_DEFAULT - = Collections.unmodifiableList(Arrays.asList("java.class", - "java.properties")); + public static final List FORMAT_DEFAULT + = List.of("java.class", "java.properties"); /** * The class-only format List containing - * "java.class". This List is {@linkplain - * Collections#unmodifiableList(List) unmodifiable}. + * "java.class". This List is unmodifiable. * * @see #getFormats(String) */ - public static final List FORMAT_CLASS - = Collections.unmodifiableList(Arrays.asList("java.class")); + public static final List FORMAT_CLASS = List.of("java.class"); /** * The properties-only format List containing - * "java.properties". This List is - * {@linkplain Collections#unmodifiableList(List) unmodifiable}. + * "java.properties". This List is unmodifiable. * * @see #getFormats(String) */ - public static final List FORMAT_PROPERTIES - = Collections.unmodifiableList(Arrays.asList("java.properties")); + public static final List FORMAT_PROPERTIES + = List.of("java.properties"); /** * The time-to-live constant for not caching loaded resource bundle --- old/src/java.base/share/classes/java/util/stream/Collectors.java 2016-09-15 14:53:57.700764838 +0000 +++ new/src/java.base/share/classes/java/util/stream/Collectors.java 2016-09-15 14:53:57.593782424 +0000 @@ -27,7 +27,6 @@ import java.util.AbstractMap; import java.util.AbstractSet; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; @@ -1720,12 +1719,12 @@ @Override public Set> entrySet() { - return new AbstractSet>() { + return new AbstractSet<>() { @Override public Iterator> iterator() { Map.Entry falseEntry = new SimpleImmutableEntry<>(false, forFalse); Map.Entry trueEntry = new SimpleImmutableEntry<>(true, forTrue); - return Arrays.asList(falseEntry, trueEntry).iterator(); + return List.of(falseEntry, trueEntry).iterator(); } @Override