diff --git a/src/share/classes/java/util/ArrayPrefixHelpers.java b/src/share/classes/java/util/ArrayPrefixHelpers.java index ef59ec7d47897ab3cfe181974dd9bbf07919322c..afa872c5855527b86196ef834b0728091bfc552c 100644 --- a/src/share/classes/java/util/ArrayPrefixHelpers.java +++ b/src/share/classes/java/util/ArrayPrefixHelpers.java @@ -128,6 +128,7 @@ class ArrayPrefixHelpers { this.lo = lo; this.hi = hi; } + @SuppressWarnings("unchecked") public final void compute() { final BinaryOperator fn; final T[] a; @@ -692,6 +693,4 @@ class ArrayPrefixHelpers { } } } - - -} \ No newline at end of file +} diff --git a/src/share/classes/java/util/Collections.java b/src/share/classes/java/util/Collections.java index 43ce42eeea6d32d316235261d534057ed7d4d60e..97555f567fa3f02b064a9a338275773026662833 100644 --- a/src/share/classes/java/util/Collections.java +++ b/src/share/classes/java/util/Collections.java @@ -1143,6 +1143,7 @@ public class Collections { public boolean removeIf(Predicate filter) { throw new UnsupportedOperationException(); } + @SuppressWarnings("unchecked") @Override public Spliterator spliterator() { return (Spliterator)c.spliterator(); @@ -1900,7 +1901,7 @@ public class Collections { private static final long serialVersionUID = -2239321462712562324L; - EmptyNavigableMap() { super(new TreeMap()); } + EmptyNavigableMap() { super(new TreeMap()); } @Override public NavigableSet navigableKeySet() @@ -1928,46 +1929,52 @@ public class Collections { public K ceilingKey(K key) { return nm.ceilingKey(key); } public K higherKey(K key) { return nm.higherKey(key); } + @SuppressWarnings("unchecked") public Entry lowerEntry(K key) { Entry lower = (Entry) nm.lowerEntry(key); return (null != lower) - ? new UnmodifiableEntrySet.UnmodifiableEntry(lower) + ? new UnmodifiableEntrySet.UnmodifiableEntry<>(lower) : null; } + @SuppressWarnings("unchecked") public Entry floorEntry(K key) { Entry floor = (Entry) nm.floorEntry(key); return (null != floor) - ? new UnmodifiableEntrySet.UnmodifiableEntry(floor) + ? new UnmodifiableEntrySet.UnmodifiableEntry<>(floor) : null; } + @SuppressWarnings("unchecked") public Entry ceilingEntry(K key) { Entry ceiling = (Entry) nm.ceilingEntry(key); return (null != ceiling) - ? new UnmodifiableEntrySet.UnmodifiableEntry(ceiling) + ? new UnmodifiableEntrySet.UnmodifiableEntry<>(ceiling) : null; } + @SuppressWarnings("unchecked") public Entry higherEntry(K key) { Entry higher = (Entry) nm.higherEntry(key); return (null != higher) - ? new UnmodifiableEntrySet.UnmodifiableEntry(higher) + ? new UnmodifiableEntrySet.UnmodifiableEntry<>(higher) : null; } + @SuppressWarnings("unchecked") public Entry firstEntry() { Entry first = (Entry) nm.firstEntry(); return (null != first) - ? new UnmodifiableEntrySet.UnmodifiableEntry(first) + ? new UnmodifiableEntrySet.UnmodifiableEntry<>(first) : null; } + @SuppressWarnings("unchecked") public Entry lastEntry() { Entry last = (Entry) nm.lastEntry(); return (null != last) - ? new UnmodifiableEntrySet.UnmodifiableEntry(last) + ? new UnmodifiableEntrySet.UnmodifiableEntry<>(last) : null; } @@ -2360,7 +2367,7 @@ public class Collections { } public NavigableSet tailSet(E fromElement) { synchronized (mutex) { - return new SynchronizedNavigableSet(ns.tailSet(fromElement, true), mutex); + return new SynchronizedNavigableSet<>(ns.tailSet(fromElement, true), mutex); } } @@ -2925,7 +2932,7 @@ public class Collections { public NavigableMap descendingMap() { synchronized (mutex) { return - new SynchronizedNavigableMap(nm.descendingMap(), mutex); + new SynchronizedNavigableMap<>(nm.descendingMap(), mutex); } } @@ -2935,13 +2942,13 @@ public class Collections { public NavigableSet navigableKeySet() { synchronized (mutex) { - return new SynchronizedNavigableSet(nm.navigableKeySet(), mutex); + return new SynchronizedNavigableSet<>(nm.navigableKeySet(), mutex); } } public NavigableSet descendingKeySet() { synchronized (mutex) { - return new SynchronizedNavigableSet(nm.descendingKeySet(), mutex); + return new SynchronizedNavigableSet<>(nm.descendingKeySet(), mutex); } } @@ -2959,27 +2966,27 @@ public class Collections { } public SortedMap tailMap(K fromKey) { synchronized (mutex) { - return new SynchronizedNavigableMap<>(nm.tailMap(fromKey, true),mutex); + return new SynchronizedNavigableMap<>(nm.tailMap(fromKey, true),mutex); } } public NavigableMap subMap(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive) { synchronized (mutex) { - return new SynchronizedNavigableMap( + return new SynchronizedNavigableMap<>( nm.subMap(fromKey, fromInclusive, toKey, toInclusive), mutex); } } public NavigableMap headMap(K toKey, boolean inclusive) { synchronized (mutex) { - return new SynchronizedNavigableMap( + return new SynchronizedNavigableMap<>( nm.headMap(toKey, inclusive), mutex); } } public NavigableMap tailMap(K fromKey, boolean inclusive) { synchronized (mutex) { - return new SynchronizedNavigableMap( + return new SynchronizedNavigableMap<>( nm.tailMap(fromKey, inclusive), mutex); } } @@ -4081,7 +4088,7 @@ public class Collections { public Entry lowerEntry(K key) { Entry lower = nm.lowerEntry(key); return (null != lower) - ? new CheckedMap.CheckedEntrySet.CheckedEntry(lower, valueType) + ? new CheckedMap.CheckedEntrySet.CheckedEntry<>(lower, valueType) : null; } @@ -4090,7 +4097,7 @@ public class Collections { public Entry floorEntry(K key) { Entry floor = nm.floorEntry(key); return (null != floor) - ? new CheckedMap.CheckedEntrySet.CheckedEntry(floor, valueType) + ? new CheckedMap.CheckedEntrySet.CheckedEntry<>(floor, valueType) : null; } @@ -4099,7 +4106,7 @@ public class Collections { public Entry ceilingEntry(K key) { Entry ceiling = nm.ceilingEntry(key); return (null != ceiling) - ? new CheckedMap.CheckedEntrySet.CheckedEntry(ceiling, valueType) + ? new CheckedMap.CheckedEntrySet.CheckedEntry<>(ceiling, valueType) : null; } @@ -4108,7 +4115,7 @@ public class Collections { public Entry higherEntry(K key) { Entry higher = nm.higherEntry(key); return (null != higher) - ? new CheckedMap.CheckedEntrySet.CheckedEntry(higher, valueType) + ? new CheckedMap.CheckedEntrySet.CheckedEntry<>(higher, valueType) : null; } @@ -4117,14 +4124,14 @@ public class Collections { public Entry firstEntry() { Entry first = nm.firstEntry(); return (null != first) - ? new CheckedMap.CheckedEntrySet.CheckedEntry(first, valueType) + ? new CheckedMap.CheckedEntrySet.CheckedEntry<>(first, valueType) : null; } public Entry lastEntry() { Entry last = nm.lastEntry(); return (null != last) - ? new CheckedMap.CheckedEntrySet.CheckedEntry(last, valueType) + ? new CheckedMap.CheckedEntrySet.CheckedEntry<>(last, valueType) : null; } @@ -4132,14 +4139,14 @@ public class Collections { Entry entry = nm.pollFirstEntry(); return (null == entry) ? null - : new CheckedMap.CheckedEntrySet.CheckedEntry(entry, valueType); + : new CheckedMap.CheckedEntrySet.CheckedEntry<>(entry, valueType); } public Entry pollLastEntry() { Entry entry = nm.pollLastEntry(); return (null == entry) ? null - : new CheckedMap.CheckedEntrySet.CheckedEntry(entry, valueType); + : new CheckedMap.CheckedEntrySet.CheckedEntry<>(entry, valueType); } public NavigableMap descendingMap() { diff --git a/src/share/classes/java/util/Comparator.java b/src/share/classes/java/util/Comparator.java index cd65ca4ea06e05e5314cd68f9ce2f2a9ae1d4f7e..55d5efb986678e4216d3c8088cb05cc71f1970f6 100644 --- a/src/share/classes/java/util/Comparator.java +++ b/src/share/classes/java/util/Comparator.java @@ -352,6 +352,7 @@ public interface Comparator { * @see Comparable * @since 1.8 */ + @SuppressWarnings("unchecked") public static > Comparator naturalOrder() { return (Comparator) Comparators.NaturalOrderComparator.INSTANCE; } @@ -374,7 +375,7 @@ public interface Comparator { * @since 1.8 */ public static Comparator nullsFirst(Comparator comparator) { - return new Comparators.NullComparator(true, comparator); + return new Comparators.NullComparator<>(true, comparator); } /** @@ -395,7 +396,7 @@ public interface Comparator { * @since 1.8 */ public static Comparator nullsLast(Comparator comparator) { - return new Comparators.NullComparator(false, comparator); + return new Comparators.NullComparator<>(false, comparator); } /** diff --git a/src/share/classes/java/util/Comparators.java b/src/share/classes/java/util/Comparators.java index a90383210854756b2589a16c9740abc3d6ee3cec..ee806798d7a79807217219afe714ac3344e846f9 100644 --- a/src/share/classes/java/util/Comparators.java +++ b/src/share/classes/java/util/Comparators.java @@ -87,12 +87,12 @@ class Comparators { @Override public Comparator thenComparing(Comparator other) { Objects.requireNonNull(other); - return new NullComparator(nullFirst, real == null ? other : real.thenComparing(other)); + return new NullComparator<>(nullFirst, real == null ? other : real.thenComparing(other)); } @Override public Comparator reversed() { - return new NullComparator(!nullFirst, real == null ? null : real.reversed()); + return new NullComparator<>(!nullFirst, real == null ? null : real.reversed()); } } } diff --git a/src/share/classes/java/util/Hashtable.java b/src/share/classes/java/util/Hashtable.java index a481719be0c97d1a95ab5c9da3c0a43902a68eb0..518bd17f5b784e90937bb2a82f1147f4581767b1 100644 --- a/src/share/classes/java/util/Hashtable.java +++ b/src/share/classes/java/util/Hashtable.java @@ -928,6 +928,7 @@ public class Hashtable return (null == result) ? defaultValue : result; } + @SuppressWarnings("unchecked") @Override public synchronized void forEach(BiConsumer action) { Objects.requireNonNull(action); // explicit check required in case @@ -947,6 +948,7 @@ public class Hashtable } } + @SuppressWarnings("unchecked") @Override public synchronized void replaceAll(BiFunction function) { Objects.requireNonNull(function); // explicit check required in case diff --git a/src/share/classes/java/util/IdentityHashMap.java b/src/share/classes/java/util/IdentityHashMap.java index 3064588c9013b3c9a7c7b67795fcd08df530d547..a4bdc4b9efdadec6b38e3f010788e30a2fde38ff 100644 --- a/src/share/classes/java/util/IdentityHashMap.java +++ b/src/share/classes/java/util/IdentityHashMap.java @@ -1339,6 +1339,7 @@ public class IdentityHashMap tab[i + 1] = value; } + @SuppressWarnings("unchecked") @Override public void forEach(BiConsumer action) { Objects.requireNonNull(action); @@ -1357,6 +1358,7 @@ public class IdentityHashMap } } + @SuppressWarnings("unchecked") @Override public void replaceAll(BiFunction function) { Objects.requireNonNull(function); diff --git a/src/share/classes/java/util/Vector.java b/src/share/classes/java/util/Vector.java index 18cc6f2f0aa14b8ae2d24c5600b3e579018e89bc..6146957dfd6f6cc8f62a32f1eba2d0919ffaf153 100644 --- a/src/share/classes/java/util/Vector.java +++ b/src/share/classes/java/util/Vector.java @@ -1164,12 +1164,13 @@ public class Vector if (i >= size) { return; } - final Object[] elementData = Vector.this.elementData; + @SuppressWarnings("unchecked") + final E[] elementData = (E[]) Vector.this.elementData; if (i >= elementData.length) { throw new ConcurrentModificationException(); } while (i != size && modCount == expectedModCount) { - action.accept((E) elementData[i++]); + action.accept(elementData[i++]); } // update once at end of iteration to reduce heap write traffic cursor = i; @@ -1311,8 +1312,8 @@ public class Vector modCount++; } - @Override @SuppressWarnings("unchecked") + @Override public synchronized void sort(Comparator c) { final int expectedModCount = modCount; Arrays.sort((E[]) elementData, 0, elementCount, c); diff --git a/src/share/classes/java/util/WeakHashMap.java b/src/share/classes/java/util/WeakHashMap.java index eb2e636e2ba3e78cdb286f79c94ec75c46f8e196..0299d29663884bfc2059b8ac36cf4ad273c0050d 100644 --- a/src/share/classes/java/util/WeakHashMap.java +++ b/src/share/classes/java/util/WeakHashMap.java @@ -1038,6 +1038,7 @@ public class WeakHashMap } } + @SuppressWarnings("unchecked") @Override public void forEach(BiConsumer action) { Objects.requireNonNull(action); @@ -1059,6 +1060,7 @@ public class WeakHashMap } } + @SuppressWarnings("unchecked") @Override public void replaceAll(BiFunction function) { Objects.requireNonNull(function);