Set an exception thrown instead of the root cause during the Client initialization
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 22274a3..16c3521 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -27,6 +27,7 @@
* Bumped to Apache `commons-configuration` 2.8.0 to fix security vulnerability.
* Fixed issue where the `GremlinGroovyScriptEngine` reused the same translator concurrently which lead to incorrect translations.
* Fixed bug where tasks that haven't started running yet time out due to `evaluationTimeout` and never send a response back to the client.
+* Set the exact exception in `initializationFailure` on the Java driver instead of the root cause.
[[release-3-5-4]]
=== TinkerPop 3.5.4 (Release Date: July 18, 2022)
diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Client.java b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Client.java
index ed75730..89dfcc7 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Client.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Client.java
@@ -534,14 +534,8 @@
.toArray(CompletableFuture[]::new))
.join();
} catch (CompletionException ex) {
- Throwable cause = ExceptionUtils.getRootCause(ex);
- if (null != cause) {
- logger.error("", cause);
- this.initializationFailure = cause;
- } else {
- logger.error("", ex);
- this.initializationFailure = ex;
- }
+ logger.error("Initialization failed", ex);
+ this.initializationFailure = ex;
} finally {
hostExecutor.shutdown();
}
@@ -559,9 +553,9 @@
}
private void throwNoHostAvailableException() {
+ final Throwable rootCause = ExceptionUtils.getRootCause(initializationFailure);
// allow the certain exceptions to propagate as a cause
- if (initializationFailure != null && (initializationFailure instanceof SSLException ||
- initializationFailure instanceof ConnectException)) {
+ if (rootCause instanceof SSLException || rootCause instanceof ConnectException) {
throw new NoHostAvailableException(initializationFailure);
} else {
throw new NoHostAvailableException();
diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinDriverIntegrateTest.java b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinDriverIntegrateTest.java
index 04945e2..e44660e 100644
--- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinDriverIntegrateTest.java
+++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinDriverIntegrateTest.java
@@ -1862,7 +1862,7 @@
if (client instanceof Client.SessionedClient) {
assertThat(re2.getCause().getCause(), instanceOf(ConnectionException.class));
} else {
- assertThat(re2.getCause(), instanceOf(ConnectException.class));
+ assertThat(re2.getCause().getCause().getCause(), instanceOf(ConnectException.class));
}
}