Skip to content

Commit bf5b85a

Browse files
mderkamziccard
authored andcommitted
Disallowed null error in BatchResult. Adjusted doc. (googleapis#921)
1 parent c95e1ec commit bf5b85a

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

gcloud-java-core/src/main/java/com/google/cloud/BatchResult.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@
2222
import java.util.List;
2323

2424
/**
25-
* This class holds a single result of a batch call. {@code T} is the type of the result and {@code
26-
* E} is the type of the service-dependent exception thrown when a processing error occurs.
25+
* This class holds a single result of a batch call. The class is not thread-safe.
26+
*
27+
* @param <T> the type of the result
28+
* @param <E> the type of the service-dependent exception thrown when a processing error occurs
29+
*
2730
*/
2831
public abstract class BatchResult<T, E extends BaseServiceException> {
2932

@@ -44,7 +47,7 @@ public boolean completed() {
4447
* Returns the result of this call.
4548
*
4649
* @throws IllegalStateException if the batch has not been completed yet
47-
* @throws E if an error occurred when processing this request
50+
* @throws E if an error occurred when processing the batch request
4851
*/
4952
public T get() throws E {
5053
checkState(completed(), "Batch has not been completed yet");
@@ -60,18 +63,16 @@ public T get() throws E {
6063
* @throws IllegalStateException if the batch has been completed already
6164
*/
6265
public void notify(Callback<T, E> callback) {
63-
if (completed) {
64-
throw new IllegalStateException("The batch has been completed. All the calls to the notify()"
66+
checkState(!completed, "The batch has been completed. All the calls to the notify()"
6567
+ " method should be done prior to submitting the batch.");
66-
}
6768
toBeNotified.add(callback);
6869
}
6970

7071
/**
7172
* Sets an error and status as completed. Notifies all callbacks.
7273
*/
7374
protected void error(E error) {
74-
this.error = error;
75+
this.error = checkNotNull(error);
7576
this.completed = true;
7677
for (Callback<T, E> callback : toBeNotified) {
7778
callback.error(error);

gcloud-java-core/src/test/java/com/google/cloud/BatchResultTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ public void testError() {
5858
} catch (IllegalStateException ex) {
5959
// expected
6060
}
61+
try {
62+
result.error(null);
63+
fail();
64+
} catch (NullPointerException exc) {
65+
// expected
66+
}
6167
BaseServiceException ex = new BaseServiceException(0, "message", "reason", false);
6268
result.error(ex);
6369
try {

0 commit comments

Comments
 (0)