changeset 19208:1e3d351eba80

8022412: Fixed warnings in java.util root, except for HashMap Reviewed-by: mduigou, darcy Contributed-by: marcus.lagergren@oracle.com
author lagergren
date Tue, 06 Aug 2013 12:56:18 -0700
parents 3448b0cb4077
children 6d3db5fe54e3
files jdk/src/share/classes/java/util/ArrayPrefixHelpers.java jdk/src/share/classes/java/util/Collections.java jdk/src/share/classes/java/util/Comparator.java jdk/src/share/classes/java/util/Comparators.java jdk/src/share/classes/java/util/Hashtable.java jdk/src/share/classes/java/util/IdentityHashMap.java jdk/src/share/classes/java/util/Vector.java jdk/src/share/classes/java/util/WeakHashMap.java
diffstat 8 files changed, 47 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/src/share/classes/java/util/ArrayPrefixHelpers.java	Tue Aug 06 13:25:04 2013 -0700
+++ b/jdk/src/share/classes/java/util/ArrayPrefixHelpers.java	Tue Aug 06 12:56:18 2013 -0700
@@ -128,6 +128,7 @@
             this.lo = lo; this.hi = hi;
         }
 
+        @SuppressWarnings("unchecked")
         public final void compute() {
             final BinaryOperator<T> fn;
             final T[] a;
@@ -692,6 +693,4 @@
             }
         }
     }
-
-
-}
\ No newline at end of file
+}
--- a/jdk/src/share/classes/java/util/Collections.java	Tue Aug 06 13:25:04 2013 -0700
+++ b/jdk/src/share/classes/java/util/Collections.java	Tue Aug 06 12:56:18 2013 -0700
@@ -1143,6 +1143,7 @@
         public boolean removeIf(Predicate<? super E> filter) {
             throw new UnsupportedOperationException();
         }
+        @SuppressWarnings("unchecked")
         @Override
         public Spliterator<E> spliterator() {
             return (Spliterator<E>)c.spliterator();
@@ -1900,7 +1901,7 @@
 
             private static final long serialVersionUID = -2239321462712562324L;
 
-            EmptyNavigableMap()                       { super(new TreeMap()); }
+            EmptyNavigableMap()                       { super(new TreeMap<K,V>()); }
 
             @Override
             public NavigableSet<K> navigableKeySet()
@@ -1928,46 +1929,52 @@
         public K ceilingKey(K key)               { return nm.ceilingKey(key); }
         public K higherKey(K key)                 { return nm.higherKey(key); }
 
+        @SuppressWarnings("unchecked")
         public Entry<K, V> lowerEntry(K key) {
             Entry<K,V> lower = (Entry<K, V>) nm.lowerEntry(key);
             return (null != lower)
-                ? new UnmodifiableEntrySet.UnmodifiableEntry(lower)
+                ? new UnmodifiableEntrySet.UnmodifiableEntry<>(lower)
                 : null;
         }
 
+        @SuppressWarnings("unchecked")
         public Entry<K, V> floorEntry(K key) {
             Entry<K,V> floor = (Entry<K, V>) nm.floorEntry(key);
             return (null != floor)
-                ? new UnmodifiableEntrySet.UnmodifiableEntry(floor)
+                ? new UnmodifiableEntrySet.UnmodifiableEntry<>(floor)
                 : null;
         }
 
+        @SuppressWarnings("unchecked")
         public Entry<K, V> ceilingEntry(K key) {
             Entry<K,V> ceiling = (Entry<K, V>) nm.ceilingEntry(key);
             return (null != ceiling)
-                ? new UnmodifiableEntrySet.UnmodifiableEntry(ceiling)
+                ? new UnmodifiableEntrySet.UnmodifiableEntry<>(ceiling)
                 : null;
         }
 
 
+        @SuppressWarnings("unchecked")
         public Entry<K, V> higherEntry(K key) {
             Entry<K,V> higher = (Entry<K, V>) nm.higherEntry(key);
             return (null != higher)
-                ? new UnmodifiableEntrySet.UnmodifiableEntry(higher)
+                ? new UnmodifiableEntrySet.UnmodifiableEntry<>(higher)
                 : null;
         }
 
+        @SuppressWarnings("unchecked")
         public Entry<K, V> firstEntry() {
             Entry<K,V> first = (Entry<K, V>) nm.firstEntry();
             return (null != first)
-                ? new UnmodifiableEntrySet.UnmodifiableEntry(first)
+                ? new UnmodifiableEntrySet.UnmodifiableEntry<>(first)
                 : null;
         }
 
+        @SuppressWarnings("unchecked")
         public Entry<K, V> lastEntry() {
             Entry<K,V> last = (Entry<K, V>) nm.lastEntry();
             return (null != last)
-                ? new UnmodifiableEntrySet.UnmodifiableEntry(last)
+                ? new UnmodifiableEntrySet.UnmodifiableEntry<>(last)
                 : null;
         }
 
@@ -2360,7 +2367,7 @@
         }
         public NavigableSet<E> 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 NavigableMap<K, V> descendingMap() {
             synchronized (mutex) {
                 return
-                    new SynchronizedNavigableMap(nm.descendingMap(), mutex);
+                    new SynchronizedNavigableMap<>(nm.descendingMap(), mutex);
             }
         }
 
@@ -2935,13 +2942,13 @@
 
         public NavigableSet<K> navigableKeySet() {
             synchronized (mutex) {
-                return new SynchronizedNavigableSet(nm.navigableKeySet(), mutex);
+                return new SynchronizedNavigableSet<>(nm.navigableKeySet(), mutex);
             }
         }
 
         public NavigableSet<K> descendingKeySet() {
             synchronized (mutex) {
-                return new SynchronizedNavigableSet(nm.descendingKeySet(), mutex);
+                return new SynchronizedNavigableSet<>(nm.descendingKeySet(), mutex);
             }
         }
 
@@ -2959,27 +2966,27 @@
         }
         public SortedMap<K,V> tailMap(K fromKey) {
             synchronized (mutex) {
-               return new SynchronizedNavigableMap<>(nm.tailMap(fromKey, true),mutex);
+        return new SynchronizedNavigableMap<>(nm.tailMap(fromKey, true),mutex);
             }
         }
 
         public NavigableMap<K, V> 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<K, V> headMap(K toKey, boolean inclusive) {
             synchronized (mutex) {
-                return new SynchronizedNavigableMap(
+                return new SynchronizedNavigableMap<>(
                         nm.headMap(toKey, inclusive), mutex);
             }
         }
 
         public NavigableMap<K, V> tailMap(K fromKey, boolean inclusive) {
             synchronized (mutex) {
-                return new SynchronizedNavigableMap(
+                return new SynchronizedNavigableMap<>(
                     nm.tailMap(fromKey, inclusive), mutex);
             }
         }
@@ -4081,7 +4088,7 @@
         public Entry<K, V> lowerEntry(K key) {
             Entry<K,V> 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 Entry<K, V> floorEntry(K key) {
             Entry<K,V> 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 Entry<K, V> ceilingEntry(K key) {
             Entry<K,V> 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 Entry<K, V> higherEntry(K key) {
             Entry<K,V> 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 Entry<K, V> firstEntry() {
             Entry<K,V> first = nm.firstEntry();
             return (null != first)
-                ? new CheckedMap.CheckedEntrySet.CheckedEntry(first, valueType)
+                ? new CheckedMap.CheckedEntrySet.CheckedEntry<>(first, valueType)
                 : null;
         }
 
         public Entry<K, V> lastEntry() {
             Entry<K,V> last = nm.lastEntry();
             return (null != last)
-                ? new CheckedMap.CheckedEntrySet.CheckedEntry(last, valueType)
+                ? new CheckedMap.CheckedEntrySet.CheckedEntry<>(last, valueType)
                 : null;
         }
 
@@ -4132,14 +4139,14 @@
             Entry<K,V> entry = nm.pollFirstEntry();
             return (null == entry)
                 ? null
-                : new CheckedMap.CheckedEntrySet.CheckedEntry(entry, valueType);
+                : new CheckedMap.CheckedEntrySet.CheckedEntry<>(entry, valueType);
         }
 
         public Entry<K, V> pollLastEntry() {
             Entry<K,V> entry = nm.pollLastEntry();
             return (null == entry)
                 ? null
-                : new CheckedMap.CheckedEntrySet.CheckedEntry(entry, valueType);
+                : new CheckedMap.CheckedEntrySet.CheckedEntry<>(entry, valueType);
         }
 
         public NavigableMap<K, V> descendingMap() {
--- a/jdk/src/share/classes/java/util/Comparator.java	Tue Aug 06 13:25:04 2013 -0700
+++ b/jdk/src/share/classes/java/util/Comparator.java	Tue Aug 06 12:56:18 2013 -0700
@@ -352,6 +352,7 @@
      * @see Comparable
      * @since 1.8
      */
+    @SuppressWarnings("unchecked")
     public static <T extends Comparable<? super T>> Comparator<T> naturalOrder() {
         return (Comparator<T>) Comparators.NaturalOrderComparator.INSTANCE;
     }
@@ -374,7 +375,7 @@
      * @since 1.8
      */
     public static <T> Comparator<T> nullsFirst(Comparator<? super T> comparator) {
-        return new Comparators.NullComparator(true, comparator);
+        return new Comparators.NullComparator<>(true, comparator);
     }
 
     /**
@@ -395,7 +396,7 @@
      * @since 1.8
      */
     public static <T> Comparator<T> nullsLast(Comparator<? super T> comparator) {
-        return new Comparators.NullComparator(false, comparator);
+        return new Comparators.NullComparator<>(false, comparator);
     }
 
     /**
--- a/jdk/src/share/classes/java/util/Comparators.java	Tue Aug 06 13:25:04 2013 -0700
+++ b/jdk/src/share/classes/java/util/Comparators.java	Tue Aug 06 12:56:18 2013 -0700
@@ -87,12 +87,12 @@
         @Override
         public Comparator<T> thenComparing(Comparator<? super T> 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<T> reversed() {
-            return new NullComparator(!nullFirst, real == null ? null : real.reversed());
+            return new NullComparator<>(!nullFirst, real == null ? null : real.reversed());
         }
     }
 }
--- a/jdk/src/share/classes/java/util/Hashtable.java	Tue Aug 06 13:25:04 2013 -0700
+++ b/jdk/src/share/classes/java/util/Hashtable.java	Tue Aug 06 12:56:18 2013 -0700
@@ -928,6 +928,7 @@
         return (null == result) ? defaultValue : result;
     }
 
+    @SuppressWarnings("unchecked")
     @Override
     public synchronized void forEach(BiConsumer<? super K, ? super V> action) {
         Objects.requireNonNull(action);     // explicit check required in case
@@ -947,6 +948,7 @@
         }
     }
 
+    @SuppressWarnings("unchecked")
     @Override
     public synchronized void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
         Objects.requireNonNull(function);     // explicit check required in case
--- a/jdk/src/share/classes/java/util/IdentityHashMap.java	Tue Aug 06 13:25:04 2013 -0700
+++ b/jdk/src/share/classes/java/util/IdentityHashMap.java	Tue Aug 06 12:56:18 2013 -0700
@@ -1339,6 +1339,7 @@
         tab[i + 1] = value;
     }
 
+    @SuppressWarnings("unchecked")
     @Override
     public void forEach(BiConsumer<? super K, ? super V> action) {
         Objects.requireNonNull(action);
@@ -1357,6 +1358,7 @@
         }
     }
 
+    @SuppressWarnings("unchecked")
     @Override
     public void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
         Objects.requireNonNull(function);
--- a/jdk/src/share/classes/java/util/Vector.java	Tue Aug 06 13:25:04 2013 -0700
+++ b/jdk/src/share/classes/java/util/Vector.java	Tue Aug 06 12:56:18 2013 -0700
@@ -1164,12 +1164,13 @@
                 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 @@
         modCount++;
     }
 
+    @SuppressWarnings("unchecked")
     @Override
-    @SuppressWarnings("unchecked")
     public synchronized void sort(Comparator<? super E> c) {
         final int expectedModCount = modCount;
         Arrays.sort((E[]) elementData, 0, elementCount, c);
--- a/jdk/src/share/classes/java/util/WeakHashMap.java	Tue Aug 06 13:25:04 2013 -0700
+++ b/jdk/src/share/classes/java/util/WeakHashMap.java	Tue Aug 06 12:56:18 2013 -0700
@@ -1038,6 +1038,7 @@
         }
     }
 
+    @SuppressWarnings("unchecked")
     @Override
     public void forEach(BiConsumer<? super K, ? super V> action) {
         Objects.requireNonNull(action);
@@ -1059,6 +1060,7 @@
         }
     }
 
+    @SuppressWarnings("unchecked")
     @Override
     public void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
         Objects.requireNonNull(function);