Skip to content

Commit

Permalink
fix #2940864 - Exception when clicking Find orphan
Browse files Browse the repository at this point in the history
more robust loading of XML resources for plugin (don't try to read from
null InputStream, log a message)

git-svn-id: https://jedit.svn.sourceforge.net/svnroot/jedit/jEdit/trunk@22920 6b1eeb88-9816-0410-afa2-b43733a0f04e
  • Loading branch information
kerik-sf committed Apr 6, 2013
1 parent d28cd12 commit ba03ed1
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 19 deletions.
2 changes: 2 additions & 0 deletions doc/CHANGES.txt
Expand Up @@ -88,6 +88,8 @@ Makarius, Marco Hunsicker, and Maik Nijhuis for contributing to this release.
- When checking a box to select a plugin to install, the description was
appearing and immediately disappearing. (#3398605 Dale Anson)

- Fix Exception when clicking Find orphan when disabled plugins (#2940864 Eric
Le Lay)
}}}
{{{ API Changes

Expand Down
13 changes: 12 additions & 1 deletion org/gjt/sp/jedit/JEditActionSet.java
Expand Up @@ -380,7 +380,18 @@ public void load()
{
Log.log(Log.DEBUG,this,"Loading actions from " + uri);
ActionListHandler ah = new ActionListHandler(uri.toString(),this);
if ( XMLUtilities.parseXML(uri.openStream(), ah))
InputStream in = uri.openStream();
if(in == null)
{
// this happened when calling generateCache() in the context of 'find orphan jars'
// in org.gjt.sp.jedit.pluginmgr.ManagePanel.FindOrphan.actionPerformed(ActionEvent)
// because for not loaded plugins, the plugin will not be added to the list of pluginJars
// so the org.gjt.sp.jedit.proto.jeditresource.PluginResURLConnection will not find the plugin
// to read the resource from.
// Better log a small error message than a big stack trace
Log.log(Log.WARNING, this, "Unable to open: " + uri);
}
else if ( XMLUtilities.parseXML(in, ah))
{
Log.log(Log.ERROR, this, "Unable to parse: " + uri);
}
Expand Down
8 changes: 8 additions & 0 deletions org/gjt/sp/jedit/PluginJAR.java
Expand Up @@ -1445,6 +1445,14 @@ else if(name.endsWith(".class"))
}
}

boolean isBeingLoaded = jEdit.getPluginJAR(getPath()) != null;
if(!isBeingLoaded)
{
Log.log(Log.DEBUG, PluginJAR.class,
"not loading actions, dockables, services "
+"because the plugin is not really being loaded");
return cache;
}
if(cache.actionsURI != null)
{
actions = new ActionSet(this,null,null,
Expand Down
13 changes: 12 additions & 1 deletion org/gjt/sp/jedit/ServiceManager.java
Expand Up @@ -109,7 +109,18 @@ public static void loadServices(PluginJAR plugin, URL uri,
ServiceListHandler dh = new ServiceListHandler(plugin,uri);
try
{
if (!XMLUtilities.parseXML(uri.openStream(), dh)
InputStream in = uri.openStream();
if(in == null)
{
// this happened when calling generateCache() in the context of 'find orphan jars'
// in org.gjt.sp.jedit.pluginmgr.ManagePanel.FindOrphan.actionPerformed(ActionEvent)
// because for not loaded plugins, the plugin will not be added to the list of pluginJars
// so the org.gjt.sp.jedit.proto.jeditresource.PluginResURLConnection will not find the plugin
// to read the resource from.
// Better log a small error message than a big stack trace
Log.log(Log.WARNING, ServiceManager.class, "Unable to open: " + uri);
}
else if (!XMLUtilities.parseXML(uri.openStream(), dh)
&& cache != null)
{
cache.cachedServices = dh.getCachedServices();
Expand Down
27 changes: 21 additions & 6 deletions org/gjt/sp/jedit/gui/DockableWindowFactory.java
Expand Up @@ -25,6 +25,7 @@
//{{{ Imports
import java.awt.Color;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.HashMap;
import java.util.Iterator;
Expand Down Expand Up @@ -90,13 +91,27 @@ public void loadDockableWindows(PluginJAR plugin, URL uri,
Log.log(Log.DEBUG,DockableWindowManager.class,
"Loading dockables from " + uri);
DockableListHandler dh = new DockableListHandler(plugin,uri);
boolean failure = XMLUtilities.parseXML(uri.openStream(), dh);

if (!failure && cache != null)
InputStream in = uri.openStream();
if(in == null)
{
// this happened when calling generateCache() in the context of 'find orphan jars'
// in org.gjt.sp.jedit.pluginmgr.ManagePanel.FindOrphan.actionPerformed(ActionEvent)
// because for not loaded plugins, the plugin will not be added to the list of pluginJars
// so the org.gjt.sp.jedit.proto.jeditresource.PluginResURLConnection will not find the plugin
// to read the resource from.
// Better log a small error message than a big stack trace
Log.log(Log.WARNING, this, "Unable to open: " + uri);
}
else
{
cache.cachedDockableNames = dh.getCachedDockableNames();
cache.cachedDockableActionFlags = dh.getCachedDockableActionFlags();
cache.cachedDockableMovableFlags = dh.getCachedDockableMovableFlags();
boolean failure = XMLUtilities.parseXML(in, dh);

if (!failure && cache != null)
{
cache.cachedDockableNames = dh.getCachedDockableNames();
cache.cachedDockableActionFlags = dh.getCachedDockableActionFlags();
cache.cachedDockableMovableFlags = dh.getCachedDockableMovableFlags();
}
}
}
catch(IOException e)
Expand Down
43 changes: 32 additions & 11 deletions org/gjt/sp/jedit/pluginmgr/ManagePanel.java
Expand Up @@ -267,19 +267,31 @@ private static Collection<String> getDeclaredJars(String jarName) throws IOExcep
{
pluginCacheEntry = pluginJAR.generateCache();
}
Properties cachedProperties = pluginCacheEntry.cachedProperties;
if(pluginCacheEntry == null)
{
// this happens when, for some reason, two versions
// of a plugin are installed, e.g when XSLT.jar and
// xslt.jar are both in $JEDIT_HOME/jars on Linux.
Log.log(Log.WARNING, ManagePanel.class,
"couldn't load plugin "+pluginJAR.getPath()
+" (most likely other version exists)");
}
else
{
Properties cachedProperties = pluginCacheEntry.cachedProperties;

String jars = cachedProperties.getProperty("plugin." + pluginCacheEntry.pluginClass + ".jars");
String jars = cachedProperties.getProperty("plugin." + pluginCacheEntry.pluginClass + ".jars");

if (jars != null)
{
String dir = MiscUtilities.getParentOfPath(pluginJAR.getPath());
StringTokenizer st = new StringTokenizer(jars);
while (st.hasMoreTokens())
if (jars != null)
{
String _jarPath = MiscUtilities.constructPath(dir, st.nextToken());
if (new File(_jarPath).exists())
jarList.add(_jarPath);
String dir = MiscUtilities.getParentOfPath(pluginJAR.getPath());
StringTokenizer st = new StringTokenizer(jars);
while (st.hasMoreTokens())
{
String _jarPath = MiscUtilities.constructPath(dir, st.nextToken());
if (new File(_jarPath).exists())
jarList.add(_jarPath);
}
}
}
jarList.add(jarName);
Expand Down Expand Up @@ -1030,7 +1042,16 @@ public void actionPerformed(ActionEvent e)
{
pluginCacheEntry = pluginJAR.generateCache();
}
if (pluginCacheEntry.pluginClass == null)
if(pluginCacheEntry == null)
{
// this happens when, for some reason, two versions
// of a plugin are installed, e.g when XSLT.jar and
// xslt.jar are both in $JEDIT_HOME/jars on Linux.
Log.log(Log.WARNING, ManagePanel.class,
"couldn't load plugin "+pluginJAR.getPath()
+" (most likely other version exists)");
}
if (pluginCacheEntry == null || pluginCacheEntry.pluginClass == null)
{
// Not a plugin
jarlibs.put(new File(notLoadedJars[i]).getName(), notLoadedJars[i]);
Expand Down
Expand Up @@ -33,6 +33,8 @@
import org.gjt.sp.jedit.MiscUtilities;
import org.gjt.sp.jedit.PluginJAR;
import org.gjt.sp.jedit.jEdit;

import org.gjt.sp.util.Log;
//}}}

//{{{ class PluginResURLConnection
Expand Down Expand Up @@ -79,17 +81,24 @@ public void connect() throws IOException
}
else
{
boolean pluginFoundInPluginJARs = false;
PluginJAR[] plugins = jEdit.getPluginJARs();
for(int i = 0; i < plugins.length; i++)
{
PluginJAR jar = plugins[i];
String jarName =MiscUtilities.getFileName(jar.getPath()).toLowerCase();
if(plugin.equalsIgnoreCase(jarName))
{
pluginFoundInPluginJARs = true;
in = jar.getClassLoader().getResourceAsStream(resource);
break;
}
}
if(!pluginFoundInPluginJARs){
Log.log(Log.DEBUG, PluginResURLConnection.class,
"reading resource from not loaded plugin "
+" => will always fail !");
}
}

if((in == null) && (plugin == null))
Expand Down

0 comments on commit ba03ed1

Please sign in to comment.