diff --git a/core/pom.xml b/core/pom.xml index 11d7648919af9612467e85ba0d6080aee0968293..35ff031eef5f5dbe8238366b53afe4c5e9f739a7 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 0d8254b1f314464942655463fd6a29948d4150da..751d3fa8a5d470e36e579dd1169bcd88ea649507 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 bb5095632f771bc0f4abc6970af3c6a4023f3e3c..722b0391b5a1c09c616344aca51f2e0f9d853fd4 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 8bef506b45b9773e2854e2d3f1a42d1265ff54c1..af67eaa3ea716c29ec5f55f91d96f00c48f7e2b1 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 9e1f22c8e77269c24d9460c4bd0aee2551ef02fa..3ceff0a419bfbe2ca3dec5c07927259dc2d15ba0 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 e10696531bf7f703617c230c16db2378817696a3..bccb84b8eaba69c384a102242f3352e0e9e1f0a9 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 348bd8ffffa5e5a14c827e574b341736ff1418a3..e70037ab57e31b087b5942808920263da5c436f6 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 beb5883cf71c50f8bc54ce039abe232eb3975175..6faec3840b538e0b3557dc4aa48abf91e45a657d 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 b5cd9cd41e7fe74efba44c0cda9430cb82e67982..f1f67925e70e9c186edf723881aaee59aa033e37 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 1119d39e2ff4e0a9ba99ab1e15e97834751a164c..52bf53daeaab9fb0dfbc44c5760c8db0849abcda 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 78a7abb00cf794a84d60d720434ce57eb2c7123e..5c913e592e0c46e30f91b2b9de7b60ba87b494a6 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 5722290c312a054425e437e2cdb1f9896fd0abc2..8e24524e58ce101db0f741db76183dd343f66318 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 991bf3c5c03ebf0308403a758a02531cb21eda43..aafb06fecd5510c6e72a69550ead3b6d60ce5b12 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 efb26660bb73ce6217f935ef4754e341742ce160..f808256798732f10ebe614a33ea76d23f4112c87 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 fe86c1ad7d4e3479405a6b6a097db5d887918d99..294cd953131dd2825dc82a0e765ada23346fce7a 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 50849a3351e56f848ff6ca061e4dff18f72a8b59..ef4aea75d778a58fc5e48e44daaf815da3cc50d1 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 66f7152efd6446104169e98529ee13cc5e86f9ae..d85a740f30b7b41cf99ed9a07b9ac91c0e028073 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 946cb4395c1a21e83bc5162858545ec1bc34575d..0decb8f541f4b7175023ea68e5678f51e4d84288 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 13c1584bf7edc0cdc9aac742be5485f043e07f54..9581459cf4758eb65fc98687b235d0f8e78bac31 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