PluginManager: try/catch Throwable all the plugin startup stuff

If you loaded an external plugin that throws LinkageErrors it could
cause the client not to start
This commit is contained in:
Max Weber
2020-02-13 09:55:19 -07:00
parent 9d908110b8
commit e7679a8700
2 changed files with 46 additions and 13 deletions

View File

@@ -305,7 +305,11 @@ public class ExternalPluginManager
}); });
} }
} }
catch (Exception e) catch (ThreadDeath e)
{
throw e;
}
catch (Throwable e)
{ {
log.warn("Unable to start or load external plugin \"{}\"", manifest.getInternalName(), e); log.warn("Unable to start or load external plugin \"{}\"", manifest.getInternalName(), e);
if (newPlugins != null) if (newPlugins != null)

View File

@@ -160,17 +160,27 @@ public class PluginManager
public Config getPluginConfigProxy(Plugin plugin) public Config getPluginConfigProxy(Plugin plugin)
{ {
final Injector injector = plugin.getInjector(); try
for (Key<?> key : injector.getAllBindings().keySet())
{ {
Class<?> type = key.getTypeLiteral().getRawType(); final Injector injector = plugin.getInjector();
if (Config.class.isAssignableFrom(type))
for (Key<?> key : injector.getAllBindings().keySet())
{ {
return (Config) injector.getInstance(key); Class<?> type = key.getTypeLiteral().getRawType();
if (Config.class.isAssignableFrom(type))
{
return (Config) injector.getInstance(key);
}
} }
} }
catch (ThreadDeath e)
{
throw e;
}
catch (Throwable e)
{
log.warn("Unable to get plugin config", e);
}
return null; return null;
} }
@@ -203,9 +213,20 @@ public class PluginManager
public void loadDefaultPluginConfiguration(Collection<Plugin> plugins) public void loadDefaultPluginConfiguration(Collection<Plugin> plugins)
{ {
for (Object config : getPluginConfigProxies(plugins)) try
{ {
configManager.setDefaultConfiguration(config, false); for (Object config : getPluginConfigProxies(plugins))
{
configManager.setDefaultConfiguration(config, false);
}
}
catch (ThreadDeath e)
{
throw e;
}
catch (Throwable ex)
{
log.warn("Unable to reset plugin configuration", ex);
} }
} }
@@ -367,7 +388,11 @@ public class PluginManager
schedule(plugin); schedule(plugin);
eventBus.post(new PluginChanged(plugin, true)); eventBus.post(new PluginChanged(plugin, true));
} }
catch (Exception ex) catch (ThreadDeath e)
{
throw e;
}
catch (Throwable ex)
{ {
throw new PluginInstantiationException(ex); throw new PluginInstantiationException(ex);
} }
@@ -440,9 +465,13 @@ public class PluginManager
Plugin plugin; Plugin plugin;
try try
{ {
plugin = clazz.newInstance(); plugin = clazz.getDeclaredConstructor().newInstance();
} }
catch (InstantiationException | IllegalAccessException ex) catch (ThreadDeath e)
{
throw e;
}
catch (Throwable ex)
{ {
throw new PluginInstantiationException(ex); throw new PluginInstantiationException(ex);
} }