From 61ec1455c000024c53425fe84bfb238880e46c8d Mon Sep 17 00:00:00 2001 From: Lajos Olah Date: Tue, 25 Feb 2020 17:17:02 -0500 Subject: [PATCH] Do not fail if known hosts file does not contain valid host key KnownHosts (implementing HostKeyRepository) in Jsch can return null which could cause NullPointerException in Stream.of(...) Change-Id: Iddcf5f34f8c8475a85ca7ae018bbe48d1b3fbbc0 Signed-off-by: Lajos Olah --- .../eclipse/jgit/transport/JschConfigSessionFactory.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/JschConfigSessionFactory.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/JschConfigSessionFactory.java index faa917a50..718c8f611 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/JschConfigSessionFactory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/JschConfigSessionFactory.java @@ -219,7 +219,13 @@ public abstract class JschConfigSessionFactory extends SshSessionFactory { private static void setPreferredKeyTypesOrder(Session session) { HostKeyRepository hkr = session.getHostKeyRepository(); - List known = Stream.of(hkr.getHostKey(hostName(session), null)) + HostKey[] hostKeys = hkr.getHostKey(hostName(session), null); + + if (hostKeys == null) { + return; + } + + List known = Stream.of(hostKeys) .map(HostKey::getType) .collect(toList());