From 6383a3f08dc469684923c457e2ce5a2ae296f614 Mon Sep 17 00:00:00 2001 From: Andrew Parmet Date: Fri, 6 Oct 2023 16:09:09 -0400 Subject: [PATCH] tolerate null causes Signed-off-by: Andrew Parmet --- .../client/transport/aws/AwsSdk2Transport.java | 12 ++++++++---- .../httpclient5/ApacheHttpClient5Transport.java | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/java-client/src/main/java/org/opensearch/client/transport/aws/AwsSdk2Transport.java b/java-client/src/main/java/org/opensearch/client/transport/aws/AwsSdk2Transport.java index eb3274a368..737de115ff 100644 --- a/java-client/src/main/java/org/opensearch/client/transport/aws/AwsSdk2Transport.java +++ b/java-client/src/main/java/org/opensearch/client/transport/aws/AwsSdk2Transport.java @@ -194,11 +194,15 @@ public ResponseT performRequest( try { return executeAsync((SdkAsyncHttpClient) httpClient, clientReq, requestBody, endpoint, options).get(); } catch (ExecutionException e) { - if (e.getCause() instanceof IOException) { - throw (IOException) e.getCause(); - } else { - throw new IOException(e.getCause()); + Throwable cause = e.getCause(); + if (cause != null) { + if (cause instanceof IOException) { + throw (IOException) cause; + } else { + throw new IOException(cause); + } } + throw new IOException(e); } catch (InterruptedException e) { throw new IOException("HttpRequest was interrupted", e); } diff --git a/java-client/src/main/java/org/opensearch/client/transport/httpclient5/ApacheHttpClient5Transport.java b/java-client/src/main/java/org/opensearch/client/transport/httpclient5/ApacheHttpClient5Transport.java index 8d3b14c9dd..032e0fd204 100644 --- a/java-client/src/main/java/org/opensearch/client/transport/httpclient5/ApacheHttpClient5Transport.java +++ b/java-client/src/main/java/org/opensearch/client/transport/httpclient5/ApacheHttpClient5Transport.java @@ -143,11 +143,15 @@ public ResponseT performRequest( try { return performRequestAsync(request, endpoint, options).join(); } catch (final CompletionException ex) { - if (ex.getCause() instanceof IOException) { - throw (IOException) ex.getCause(); - } else { - throw new IOException(ex.getCause()); + Throwable cause = ex.getCause(); + if (cause != null) { + if (cause instanceof IOException) { + throw (IOException) cause; + } else { + throw new IOException(cause); + } } + throw new IOException(ex); } }