File tree Expand file tree Collapse file tree 2 files changed +19
-5
lines changed
driver-core/src/test/unit/com/mongodb/async Expand file tree Collapse file tree 2 files changed +19
-5
lines changed Original file line number Diff line number Diff line change 43
43
<suppress checks =" AvoidStarImportCheck" files =" .*primer.*" />
44
44
<suppress checks =" VisibilityModifierCheck" files =" .*primer.*" />
45
45
46
+ <!-- Allow printStackTrace in this file -->
47
+ <suppress checks =" Regexp" files =" CallbackResultHolder" />
48
+
46
49
<!-- Do not check documentation tests classes -->
47
50
<suppress checks =" Javadoc*" files =" .*documentation.*" />
48
51
<suppress checks =" Regexp" files =" .*documentation.*" />
Original file line number Diff line number Diff line change 16
16
17
17
package com .mongodb .async ;
18
18
19
+ import java .io .PrintWriter ;
20
+ import java .io .StringWriter ;
21
+
19
22
/**
20
23
* A SingleResultCallback implementation that saves the result of the callback.
21
24
*
@@ -35,13 +38,21 @@ class CallbackResultHolder<T> implements SingleResultCallback<T> {
35
38
*/
36
39
public void onResult (final T result , final Throwable error ) {
37
40
if (isDone ) {
38
- throw new IllegalStateException ("The CallbackResult cannot be initialized multiple times." );
41
+ throw new IllegalStateException ("The CallbackResult cannot be initialized multiple times. The first time it was initialized "
42
+ + "with " + (this .error != null ? getErrorString (this .error ) : this .result ) + "\n The second time it was initialized "
43
+ + "with " + (error != null ? getErrorString (error ) : result ));
39
44
}
40
45
this .result = result ;
41
46
this .error = error ;
42
47
this .isDone = true ;
43
48
}
44
49
50
+ private String getErrorString (final Throwable error ) {
51
+ StringWriter writer = new StringWriter ();
52
+ error .printStackTrace (new PrintWriter (writer ));
53
+ return writer .toString ();
54
+ }
55
+
45
56
/**
46
57
* Returns the result of the callback or null.
47
58
*
@@ -81,9 +92,9 @@ public boolean isDone() {
81
92
@ Override
82
93
public String toString () {
83
94
return "CallbackResultHolder{"
84
- + "result=" + result
85
- + ", error=" + error
86
- + ", isDone=" + isDone
87
- + '}' ;
95
+ + "result=" + result
96
+ + ", error=" + error
97
+ + ", isDone=" + isDone
98
+ + '}' ;
88
99
}
89
100
}
You can’t perform that action at this time.
0 commit comments