From bd3823ce0df77bb3bd519fab9ccbec6653b16b66 Mon Sep 17 00:00:00 2001 From: Basil Crow Date: Fri, 24 Dec 2021 16:36:32 -0800 Subject: [PATCH] Spotbugs fixes for `LI_LAZY_INIT_STATIC`, `NP_LOAD_OF_KNOWN_NULL_VALUE`, and `UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD` (#6099) --- .../security/HudsonPrivateSecurityRealm.java | 1 + core/src/main/java/hudson/util/ProcessTree.java | 2 +- .../jenkins/security/MasterToSlaveCallable.java | 2 +- .../LegacyApiTokenAdministrativeMonitor.java | 2 ++ .../jenkins/util/JSONSignatureValidator.java | 1 + src/spotbugs/spotbugs-excludes.xml | 16 ---------------- 6 files changed, 6 insertions(+), 18 deletions(-) diff --git a/core/src/main/java/hudson/security/HudsonPrivateSecurityRealm.java b/core/src/main/java/hudson/security/HudsonPrivateSecurityRealm.java index 30885c48c9..4696d7c63e 100644 --- a/core/src/main/java/hudson/security/HudsonPrivateSecurityRealm.java +++ b/core/src/main/java/hudson/security/HudsonPrivateSecurityRealm.java @@ -401,6 +401,7 @@ public class HudsonPrivateSecurityRealm extends AbstractPasswordBasedSecurityRea * @return a {@link SignupInfo#SignupInfo(StaplerRequest) SignupInfo from given request}, with {@link * SignupInfo#errors} containing errors (keyed by field name), if any of the supported fields are invalid */ + @SuppressFBWarnings(value = "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", justification = "written to by Stapler") private SignupInfo validateAccountCreationForm(StaplerRequest req, boolean validateCaptcha) { // form field validation // this pattern needs to be generalized and moved to stapler diff --git a/core/src/main/java/hudson/util/ProcessTree.java b/core/src/main/java/hudson/util/ProcessTree.java index f9d140f51c..82c46d3292 100644 --- a/core/src/main/java/hudson/util/ProcessTree.java +++ b/core/src/main/java/hudson/util/ProcessTree.java @@ -427,7 +427,7 @@ public abstract class ProcessTree implements Iterable, IProcessTree, } - /* package */ static Boolean vetoersExist; + /* package */ static volatile Boolean vetoersExist; /** * Gets the {@link ProcessTree} of the current system diff --git a/core/src/main/java/jenkins/security/MasterToSlaveCallable.java b/core/src/main/java/jenkins/security/MasterToSlaveCallable.java index 456719c9fc..6751533a01 100644 --- a/core/src/main/java/jenkins/security/MasterToSlaveCallable.java +++ b/core/src/main/java/jenkins/security/MasterToSlaveCallable.java @@ -30,7 +30,7 @@ public abstract class MasterToSlaveCallable implements C public Channel getChannelOrFail() throws ChannelClosedException { final Channel ch = Channel.current(); if (ch == null) { - throw new ChannelClosedException(ch, new IllegalStateException("No channel associated with the thread")); + throw new ChannelClosedException((Channel) null, new IllegalStateException("No channel associated with the thread")); } return ch; } diff --git a/core/src/main/java/jenkins/security/apitoken/LegacyApiTokenAdministrativeMonitor.java b/core/src/main/java/jenkins/security/apitoken/LegacyApiTokenAdministrativeMonitor.java index 2e3005ddea..18827c94fd 100644 --- a/core/src/main/java/jenkins/security/apitoken/LegacyApiTokenAdministrativeMonitor.java +++ b/core/src/main/java/jenkins/security/apitoken/LegacyApiTokenAdministrativeMonitor.java @@ -25,6 +25,7 @@ package jenkins.security.apitoken; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import hudson.Extension; import hudson.model.AdministrativeMonitor; import hudson.model.User; @@ -160,6 +161,7 @@ public class LegacyApiTokenAdministrativeMonitor extends AdministrativeMonitor { } @RequirePOST + @SuppressFBWarnings(value = "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", justification = "written to by Stapler") public HttpResponse doRevokeAllSelected(@JsonBody RevokeAllSelectedModel content) throws IOException { for (RevokeAllSelectedUserAndUuid value : content.values) { if (value.userId == null) { diff --git a/core/src/main/java/jenkins/util/JSONSignatureValidator.java b/core/src/main/java/jenkins/util/JSONSignatureValidator.java index a6bd08c91a..e7ffef6d66 100644 --- a/core/src/main/java/jenkins/util/JSONSignatureValidator.java +++ b/core/src/main/java/jenkins/util/JSONSignatureValidator.java @@ -245,6 +245,7 @@ public class JSONSignatureValidator { } + @SuppressFBWarnings(value = "NP_LOAD_OF_KNOWN_NULL_VALUE", justification = "https://github.com/spotbugs/spotbugs/issues/756") protected Set loadTrustAnchors(CertificateFactory cf) throws IOException { // if we trust default root CAs, we end up trusting anyone who has a valid certificate, // which isn't useful at all diff --git a/src/spotbugs/spotbugs-excludes.xml b/src/spotbugs/spotbugs-excludes.xml index 9f5927b041..0d4eb6c636 100644 --- a/src/spotbugs/spotbugs-excludes.xml +++ b/src/spotbugs/spotbugs-excludes.xml @@ -144,7 +144,6 @@ - @@ -181,13 +180,6 @@ - - - - - - - @@ -513,14 +505,6 @@ - - - - - - - -