diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2020-12-05 00:23:15 +0100 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2020-12-22 10:53:00 +0100 |
commit | 50f0347ea3a17aa754dfb139acfc2d57ea488fa4 (patch) | |
tree | 2c2e7b4d50e3d9bd807e4d968af1e131e5128d42 /org.eclipse.jgit.ssh.apache | |
parent | bceb202319b6f2b02b15f32db5c40a912e4bd1f3 (diff) | |
download | jgit-50f0347ea3a17aa754dfb139acfc2d57ea488fa4.tar.gz jgit-50f0347ea3a17aa754dfb139acfc2d57ea488fa4.zip |
[spotbugs] Fix potential NPE in OpenSshServerKeyDatabase
If oldLine is null #updateModifiedServerKey shouldn't be called since it
would derefence it. Spotbugs raised this as problem
RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE. Fix it by checking if
oldLine is null before calling #updateModifiedServerKey.
Change-Id: I8a2000492986e52ce7dbe25f48b321c05fd371e4
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.ssh.apache')
-rw-r--r-- | org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/OpenSshServerKeyDatabase.java | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/OpenSshServerKeyDatabase.java b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/OpenSshServerKeyDatabase.java index 5bc1115f62..47e09b75d7 100644 --- a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/OpenSshServerKeyDatabase.java +++ b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/OpenSshServerKeyDatabase.java @@ -346,11 +346,14 @@ public class OpenSshServerKeyDatabase throws IOException { KnownHostEntry hostEntry = entry.getHostEntry(); String oldLine = hostEntry.getConfigLine(); + if (oldLine == null) { + return; + } String newLine = updateHostKeyLine(oldLine, serverKey); if (newLine == null || newLine.isEmpty()) { return; } - if (oldLine == null || oldLine.isEmpty() || newLine.equals(oldLine)) { + if (oldLine.isEmpty() || newLine.equals(oldLine)) { // Shouldn't happen. return; } |