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 <lajos.olah.jr@gmail.com>
This commit is contained in:
Lajos Olah 2020-02-25 17:17:02 -05:00
parent f63583928f
commit 61ec1455c0
1 changed files with 7 additions and 1 deletions

View File

@ -219,7 +219,13 @@ private void safeConfig(Session session, Config cfg) {
private static void setPreferredKeyTypesOrder(Session session) {
HostKeyRepository hkr = session.getHostKeyRepository();
List<String> known = Stream.of(hkr.getHostKey(hostName(session), null))
HostKey[] hostKeys = hkr.getHostKey(hostName(session), null);
if (hostKeys == null) {
return;
}
List<String> known = Stream.of(hostKeys)
.map(HostKey::getType)
.collect(toList());