[FIXED JENKINS-8866] Look for Descriptor.getId()==null and warn the administrator

This commit is contained in:
Kohsuke Kawaguchi committed 2011-03-08 11:04:00 -08:00
1 parent 51770129bb
commit 229f536cba
7 files changed
+141 -2

No files matched your search

@@ -455,6 +455,20 @@ public abstract class PluginManager extends AbstractModelObject {
return result;
}
/**
* Return the {@link PluginWrapper} that loaded the given class 'c'.
*
* @since 1.402.
*/
public PluginWrapper whichPlugin(Class c) {
ClassLoader cl = c.getClassLoader();
for (PluginWrapper p : activePlugins) {
if (p.classLoader==cl)
return p;
}
return null;
}
/**
* Orderly terminates all the plugins.
*/
@@ -0,0 +1,80 @@
/*
* The MIT License
*
* Copyright (c) 2011, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package hudson.diagnosis;
import hudson.Extension;
import hudson.PluginWrapper;
import hudson.init.Initializer;
import hudson.model.AdministrativeMonitor;
import hudson.model.Descriptor;
import hudson.model.Hudson;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.logging.Logger;
import static hudson.init.InitMilestone.EXTENSIONS_AUGMENTED;
/**
* Some old descriptors apparently has the getId() method that's used in different ways
* and that's causing errors like JENKINS-8866, so detect and report that.
*
* @author Kohsuke Kawaguchi
* @since 1.402
*/
@Extension
public class NullIdDescriptorMonitor extends AdministrativeMonitor {
private final List<Descriptor> problems = new ArrayList<Descriptor>();
@Override
public boolean isActivated() {
return !problems.isEmpty();
}
public List<Descriptor> getProblems() {
return Collections.unmodifiableList(problems);
}
private void verify() {
Hudson h = Hudson.getInstance();
for (Descriptor d : h.getExtensionList(Descriptor.class)) {
if (d.getId()==null) {
PluginWrapper p = h.getPluginManager().whichPlugin(d.getClass());
LOGGER.severe(MessageFormat.format("Descriptor {0} from plugin {1} with display name {2} has null ID",
d, p==null?"???":p.getLongName(), d.getDisplayName()));
problems.add(d);
}
}
}
@Initializer(after=EXTENSIONS_AUGMENTED)
public static void verifyId() {
AdministrativeMonitor.all().get(NullIdDescriptorMonitor.class).verify();
}
private static final Logger LOGGER = Logger.getLogger(NullIdDescriptorMonitor.class.getName());
}
@@ -30,6 +30,8 @@ import hudson.BulkChange;
import hudson.Util;
import static hudson.Functions.jsStringEscape;
import hudson.diagnosis.OldDataMonitor;
import hudson.init.InitMilestone;
import hudson.init.Initializer;
import hudson.model.listeners.SaveableListener;
import hudson.util.ReflectionUtils;
import hudson.util.ReflectionUtils.Parameter;
@@ -41,12 +43,14 @@ import org.springframework.util.StringUtils;
import org.jvnet.tiger_types.Types;
import org.apache.commons.io.IOUtils;
import static hudson.init.InitMilestone.EXTENSIONS_AUGMENTED;
import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND;
import javax.servlet.ServletException;
import javax.servlet.RequestDispatcher;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
+1 -1
View File
@@ -1682,7 +1682,7 @@ public final class Hudson extends Node implements ItemGroup<TopLevelItem>, Stapl
public static final DescriptorImpl INSTANCE = new DescriptorImpl();
public String getDisplayName() {
throw new UnsupportedOperationException();
return "";
}
@Override