]> source.dussan.org Git - jgit.git/commitdiff
[spotbugs] Fix potential NPE in OpenSshServerKeyDatabase 26/173426/6
authorMatthias Sohn <matthias.sohn@sap.com>
Fri, 4 Dec 2020 23:23:15 +0000 (00:23 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Tue, 22 Dec 2020 09:53:00 +0000 (10:53 +0100)
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>
org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/OpenSshServerKeyDatabase.java

index 5bc1115f6247b051dea60ced10384e6a4ee7a98a..47e09b75d7b81b596336da27e81c5a2a7ef7a054 100644 (file)
@@ -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;
                }