RFR 8067112: Update jdk/test/java/util/Collections/EmptyIterator.java to eliminate dependency on sun.tools.java

Pavel Rappo pavel.rappo at oracle.com
Wed Dec 10 11:47:05 UTC 2014


A quick question: can we piggyback on this particular issue and
remove some generics here? (see javac warnings):

diff -r cb475099ceac test/java/util/Collections/EmptyIterator.java
--- a/test/java/util/Collections/EmptyIterator.java	Tue Dec 09 09:22:07 2014 -0800
+++ b/test/java/util/Collections/EmptyIterator.java	Wed Dec 10 11:42:35 2014 +0000
@@ -33,12 +33,12 @@
 public class EmptyIterator {
 
     void test(String[] args) throws Throwable {
-        testEmptyCollection(Collections.<Object>emptyList());
-        testEmptyCollection(Collections.<Object>emptySet());
+        testEmptyCollection(Collections.emptyList());
+        testEmptyCollection(Collections.emptySet());
 
-        testEmptyMap(Collections.<Object, Object>emptyMap());
+        testEmptyMap(Collections.emptyMap());
 
-        Hashtable<Object, Object> emptyTable = new Hashtable<Object, Object>();
+        Hashtable<?, ?> emptyTable = new Hashtable<>();
         testEmptyEnumeration(emptyTable.keys());
         testEmptyEnumeration(emptyTable.elements());
         testEmptyIterator(emptyTable.keySet().iterator());
@@ -49,24 +49,21 @@
             Collections.emptyEnumeration();
         testEmptyEnumeration(finalEmptyTyped);
 
-        final Enumeration finalEmptyAbstract =
+        final Enumeration<?> finalEmptyAbstract =
             Collections.emptyEnumeration();
         testEmptyEnumeration(finalEmptyAbstract);
 
-        @SuppressWarnings("unchecked") Iterator<?> x =
-            new sun.tools.java.MethodSet()
-            .lookupName(sun.tools.java.Identifier.lookup(""));
-        testEmptyIterator(x);
+        testEmptyIterator(Collections.emptyIterator());
     }
 
-    <T> void testEmptyEnumeration(final Enumeration<T> e) {
+    void testEmptyEnumeration(final Enumeration<?> e) {
         check(e == emptyEnumeration());
         check(! e.hasMoreElements());
         THROWS(NoSuchElementException.class,
                new F(){void f(){ e.nextElement(); }});
     }
 
-    <T> void testEmptyIterator(final Iterator<T> it) {
+    void testEmptyIterator(final Iterator<?> it) {
         check(it == emptyIterator());
         check(! it.hasNext());
         THROWS(NoSuchElementException.class,
@@ -75,10 +72,10 @@
                new F(){void f(){ it.remove(); }});
     }
 
-    void testEmptyMap(Map<Object, Object> m) {
+    void testEmptyMap(Map<?, ?> m) {
         check(m == emptyMap());
-        check(m.entrySet().iterator() ==
-              Collections.<Map.Entry<Object,Object>>emptyIterator());
+        Iterator<? extends Map.Entry<?, ?>> iterator = m.entrySet().iterator();
+        check(iterator == Collections.<Map.Entry<?,?>>emptyIterator());
         check(m.values().iterator() == emptyIterator());
         check(m.keySet().iterator() == emptyIterator());
         equal(m, unmodifiableMap(m));
@@ -88,12 +85,12 @@
         testEmptyCollection(m.values());
     }
 
-    <E> void testToArray(final Collection<E> c) {
+    void testToArray(final Collection<?> c) {
         Object[] a = c.toArray();
         equal(a.length, 0);
         equal(a.getClass().getComponentType(), Object.class);
         THROWS(NullPointerException.class,
-               new F(){void f(){ c.toArray((Object[])null); }});
+               new F(){void f(){ c.toArray(null); }});
 
         {
             String[] t = new String[0];
@@ -109,7 +106,7 @@
         }
     }
 
-    <E> void testEmptyCollection(final Collection<E> c) {
+    void testEmptyCollection(final Collection<?> c) {
         testEmptyIterator(c.iterator());
 
         check(c.iterator() == emptyIterator());

-Pavel

> On 10 Dec 2014, at 10:26, Chris Hegarty <chris.hegarty at oracle.com> wrote:
> 
> This looks good to me Amy. Do you need a sponsor ?
> 
> -Chris.
> 
> On 10/12/14 10:15, Amy Lu wrote:
>> Please review the fix for removing internal JDK API dependency from test
>> java/util/Collections/EmptyIterator.java
>> 
>> This test has dependency on sun.tools.java from one of it’s test case,
>> this fixed by using public API for the same testing purpose.
>> 
>> bug: https://bugs.openjdk.java.net/browse/JDK-8067112
>> webrev: http://cr.openjdk.java.net/~weijun/8067112/webrev.00/
>> 
>> Thanks,
>> Amy




More information about the core-libs-dev mailing list