Skip to content

Commit 0d90aed

Browse files
committed
πŸš‘ fix NullPointerException (#2256)
1 parent f4a12e4 commit 0d90aed

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

β€Žgoogle-cloud-datastore/src/main/java/com/google/cloud/datastore/TransactionExceptionHandler.javaβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class TransactionExceptionHandler {
3333
public RetryResult beforeEval(Exception exception) {
3434
if (exception instanceof DatastoreException) {
3535
DatastoreException e = getInnerException((DatastoreException) exception);
36-
if (e.getCode() == ABORTED_CODE || e.getReason().equals("ABORTED")) {
36+
if (e.getCode() == ABORTED_CODE || e.getReason()!=null && e.getReason().equals("ABORTED")) {
3737
return Interceptor.RetryResult.RETRY;
3838
}
3939
}

β€Žgoogle-cloud-datastore/src/test/java/com/google/cloud/datastore/TransactionExceptionHandlerTest.javaβ€Ž

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,15 @@ public void testShouldTry() {
6060

6161
assertTrue(transactionHandler.shouldRetry(nestedDatastoreException, null));
6262
assertFalse(handler.shouldRetry(nestedDatastoreException, null));
63+
64+
DatastoreException nestedUserException =
65+
new DatastoreException(
66+
BaseServiceException.UNKNOWN_CODE,
67+
"",
68+
null,
69+
new RuntimeException(""));
70+
71+
assertFalse(transactionHandler.shouldRetry(nestedUserException, null));
72+
assertFalse(handler.shouldRetry(nestedDatastoreException, null));
6373
}
6474
}

0 commit comments

Comments
Β (0)