8041772: (ch) PendingFuture.CANCELLED has backtrace that potentially keeps objects alive
authoralanb
Wed, 30 Apr 2014 14:27:19 +0100
changeset 24199 6c6e4f22e8b5
parent 24198 41b2f3e923b8
child 24200 5cbca4ed35a3
8041772: (ch) PendingFuture.CANCELLED has backtrace that potentially keeps objects alive Reviewed-by: chegar
jdk/src/share/classes/sun/nio/ch/PendingFuture.java
--- a/jdk/src/share/classes/sun/nio/ch/PendingFuture.java	Wed Apr 30 14:46:19 2014 +0200
+++ b/jdk/src/share/classes/sun/nio/ch/PendingFuture.java	Wed Apr 30 14:27:19 2014 +0100
@@ -35,8 +35,6 @@
  */
 
 final class PendingFuture<V,A> implements Future<V> {
-    private static final CancellationException CANCELLED =
-        new CancellationException();
 
     private final AsynchronousChannel channel;
     private final CompletionHandler<V,? super A> handler;
@@ -180,7 +178,7 @@
                 latch.await();
         }
         if (exc != null) {
-            if (exc == CANCELLED)
+            if (exc instanceof CancellationException)
                 throw new CancellationException();
             throw new ExecutionException(exc);
         }
@@ -197,7 +195,7 @@
                 if (!latch.await(timeout, unit)) throw new TimeoutException();
         }
         if (exc != null) {
-            if (exc == CANCELLED)
+            if (exc instanceof CancellationException)
                 throw new CancellationException();
             throw new ExecutionException(exc);
         }
@@ -205,7 +203,7 @@
     }
 
     Throwable exception() {
-        return (exc != CANCELLED) ? exc : null;
+        return (exc instanceof CancellationException) ? null : exc;
     }
 
     V value() {
@@ -214,7 +212,7 @@
 
     @Override
     public boolean isCancelled() {
-        return (exc == CANCELLED);
+        return (exc instanceof CancellationException);
     }
 
     @Override
@@ -233,7 +231,7 @@
                 ((Cancellable)channel()).onCancel(this);
 
             // set result and cancel timer
-            exc = CANCELLED;
+            exc = new CancellationException();
             haveResult = true;
             if (timeoutTask != null)
                 timeoutTask.cancel(false);