From ef3e84ce3aa74d32a6ac9b5a292106512ce4dedf Mon Sep 17 00:00:00 2001 From: Ryan Fu Date: Mon, 17 Oct 2022 10:08:07 -0700 Subject: [PATCH] Checks for iterator hasNext element (#18041) * Checks for iterator hasNext element * Fix linter with newline --- .../io/airbyte/integrations/base/ssh/SshTunnel.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/airbyte-integrations/bases/base-java/src/main/java/io/airbyte/integrations/base/ssh/SshTunnel.java b/airbyte-integrations/bases/base-java/src/main/java/io/airbyte/integrations/base/ssh/SshTunnel.java index 1c694def8e9a..313dfe46d053 100644 --- a/airbyte-integrations/bases/base-java/src/main/java/io/airbyte/integrations/base/ssh/SshTunnel.java +++ b/airbyte-integrations/bases/base-java/src/main/java/io/airbyte/integrations/base/ssh/SshTunnel.java @@ -142,7 +142,7 @@ public SshTunnel(final JsonNode config, URL urlObject = null; try { urlObject = new URL(remoteServiceUrl); - } catch (MalformedURLException e) { + } catch (final MalformedURLException e) { AirbyteTraceMessageUtility.emitConfigErrorTrace(e, String.format("Provided value for remote service URL is not valid: %s", remoteServiceUrl)); } @@ -184,7 +184,8 @@ public JsonNode getConfigInTunnel() throws Exception { Jsons.replaceNestedInt(clone, portKey, tunnelLocalPort); } if (endPointKey != null) { - URL tunnelEndPointURL = new URL(remoteServiceProtocol, SshdSocketAddress.LOCALHOST_ADDRESS.getHostName(), tunnelLocalPort, remoteServicePath); + final URL tunnelEndPointURL = + new URL(remoteServiceProtocol, SshdSocketAddress.LOCALHOST_ADDRESS.getHostName(), tunnelLocalPort, remoteServicePath); Jsons.replaceNestedString(clone, Arrays.asList(endPointKey), tunnelEndPointURL.toString()); } return clone; @@ -306,7 +307,10 @@ KeyPair getPrivateKeyPair() throws IOException, GeneralSecurityException { .getKeyPairResourceParser() .loadKeyPairs(null, null, null, new StringReader(validatedKey)); - return (keyPairs == null) ? null : keyPairs.iterator().next(); + if (keyPairs != null && keyPairs.iterator().hasNext()) { + return keyPairs.iterator().next(); + } + return null; } private String validateKey() {