Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Disallowed null error in BatchResult. Adjusted doc.
  • Loading branch information
mderka committed Apr 14, 2016
commit 6127358501af6c44692dba3a5979439f408e2be1
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 @@ -23,8 +23,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 @@ -45,7 +48,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 @@ -61,18 +64,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