mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-10-28 12:05:19 +00:00
Better null safety.
Defense against an exception consistently thrown when running functional tests against 1.532.1 (but not 1.540, for whatever reason): … hudson.PluginWrapper stop WARNING: Failed to shut down … java.lang.NullPointerException at jenkins.model.Jenkins.lookup(Jenkins.java:3898) at hudson.PluginWrapper.getPlugin(PluginWrapper.java:287) at hudson.PluginWrapper.stop(PluginWrapper.java:377) at hudson.PluginManager.stop(PluginManager.java:650) at org.jvnet.hudson.test.TestPluginManager.reallyStop(TestPluginManager.java:129) at org.jvnet.hudson.test.TestPluginManager.access$000(TestPluginManager.java:55) at org.jvnet.hudson.test.TestPluginManager$1.run(TestPluginManager.java:140)
This commit is contained in:
1 parent
90395ee695
commit
6586d779b1
2 files changed
+18
-10
No files matched your search
@@ -55,6 +55,7 @@ import org.kohsuke.stapler.interceptor.RequirePOST;
|
||||
import java.util.Enumeration;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.logging.Level;
|
||||
import javax.annotation.CheckForNull;
|
||||
|
||||
/**
|
||||
* Represents a Jenkins plug-in and associated control information
|
||||
@@ -284,8 +285,9 @@ public class PluginWrapper implements Comparable<PluginWrapper>, ModelObject {
|
||||
/**
|
||||
* Gets the instance of {@link Plugin} contributed by this plugin.
|
||||
*/
|
||||
public Plugin getPlugin() {
|
||||
return Jenkins.lookup(PluginInstanceStore.class).store.get(this);
|
||||
public @CheckForNull Plugin getPlugin() {
|
||||
PluginInstanceStore pis = Jenkins.lookup(PluginInstanceStore.class);
|
||||
return pis != null ? pis.store.get(this) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -373,11 +375,16 @@ public class PluginWrapper implements Comparable<PluginWrapper>, ModelObject {
|
||||
* Terminates the plugin.
|
||||
*/
|
||||
public void stop() {
|
||||
LOGGER.log(Level.FINE, "Stopping {0}", shortName);
|
||||
try {
|
||||
getPlugin().stop();
|
||||
} catch(Throwable t) {
|
||||
LOGGER.log(WARNING, "Failed to shut down "+shortName, t);
|
||||
Plugin plugin = getPlugin();
|
||||
if (plugin != null) {
|
||||
try {
|
||||
LOGGER.log(Level.FINE, "Stopping {0}", shortName);
|
||||
plugin.stop();
|
||||
} catch (Throwable t) {
|
||||
LOGGER.log(WARNING, "Failed to shut down " + shortName, t);
|
||||
}
|
||||
} else {
|
||||
LOGGER.log(Level.FINE, "Could not find Plugin instance to stop for {0}", shortName);
|
||||
}
|
||||
// Work around a bug in commons-logging.
|
||||
// See http://www.szegedi.org/articles/memleak.html
|
||||
|
||||
Reference in new issue
Block a user