From 07cd34412309253486dfb4d411c73695c783a829 Mon Sep 17 00:00:00 2001 From: Sxtanna Date: Sat, 25 Jul 2020 23:55:17 -0400 Subject: [PATCH] updated local expansion to not catch potential linkage errors, and report them. closes #377 --- .../manager/LocalExpansionManager.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/java/me/clip/placeholderapi/expansion/manager/LocalExpansionManager.java b/src/main/java/me/clip/placeholderapi/expansion/manager/LocalExpansionManager.java index 50c39f5..a9088b9 100644 --- a/src/main/java/me/clip/placeholderapi/expansion/manager/LocalExpansionManager.java +++ b/src/main/java/me/clip/placeholderapi/expansion/manager/LocalExpansionManager.java @@ -229,13 +229,23 @@ public final class LocalExpansionManager implements Listener public Optional register(@NotNull final Class clazz) { - final PlaceholderExpansion expansion = createExpansionInstance(clazz); - if (expansion == null || !expansion.register()) + try { - return Optional.empty(); + final PlaceholderExpansion expansion = createExpansionInstance(clazz); + if (expansion == null || !expansion.register()) + { + return Optional.empty(); + } + + return Optional.of(expansion); + } + catch (final LinkageError ex) + { + plugin.getLogger().severe("expansion class " + clazz.getSimpleName() + " is outdated: \n" + + "Failed to load due to a [" + ex.getClass().getSimpleName() + "], attempted to use " + ex.getMessage()); } - return Optional.of(expansion); + return Optional.empty(); } public boolean unregister(@NotNull final PlaceholderExpansion expansion) @@ -347,13 +357,13 @@ public final class LocalExpansionManager implements Listener @Nullable - public PlaceholderExpansion createExpansionInstance(@NotNull final Class clazz) + public PlaceholderExpansion createExpansionInstance(@NotNull final Class clazz) throws LinkageError { try { return clazz.getDeclaredConstructor().newInstance(); } - catch (final Throwable ex) + catch (final Exception ex) { plugin.getLogger().log(Level.SEVERE, "Failed to load placeholder expansion from class: " + clazz.getName(), ex); return null;