Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallowed null error in BatchResult. Adjusted doc. #921

Merged
merged 1 commit into from
Apr 14, 2016
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
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