From e76b940561d4a764cecb2cb11b8ed11b90aa7efe Mon Sep 17 00:00:00 2001 From: kohsuke Date: Tue, 24 Feb 2009 00:03:48 +0000 Subject: [PATCH] bug fix in the load order handling. Until all the plugins are loaded, we cannot start the discovery process, so if the list view is requested before that, just return the list of legacy instances as an approximation. The current plugin code shouldn't expect the DescriptorList to be fully populated until all the plugins are loaded anyway, so this partial visibility isn't any different from what they currently see. OTOH, this prevents NPE in ExtensionFinder.Sezpoz when it tries to get the uber classloader. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@15606 71c3de6d-444a-0410-be80-ed276b4c234a --- core/src/main/java/hudson/ExtensionList.java | 32 +++++++++++--------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/hudson/ExtensionList.java b/core/src/main/java/hudson/ExtensionList.java index 219bff5901..8c0a3ed870 100644 --- a/core/src/main/java/hudson/ExtensionList.java +++ b/core/src/main/java/hudson/ExtensionList.java @@ -34,7 +34,6 @@ import java.util.Iterator; import java.util.List; import java.util.Vector; import java.util.concurrent.CopyOnWriteArrayList; -import java.util.logging.Logger; /** * Retains the known extension instances for the given type 'T'. @@ -81,8 +80,7 @@ public class ExtensionList extends AbstractCollection { private final List listView = new AbstractList() { @Override public T get(int index) { - ensureLoaded(); - return extensions.get(index); + return ensureLoaded().get(index); } @Override @@ -96,11 +94,17 @@ public class ExtensionList extends AbstractCollection { } @Override - public void add(int index, T element) { - legacyInstances.add(element); + public boolean add(T t) { + legacyInstances.add(t); // if we've already filled extensions, add it if(extensions!=null) - extensions.add(element); + extensions.add(t); + return true; + } + + @Override + public void add(int index, T element) { + add(element); } }; @@ -133,13 +137,11 @@ public class ExtensionList extends AbstractCollection { } public Iterator iterator() { - ensureLoaded(); - return extensions.iterator(); + return ensureLoaded().iterator(); } public int size() { - ensureLoaded(); - return extensions.size(); + return ensureLoaded().size(); } /** @@ -149,15 +151,19 @@ public class ExtensionList extends AbstractCollection { return hudson.getExtensionList(ExtensionFinder.class); } - private void ensureLoaded() { + private List ensureLoaded() { if(extensions!=null) - return; // already loaded + return extensions; // already loaded + if(Hudson.getInstance().getPluginManager()==null) + return legacyInstances; // can't perform the auto discovery until all plugins are loaded, so just make the legacy instances visisble + synchronized (this) { if(extensions==null) { List r = load(); r.addAll(legacyInstances); extensions = new CopyOnWriteArrayList(r); } + return extensions; } } @@ -198,6 +204,4 @@ public class ExtensionList extends AbstractCollection { }; return new ExtensionList(hudson,type); } - - private static final Logger LOGGER = Logger.getLogger(ExtensionList.class.getName()); }