Skip to content

Commit

Permalink
Disallowed null error in BatchResult. Adjusted doc. (googleapis#921)
Browse files Browse the repository at this point in the history
  • Loading branch information
mderka authored and mziccard committed Apr 19, 2016
1 parent c95e1ec commit bf5b85a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
15 changes: 8 additions & 7 deletions gcloud-java-core/src/main/java/com/google/cloud/BatchResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T> the type of the result
* @param <E> the type of the service-dependent exception thrown when a processing error occurs
*
*/
public abstract class BatchResult<T, E extends BaseServiceException> {

Expand All @@ -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");
Expand All @@ -60,18 +63,16 @@ public T get() throws E {
* @throws IllegalStateException if the batch has been completed already
*/
public void notify(Callback<T, E> 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);
}

/**
* 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<T, E> callback : toBeNotified) {
callback.error(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit bf5b85a

Please sign in to comment.