diff --git a/gcloud-java-core/src/main/java/com/google/cloud/BatchResult.java b/gcloud-java-core/src/main/java/com/google/cloud/BatchResult.java index 388551d5aaea..143966254a53 100644 --- a/gcloud-java-core/src/main/java/com/google/cloud/BatchResult.java +++ b/gcloud-java-core/src/main/java/com/google/cloud/BatchResult.java @@ -22,8 +22,11 @@ import java.util.List; /** - * This class holds a single result of a batch call. {@code T} is the type of the result and {@code - * E} is the type of the service-dependent exception thrown when a processing error occurs. + * This class holds a single result of a batch call. The class is not thread-safe. + * + * @param the type of the result + * @param the type of the service-dependent exception thrown when a processing error occurs + * */ public abstract class BatchResult { @@ -44,7 +47,7 @@ public boolean completed() { * Returns the result of this call. * * @throws IllegalStateException if the batch has not been completed yet - * @throws E if an error occurred when processing this request + * @throws E if an error occurred when processing the batch request */ public T get() throws E { checkState(completed(), "Batch has not been completed yet"); @@ -60,10 +63,8 @@ public T get() throws E { * @throws IllegalStateException if the batch has been completed already */ public void notify(Callback callback) { - if (completed) { - throw new IllegalStateException("The batch has been completed. All the calls to the notify()" + checkState(!completed, "The batch has been completed. All the calls to the notify()" + " method should be done prior to submitting the batch."); - } toBeNotified.add(callback); } @@ -71,7 +72,7 @@ public void notify(Callback callback) { * Sets an error and status as completed. Notifies all callbacks. */ protected void error(E error) { - this.error = error; + this.error = checkNotNull(error); this.completed = true; for (Callback callback : toBeNotified) { callback.error(error); diff --git a/gcloud-java-core/src/test/java/com/google/cloud/BatchResultTest.java b/gcloud-java-core/src/test/java/com/google/cloud/BatchResultTest.java index 85172170144d..8fb26bc8ce36 100644 --- a/gcloud-java-core/src/test/java/com/google/cloud/BatchResultTest.java +++ b/gcloud-java-core/src/test/java/com/google/cloud/BatchResultTest.java @@ -58,6 +58,12 @@ public void testError() { } catch (IllegalStateException ex) { // expected } + try { + result.error(null); + fail(); + } catch (NullPointerException exc) { + // expected + } BaseServiceException ex = new BaseServiceException(0, "message", "reason", false); result.error(ex); try {