diff --git a/core/pom.xml b/core/pom.xml index 11d7648919..35ff031eef 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -510,6 +510,13 @@ THE SOFTWARE. 1.0 + + findbugs + annotations + 1.0.0 + provided + + + findbugs @@ -761,8 +768,7 @@ THE SOFTWARE. 2.3.2 Max - Normal - hudson.- + High src/findbugs-filter.xml diff --git a/core/src/findbugs-filter.xml b/core/src/findbugs-filter.xml index 0d8254b1f3..751d3fa8a5 100644 --- a/core/src/findbugs-filter.xml +++ b/core/src/findbugs-filter.xml @@ -1,139 +1,20 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + - - - - - + - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + diff --git a/core/src/main/java/hudson/WebAppMain.java b/core/src/main/java/hudson/WebAppMain.java index bb5095632f..722b0391b5 100644 --- a/core/src/main/java/hudson/WebAppMain.java +++ b/core/src/main/java/hudson/WebAppMain.java @@ -260,6 +260,7 @@ public final class WebAppMain implements ServletContextListener { /** * Installs log handler to monitor all Hudson logs. */ + @edu.umd.cs.findbugs.annotations.SuppressWarnings("LG_LOST_LOGGER_DUE_TO_WEAK_REFERENCE") private void installLogger() { Jenkins.logRecords = handler.getView(); Logger.getLogger("hudson").addHandler(handler); diff --git a/core/src/main/java/hudson/cli/CliManagerImpl.java b/core/src/main/java/hudson/cli/CliManagerImpl.java index 8bef506b45..af67eaa3ea 100644 --- a/core/src/main/java/hudson/cli/CliManagerImpl.java +++ b/core/src/main/java/hudson/cli/CliManagerImpl.java @@ -59,7 +59,7 @@ import static java.util.logging.Level.*; * @author Kohsuke Kawaguchi */ public class CliManagerImpl implements CliEntryPoint, Serializable { - private final Channel channel; + private transient final Channel channel; public CliManagerImpl(Channel channel) { this.channel = channel; diff --git a/core/src/main/java/hudson/logging/LogRecorderManager.java b/core/src/main/java/hudson/logging/LogRecorderManager.java index 9e1f22c8e7..3ceff0a419 100644 --- a/core/src/main/java/hudson/logging/LogRecorderManager.java +++ b/core/src/main/java/hudson/logging/LogRecorderManager.java @@ -112,6 +112,7 @@ public class LogRecorderManager extends AbstractModelObject { /** * Configure the logging level. */ + @edu.umd.cs.findbugs.annotations.SuppressWarnings("LG_LOST_LOGGER_DUE_TO_WEAK_REFERENCE") public HttpResponse doConfigLogger(@QueryParameter String name, @QueryParameter String level) { Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER); Level lv; diff --git a/core/src/main/java/hudson/model/AperiodicWork.java b/core/src/main/java/hudson/model/AperiodicWork.java index e10696531b..bccb84b8ea 100644 --- a/core/src/main/java/hudson/model/AperiodicWork.java +++ b/core/src/main/java/hudson/model/AperiodicWork.java @@ -74,7 +74,7 @@ public abstract class AperiodicWork extends SafeTimerTask implements ExtensionPo * By default it chooses the value randomly between 0 and {@link #getRecurrencePeriod()} */ public long getInitialDelay() { - return Math.abs(new Random().nextLong())%getRecurrencePeriod(); + return Math.abs(RANDOM.nextLong())%getRecurrencePeriod(); } @Override @@ -92,4 +92,5 @@ public abstract class AperiodicWork extends SafeTimerTask implements ExtensionPo return Jenkins.getInstance().getExtensionList(AperiodicWork.class); } + private static final Random RANDOM = new Random(); } diff --git a/core/src/main/java/hudson/model/FingerprintCleanupThread.java b/core/src/main/java/hudson/model/FingerprintCleanupThread.java index 348bd8ffff..e70037ab57 100644 --- a/core/src/main/java/hudson/model/FingerprintCleanupThread.java +++ b/core/src/main/java/hudson/model/FingerprintCleanupThread.java @@ -45,11 +45,8 @@ import java.util.regex.Pattern; @Extension public final class FingerprintCleanupThread extends AsyncPeriodicWork { - private static FingerprintCleanupThread theInstance; - public FingerprintCleanupThread() { super("Fingerprint cleanup"); - theInstance = this; } public long getRecurrencePeriod() { @@ -57,7 +54,11 @@ public final class FingerprintCleanupThread extends AsyncPeriodicWork { } public static void invoke() { - theInstance.run(); + getInstance().run(); + } + + private static FingerprintCleanupThread getInstance() { + return Jenkins.getInstance().getExtensionList(AsyncPeriodicWork.class).get(FingerprintCleanupThread.class); } protected void execute(TaskListener listener) { diff --git a/core/src/main/java/hudson/model/PeriodicWork.java b/core/src/main/java/hudson/model/PeriodicWork.java index beb5883cf7..6faec3840b 100644 --- a/core/src/main/java/hudson/model/PeriodicWork.java +++ b/core/src/main/java/hudson/model/PeriodicWork.java @@ -75,7 +75,7 @@ public abstract class PeriodicWork extends SafeTimerTask implements ExtensionPoi * By default it chooses the value randomly between 0 and {@link #getRecurrencePeriod()} */ public long getInitialDelay() { - return Math.abs(new Random().nextLong())%getRecurrencePeriod(); + return Math.abs(RANDOM.nextLong())%getRecurrencePeriod(); } /** @@ -89,4 +89,6 @@ public abstract class PeriodicWork extends SafeTimerTask implements ExtensionPoi protected static final long MIN = 1000*60; protected static final long HOUR =60*MIN; protected static final long DAY = 24*HOUR; + + private static final Random RANDOM = new Random(); } diff --git a/core/src/main/java/hudson/model/Slave.java b/core/src/main/java/hudson/model/Slave.java index b5cd9cd41e..f1f67925e7 100644 --- a/core/src/main/java/hudson/model/Slave.java +++ b/core/src/main/java/hudson/model/Slave.java @@ -336,7 +336,7 @@ public abstract class Slave extends Node implements Serializable { /** * Invoked by XStream when this object is read into memory. */ - private Object readResolve() { + protected Object readResolve() { // convert the old format to the new one if (launcher == null) { launcher = (agentCommand == null || agentCommand.trim().length() == 0) diff --git a/core/src/main/java/hudson/model/WorkspaceCleanupThread.java b/core/src/main/java/hudson/model/WorkspaceCleanupThread.java index 1119d39e2f..52bf53daea 100644 --- a/core/src/main/java/hudson/model/WorkspaceCleanupThread.java +++ b/core/src/main/java/hudson/model/WorkspaceCleanupThread.java @@ -43,11 +43,8 @@ import java.util.logging.Logger; */ @Extension public class WorkspaceCleanupThread extends AsyncPeriodicWork { - private static WorkspaceCleanupThread theInstance; - public WorkspaceCleanupThread() { super("Workspace clean-up"); - theInstance = this; } public long getRecurrencePeriod() { @@ -55,7 +52,7 @@ public class WorkspaceCleanupThread extends AsyncPeriodicWork { } public static void invoke() { - theInstance.run(); + Jenkins.getInstance().getExtensionList(AsyncPeriodicWork.class).get(WorkspaceCleanupThread.class).run(); } // so that this can be easily accessed from sub-routine. diff --git a/core/src/main/java/hudson/os/solaris/ZFSProvisioner.java b/core/src/main/java/hudson/os/solaris/ZFSProvisioner.java index 78a7abb00c..5c913e592e 100644 --- a/core/src/main/java/hudson/os/solaris/ZFSProvisioner.java +++ b/core/src/main/java/hudson/os/solaris/ZFSProvisioner.java @@ -48,12 +48,10 @@ import org.jvnet.solaris.libzfs.ZFSFileSystem; * @author Kohsuke Kawaguchi */ public class ZFSProvisioner extends FileSystemProvisioner implements Serializable { - private final LibZFS libzfs = new LibZFS(); - private final Node node; + private static final LibZFS libzfs = new LibZFS(); private final String rootDataset; public ZFSProvisioner(Node node) throws IOException, InterruptedException { - this.node = node; rootDataset = node.getRootPath().act(new FileCallable() { public String invoke(File f, VirtualChannel channel) throws IOException { ZFSFileSystem fs = libzfs.getFileSystemByMountPoint(f); diff --git a/core/src/main/java/hudson/os/windows/ManagedWindowsServiceLauncher.java b/core/src/main/java/hudson/os/windows/ManagedWindowsServiceLauncher.java index 5722290c31..8e24524e58 100644 --- a/core/src/main/java/hudson/os/windows/ManagedWindowsServiceLauncher.java +++ b/core/src/main/java/hudson/os/windows/ManagedWindowsServiceLauncher.java @@ -351,7 +351,9 @@ public class ManagedWindowsServiceLauncher extends ComputerLauncher { } } + private static final Logger JINTEROP_LOGGER = Logger.getLogger("org.jinterop"); + static { - Logger.getLogger("org.jinterop").setLevel(Level.WARNING); + JINTEROP_LOGGER.setLevel(Level.WARNING); } } diff --git a/core/src/main/java/hudson/security/NotSerilizableSecurityContext.java b/core/src/main/java/hudson/security/NotSerilizableSecurityContext.java index 991bf3c5c0..aafb06fecd 100644 --- a/core/src/main/java/hudson/security/NotSerilizableSecurityContext.java +++ b/core/src/main/java/hudson/security/NotSerilizableSecurityContext.java @@ -31,7 +31,7 @@ import javax.servlet.http.HttpSession; * in Hudson. * *

- * Hudson doesn't work with a clustering anyway, and so it's better to just not persist + * Jenkins doesn't work with a clustering anyway, and so it's better to just not persist * Authentication at all. * * See http://www.nabble.com/ActiveDirectory-Plugin%3A-ClassNotFoundException-while-loading--persisted-sessions%3A-td22085140.html @@ -45,8 +45,8 @@ public class NotSerilizableSecurityContext implements SecurityContext { @Override public boolean equals(Object obj) { - if (obj instanceof SecurityContextImpl) { - SecurityContextImpl test = (SecurityContextImpl) obj; + if (obj instanceof SecurityContext) { + SecurityContext test = (SecurityContext) obj; if ((this.getAuthentication() == null) && (test.getAuthentication() == null)) { return true; diff --git a/core/src/main/java/hudson/slaves/SlaveComputer.java b/core/src/main/java/hudson/slaves/SlaveComputer.java index efb26660bb..f808256798 100644 --- a/core/src/main/java/hudson/slaves/SlaveComputer.java +++ b/core/src/main/java/hudson/slaves/SlaveComputer.java @@ -575,12 +575,11 @@ public class SlaveComputer extends Computer { // avoid double installation of the handler. JNLP slaves can reconnect to the master multiple times // and each connection gets a different RemoteClassLoader, so we need to evict them by class name, // not by their identity. - Logger logger = Logger.getLogger("hudson"); - for (Handler h : logger.getHandlers()) { + for (Handler h : LOGGER.getHandlers()) { if (h.getClass().getName().equals(SLAVE_LOG_HANDLER.getClass().getName())) - logger.removeHandler(h); + LOGGER.removeHandler(h); } - logger.addHandler(SLAVE_LOG_HANDLER); + LOGGER.addHandler(SLAVE_LOG_HANDLER); // remove Sun PKCS11 provider if present. See http://wiki.jenkins-ci.org/display/JENKINS/Solaris+Issue+6276483 try { @@ -594,6 +593,7 @@ public class SlaveComputer extends Computer { return null; } private static final long serialVersionUID = 1L; + private static final Logger LOGGER = Logger.getLogger("hudson"); } /** diff --git a/core/src/main/java/hudson/tasks/junit/JUnitResultArchiver.java b/core/src/main/java/hudson/tasks/junit/JUnitResultArchiver.java index fe86c1ad7d..294cd95313 100644 --- a/core/src/main/java/hudson/tasks/junit/JUnitResultArchiver.java +++ b/core/src/main/java/hudson/tasks/junit/JUnitResultArchiver.java @@ -68,8 +68,7 @@ import java.util.List; * * @author Kohsuke Kawaguchi */ -public class JUnitResultArchiver extends Recorder implements Serializable, - MatrixAggregatable { +public class JUnitResultArchiver extends Recorder implements MatrixAggregatable { /** * {@link FileSet} "includes" string, like "foo/bar/*.xml" diff --git a/core/src/main/java/hudson/tools/ToolInstallation.java b/core/src/main/java/hudson/tools/ToolInstallation.java index 50849a3351..ef4aea75d7 100644 --- a/core/src/main/java/hudson/tools/ToolInstallation.java +++ b/core/src/main/java/hudson/tools/ToolInstallation.java @@ -153,7 +153,7 @@ public abstract class ToolInstallation extends AbstractDescribableImpl,ToolPropertyDescriptor>(Saveable.NOOP); for (ToolProperty p : properties) diff --git a/core/src/main/java/hudson/util/ArgumentListBuilder.java b/core/src/main/java/hudson/util/ArgumentListBuilder.java index 66f7152efd..d85a740f30 100644 --- a/core/src/main/java/hudson/util/ArgumentListBuilder.java +++ b/core/src/main/java/hudson/util/ArgumentListBuilder.java @@ -43,7 +43,7 @@ import java.util.Set; * * @author Kohsuke Kawaguchi */ -public class ArgumentListBuilder implements Serializable { +public class ArgumentListBuilder implements Serializable, Cloneable { private final List args = new ArrayList(); /** * Bit mask indicating arguments that shouldn't be echoed-back (e.g., password) diff --git a/core/src/main/java/hudson/util/PluginServletFilter.java b/core/src/main/java/hudson/util/PluginServletFilter.java index 946cb4395c..0decb8f541 100644 --- a/core/src/main/java/hudson/util/PluginServletFilter.java +++ b/core/src/main/java/hudson/util/PluginServletFilter.java @@ -58,6 +58,7 @@ public class PluginServletFilter implements Filter, ExtensionPoint { public PluginServletFilter() { } + @edu.umd.cs.findbugs.annotations.SuppressWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD") public void init(FilterConfig filterConfig) throws ServletException { PluginServletFilter.filterConfig = filterConfig; synchronized (LIST) { diff --git a/core/src/main/java/jenkins/model/Jenkins.java b/core/src/main/java/jenkins/model/Jenkins.java index 13c1584bf7..9581459cf4 100644 --- a/core/src/main/java/jenkins/model/Jenkins.java +++ b/core/src/main/java/jenkins/model/Jenkins.java @@ -666,6 +666,7 @@ public class Jenkins extends AbstractCIBase implements ModifiableItemGroup