src/share/classes/java/util/concurrent/CopyOnWriteArrayList.java

Print this page

        

@@ -34,11 +34,10 @@
  */
 
 package java.util.concurrent;
 import java.util.*;
 import java.util.concurrent.locks.*;
-import sun.misc.Unsafe;
 
 /**
  * A thread-safe variant of {@link java.util.ArrayList} in which all mutative
  * operations (<tt>add</tt>, <tt>set</tt>, and so on) are implemented by
  * making a fresh copy of the underlying array.

@@ -279,13 +278,15 @@
      *
      * @return a clone of this list
      */
     public Object clone() {
         try {
-            CopyOnWriteArrayList c = (CopyOnWriteArrayList)(super.clone());
-            c.resetLock();
-            return c;
+            @SuppressWarnings("unchecked")
+            CopyOnWriteArrayList<E> clone =
+                (CopyOnWriteArrayList<E>) super.clone();
+            clone.resetLock();
+            return clone;
         } catch (CloneNotSupportedException e) {
             // this shouldn't happen, since we are Cloneable
             throw new InternalError();
         }
     }

@@ -1328,11 +1329,11 @@
     private static final sun.misc.Unsafe UNSAFE;
     private static final long lockOffset;
     static {
         try {
             UNSAFE = sun.misc.Unsafe.getUnsafe();
-            Class k = CopyOnWriteArrayList.class;
+            Class<?> k = CopyOnWriteArrayList.class;
             lockOffset = UNSAFE.objectFieldOffset
                 (k.getDeclaredField("lock"));
         } catch (Exception e) {
             throw new Error(e);
         }