36
36
/**
37
37
* The result of an unsuccessful or partially unsuccessful client-level bulk write operation.
38
38
* Note that the {@linkplain #getCode() code} and {@linkplain #getErrorLabels() labels} from this exception are not useful.
39
- * An application should use those from the {@linkplain #getError () top-level error}.
39
+ * An application should use those from the {@linkplain #getCause () top-level error}.
40
40
*
41
41
* @see ClientBulkWriteResult
42
42
* @since 5.3
45
45
public final class ClientBulkWriteException extends MongoServerException {
46
46
private static final long serialVersionUID = 1 ;
47
47
48
- @ Nullable
49
- private final MongoException error ;
50
48
private final List <WriteConcernError > writeConcernErrors ;
51
49
private final Map <Integer , WriteError > writeErrors ;
52
50
@ Nullable
@@ -55,7 +53,7 @@ public final class ClientBulkWriteException extends MongoServerException {
55
53
/**
56
54
* Constructs a new instance.
57
55
*
58
- * @param error The {@linkplain #getError () top-level error}.
56
+ * @param error The {@linkplain #getCause () top-level error}.
59
57
* @param writeConcernErrors The {@linkplain #getWriteConcernErrors() write concern errors}.
60
58
* @param writeErrors The {@linkplain #getWriteErrors() write errors}.
61
59
* @param partialResult The {@linkplain #getPartialResult() partial result}.
@@ -74,11 +72,11 @@ public ClientBulkWriteException(
74
72
error , writeConcernErrors , writeErrors , partialResult ,
75
73
notNull ("serverAddress" , serverAddress )),
76
74
validateServerAddress (error , serverAddress ));
75
+ initCause (error );
77
76
isTrueArgument ("At least one of `writeConcernErrors`, `writeErrors`, `partialResult` must be non-null or non-empty" ,
78
77
!(writeConcernErrors == null || writeConcernErrors .isEmpty ())
79
78
|| !(writeErrors == null || writeErrors .isEmpty ())
80
79
|| partialResult != null );
81
- this .error = error ;
82
80
this .writeConcernErrors = writeConcernErrors == null ? emptyList () : unmodifiableList (writeConcernErrors );
83
81
this .writeErrors = writeErrors == null ? emptyMap () : unmodifiableMap (writeErrors );
84
82
this .partialResult = partialResult ;
@@ -109,10 +107,12 @@ private static ServerAddress validateServerAddress(@Nullable final MongoExceptio
109
107
* The top-level error. That is an error that is neither a {@linkplain #getWriteConcernErrors() write concern error},
110
108
* nor is an {@linkplain #getWriteErrors() error of an individual write operation}.
111
109
*
112
- * @return The top-level error. {@linkplain Optional#isPresent() Present } only if a top-level error occurred.
110
+ * @return The top-level error. Non-{@code null } only if a top-level error occurred.
113
111
*/
114
- public Optional <MongoException > getError () {
115
- return ofNullable (error );
112
+ @ Override
113
+ @ Nullable
114
+ public MongoException getCause () {
115
+ return (MongoException ) super .getCause ();
116
116
}
117
117
118
118
/**
0 commit comments