1
1
/*
2
- * Copyright 2002-2014 the original author or authors.
2
+ * Copyright 2002-2016 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
23
23
import java .util .concurrent .atomic .AtomicReference ;
24
24
25
25
import org .springframework .util .Assert ;
26
+ import org .springframework .util .ReflectionUtils ;
26
27
27
28
/**
28
29
* A {@link org.springframework.util.concurrent.ListenableFuture ListenableFuture}
@@ -49,11 +50,11 @@ public SettableListenableFuture() {
49
50
50
51
51
52
/**
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}
57
58
*/
58
59
public boolean set (T value ) {
59
60
boolean success = this .settableTask .setValue (value );
@@ -64,14 +65,14 @@ public boolean set(T value) {
64
65
}
65
66
66
67
/**
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}
72
73
*/
73
74
public boolean setException (Throwable exception ) {
74
- Assert .notNull (exception , "'exception' must not be null" );
75
+ Assert .notNull (exception , "Exception must not be null" );
75
76
boolean success = this .settableTask .setException (exception );
76
77
if (success ) {
77
78
this .listenableFuture .run ();
@@ -149,7 +150,7 @@ protected void interruptTask() {
149
150
150
151
private static class SettableTask <T > implements Callable <T > {
151
152
152
- private static final String NO_VALUE = SettableListenableFuture . class . getName () + ".NO_VALUE" ;
153
+ private static final Object NO_VALUE = new Object () ;
153
154
154
155
private final AtomicReference <Object > value = new AtomicReference <Object >(NO_VALUE );
155
156
@@ -176,10 +177,11 @@ public void setCancelled() {
176
177
@ SuppressWarnings ("unchecked" )
177
178
@ Override
178
179
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 );
181
183
}
182
- return (T ) value . get () ;
184
+ return (T ) val ;
183
185
}
184
186
}
185
187
0 commit comments