Skip to content

Commit f475d79

Browse files
committed
docs(datastore): add comments explaining exception unwrapping and interruption handling
1 parent 181e2e6 commit f475d79

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

java-datastore/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/it/ITDatastoreProtoClientTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ private static <V> V runWithRetry(
139139
return submittedFuture.get();
140140
} catch (ExecutionException e) {
141141
Throwable cause = e.getCause();
142+
// submittedFuture.get() wraps any exception thrown during execution in an ExecutionException.
143+
// We unwrap and rethrow the actual cause (Exception or Error) directly so that test failures
144+
// report the root cause (e.g., DatastoreException or AssertionError) instead of the wrapper.
142145
if (cause instanceof Exception) {
143146
throw (Exception) cause;
144147
}
@@ -147,6 +150,7 @@ private static <V> V runWithRetry(
147150
}
148151
throw e;
149152
} catch (InterruptedException e) {
153+
// Restore the interrupted status before rethrowing, as per Java concurrency best practices.
150154
Thread.currentThread().interrupt();
151155
throw e;
152156
}

java-datastore/google-cloud-datastore-utils/src/test/java/com/google/datastore/utils/it/ITDatastoreProtoClientTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ private static <V> V runWithRetry(
135135
return submittedFuture.get();
136136
} catch (ExecutionException e) {
137137
Throwable cause = e.getCause();
138+
// submittedFuture.get() wraps any exception thrown during execution in an ExecutionException.
139+
// We unwrap and rethrow the actual cause (Exception or Error) directly so that test failures
140+
// report the root cause (e.g., DatastoreException or AssertionError) instead of the wrapper.
138141
if (cause instanceof Exception) {
139142
throw (Exception) cause;
140143
}
@@ -143,6 +146,7 @@ private static <V> V runWithRetry(
143146
}
144147
throw e;
145148
} catch (InterruptedException e) {
149+
// Restore the interrupted status before rethrowing, as per Java concurrency best practices.
146150
Thread.currentThread().interrupt();
147151
throw e;
148152
}

0 commit comments

Comments
 (0)