8021429: Fix lint warnings in java.lang.ref
authordarcy
Thu, 25 Jul 2013 20:03:20 -0700
changeset 19053 69648476a89e
parent 19052 a912fc99040b
child 19054 a64012cb49d6
8021429: Fix lint warnings in java.lang.ref Reviewed-by: lancea, mduigou, alanb
jdk/src/share/classes/java/lang/ref/FinalReference.java
jdk/src/share/classes/java/lang/ref/Finalizer.java
jdk/src/share/classes/java/lang/ref/Reference.java
jdk/src/share/classes/java/lang/ref/ReferenceQueue.java
--- a/jdk/src/share/classes/java/lang/ref/FinalReference.java	Thu Jul 25 20:30:58 2013 -0400
+++ b/jdk/src/share/classes/java/lang/ref/FinalReference.java	Thu Jul 25 20:03:20 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,13 +25,12 @@
 
 package java.lang.ref;
 
-
-/* Final references, used to implement finalization */
-
+/**
+ * Final references, used to implement finalization
+ */
 class FinalReference<T> extends Reference<T> {
 
     public FinalReference(T referent, ReferenceQueue<? super T> q) {
         super(referent, q);
     }
-
 }
--- a/jdk/src/share/classes/java/lang/ref/Finalizer.java	Thu Jul 25 20:30:58 2013 -0400
+++ b/jdk/src/share/classes/java/lang/ref/Finalizer.java	Thu Jul 25 20:03:20 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -29,16 +29,16 @@
 import java.security.AccessController;
 
 
-final class Finalizer extends FinalReference { /* Package-private; must be in
-                                                  same package as the Reference
-                                                  class */
+final class Finalizer extends FinalReference<Object> { /* Package-private; must be in
+                                                          same package as the Reference
+                                                          class */
 
     /* A native method that invokes an arbitrary object's finalize method is
        required since the finalize method is protected
      */
     static native void invokeFinalizeMethod(Object o) throws Throwable;
 
-    private static ReferenceQueue queue = new ReferenceQueue();
+    private static ReferenceQueue<Object> queue = new ReferenceQueue<>();
     private static Finalizer unfinalized = null;
     private static final Object lock = new Object();
 
--- a/jdk/src/share/classes/java/lang/ref/Reference.java	Thu Jul 25 20:30:58 2013 -0400
+++ b/jdk/src/share/classes/java/lang/ref/Reference.java	Thu Jul 25 20:03:20 2013 -0700
@@ -96,6 +96,7 @@
      *    Enqueued:   next reference in queue (or this if last)
      *    Inactive:   this
      */
+    @SuppressWarnings("rawtypes")
     Reference next;
 
     /* When active:   next element in a discovered reference list maintained by GC (or this if last)
@@ -119,7 +120,7 @@
      * them.  This list is protected by the above lock object. The
      * list uses the discovered field to link its elements.
      */
-    private static Reference pending = null;
+    private static Reference<Object> pending = null;
 
     /* High-priority thread to enqueue pending References
      */
@@ -131,7 +132,7 @@
 
         public void run() {
             for (;;) {
-                Reference r;
+                Reference<Object> r;
                 synchronized (lock) {
                     if (pending != null) {
                         r = pending;
@@ -166,7 +167,7 @@
                     continue;
                 }
 
-                ReferenceQueue q = r.queue;
+                ReferenceQueue<Object> q = r.queue;
                 if (q != ReferenceQueue.NULL) q.enqueue(r);
             }
         }
--- a/jdk/src/share/classes/java/lang/ref/ReferenceQueue.java	Thu Jul 25 20:30:58 2013 -0400
+++ b/jdk/src/share/classes/java/lang/ref/ReferenceQueue.java	Thu Jul 25 20:03:20 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -40,14 +40,14 @@
      */
     public ReferenceQueue() { }
 
-    private static class Null extends ReferenceQueue {
-        boolean enqueue(Reference r) {
+    private static class Null<S> extends ReferenceQueue<S> {
+        boolean enqueue(Reference<? extends S> r) {
             return false;
         }
     }
 
-    static ReferenceQueue NULL = new Null();
-    static ReferenceQueue ENQUEUED = new Null();
+    static ReferenceQueue<Object> NULL = new Null<>();
+    static ReferenceQueue<Object> ENQUEUED = new Null<>();
 
     static private class Lock { };
     private Lock lock = new Lock();
@@ -58,7 +58,7 @@
         synchronized (lock) {
             // Check that since getting the lock this reference hasn't already been
             // enqueued (and even then removed)
-            ReferenceQueue queue = r.queue;
+            ReferenceQueue<?> queue = r.queue;
             if ((queue == NULL) || (queue == ENQUEUED)) {
                 return false;
             }
@@ -75,10 +75,13 @@
         }
     }
 
+    @SuppressWarnings("unchecked")
     private Reference<? extends T> reallyPoll() {       /* Must hold lock */
         Reference<? extends T> r = head;
         if (r != null) {
-            head = (r.next == r) ? null : r.next;
+            head = (r.next == r) ?
+                null :
+                r.next; // Unchecked due to the next field having a raw type in Reference
             r.queue = NULL;
             r.next = r;
             queueLength--;