From 2cefdcca3f6ea69b5bc85ec8ffd93bc645fea59f Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 14 Jun 2020 02:13:15 -0700 Subject: [PATCH] Adds stack trace to onLoad if there's a LinkageError (#1399) Fixes https://github.com/BentoBoxWorld/BentoBox/issues/1362 There was already one for onEnable. This just adds the same to onLoad, which was missing. --- .../bentobox/api/addons/AddonClassLoader.java | 2 +- .../bentobox/bentobox/managers/AddonsManager.java | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/api/addons/AddonClassLoader.java b/src/main/java/world/bentobox/bentobox/api/addons/AddonClassLoader.java index 8c99d8332..f69718190 100644 --- a/src/main/java/world/bentobox/bentobox/api/addons/AddonClassLoader.java +++ b/src/main/java/world/bentobox/bentobox/api/addons/AddonClassLoader.java @@ -71,7 +71,7 @@ public class AddonClassLoader extends URLClassLoader { /** - * Convers the addon.yml to an AddonDescription + * Converts the addon.yml to an AddonDescription * @param data - yaml config (addon.yml) * @return Addon Description * @throws InvalidAddonDescriptionException - if there's a bug in the addon.yml diff --git a/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java b/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java index 76ffdb121..59a08cbb1 100644 --- a/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java +++ b/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java @@ -162,7 +162,7 @@ public class AddonsManager { addon.setState(Addon.State.LOADED); } catch (NoClassDefFoundError | NoSuchMethodError | NoSuchFieldError e) { // Looks like the addon is incompatible, because it tries to refer to missing classes... - handleAddonIncompatibility(addon); + handleAddonIncompatibility(addon, e); } catch (Exception e) { // Unhandled exception. We'll give a bit of debug here. handleAddonError(addon, e); @@ -248,10 +248,7 @@ public class AddonsManager { addon.setState(Addon.State.ENABLED); } catch (NoClassDefFoundError | NoSuchMethodError | NoSuchFieldError e) { // Looks like the addon is incompatible, because it tries to refer to missing classes... - handleAddonIncompatibility(addon); - StringBuilder a = new StringBuilder(); - addon.getDescription().getAuthors().forEach(author -> a.append(author).append(" ")); - plugin.getLogger().log(Level.SEVERE, "Please report this stack trace to the addon's author(s): " + a.toString(), e); + handleAddonIncompatibility(addon, e); } catch (Exception e) { // Unhandled exception. We'll give a bit of debug here. handleAddonError(addon, e); @@ -261,14 +258,19 @@ public class AddonsManager { /** * Handles an addon which failed to load due to an incompatibility (missing class, missing method). * @param addon instance of the Addon. + * @param e * @since 1.1 */ - private void handleAddonIncompatibility(@NonNull Addon addon) { + private void handleAddonIncompatibility(@NonNull Addon addon, LinkageError e) { // Set the AddonState as "INCOMPATIBLE". addon.setState(Addon.State.INCOMPATIBLE); plugin.logWarning("Skipping " + addon.getDescription().getName() + " as it is incompatible with the current version of BentoBox or of server software..."); plugin.logWarning("NOTE: The addon is referring to no longer existing classes."); plugin.logWarning("NOTE: DO NOT report this as a bug from BentoBox."); + StringBuilder a = new StringBuilder(); + addon.getDescription().getAuthors().forEach(author -> a.append(author).append(" ")); + plugin.getLogger().log(Level.SEVERE, "Please report this stack trace to the addon's author(s): " + a.toString(), e); + } private boolean isAddonCompatibleWithBentoBox(@NonNull Addon addon) {