11/*
2- * Copyright 2002-2014 the original author or authors.
2+ * Copyright 2002-2016 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
2323import java .util .concurrent .atomic .AtomicReference ;
2424
2525import org .springframework .util .Assert ;
26+ import org .springframework .util .ReflectionUtils ;
2627
2728/**
2829 * A {@link org.springframework.util.concurrent.ListenableFuture ListenableFuture}
@@ -49,11 +50,11 @@ public SettableListenableFuture() {
4950
5051
5152 /**
52- * Set the value of this future. This method will return {@code true} if
53- * the value was set successfully, or {@code false} if the future has already
54- * been set or cancelled.
55- * @param value the value that will be set.
56- * @return {@code true} if the value was successfully set, else {@code false}.
53+ * Set the value of this future. This method will return {@code true} if the
54+ * value was set successfully, or {@code false} if the future has already been
55+ * set or cancelled.
56+ * @param value the value that will be set
57+ * @return {@code true} if the value was successfully set, else {@code false}
5758 */
5859 public boolean set (T value ) {
5960 boolean success = this .settableTask .setValue (value );
@@ -64,14 +65,14 @@ public boolean set(T value) {
6465 }
6566
6667 /**
67- * Set the exception of this future. This method will return {@code true} if
68- * the exception was set successfully, or {@code false} if the future has already
69- * been set or cancelled.
70- * @param exception the value that will be set.
71- * @return {@code true} if the exception was successfully set, else {@code false}.
68+ * Set the exception of this future. This method will return {@code true} if the
69+ * exception was set successfully, or {@code false} if the future has already been
70+ * set or cancelled.
71+ * @param exception the value that will be set
72+ * @return {@code true} if the exception was successfully set, else {@code false}
7273 */
7374 public boolean setException (Throwable exception ) {
74- Assert .notNull (exception , "'exception' must not be null" );
75+ Assert .notNull (exception , "Exception must not be null" );
7576 boolean success = this .settableTask .setException (exception );
7677 if (success ) {
7778 this .listenableFuture .run ();
@@ -149,7 +150,7 @@ protected void interruptTask() {
149150
150151 private static class SettableTask <T > implements Callable <T > {
151152
152- private static final String NO_VALUE = SettableListenableFuture . class . getName () + ".NO_VALUE" ;
153+ private static final Object NO_VALUE = new Object () ;
153154
154155 private final AtomicReference <Object > value = new AtomicReference <Object >(NO_VALUE );
155156
@@ -176,10 +177,11 @@ public void setCancelled() {
176177 @ SuppressWarnings ("unchecked" )
177178 @ Override
178179 public T call () throws Exception {
179- if (value .get () instanceof Exception ) {
180- throw (Exception ) value .get ();
180+ Object val = this .value .get ();
181+ if (val instanceof Throwable ) {
182+ ReflectionUtils .rethrowException ((Throwable ) val );
181183 }
182- return (T ) value . get () ;
184+ return (T ) val ;
183185 }
184186 }
185187
0 commit comments