From aaa03b1cde9595afacfecd1a24e4540eda40a02a Mon Sep 17 00:00:00 2001 From: Luck Date: Wed, 15 May 2019 17:02:27 +0100 Subject: Add try..catch around the parsing of each heap dump summary entry --- .../java/me/lucko/spark/bukkit/CommandMapUtil.java | 32 ++++++---------------- 1 file changed, 8 insertions(+), 24 deletions(-) (limited to 'spark-bukkit/src') diff --git a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/CommandMapUtil.java b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/CommandMapUtil.java index 08d65df..66a1568 100644 --- a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/CommandMapUtil.java +++ b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/CommandMapUtil.java @@ -51,32 +51,16 @@ public final class CommandMapUtil { private static final Field KNOWN_COMMANDS_FIELD; static { - Constructor commandConstructor; try { - commandConstructor = PluginCommand.class.getDeclaredConstructor(String.class, Plugin.class); - commandConstructor.setAccessible(true); - } catch (NoSuchMethodException e) { - throw new RuntimeException(e); + COMMAND_CONSTRUCTOR = PluginCommand.class.getDeclaredConstructor(String.class, Plugin.class); + COMMAND_CONSTRUCTOR.setAccessible(true); + COMMAND_MAP_FIELD = SimplePluginManager.class.getDeclaredField("commandMap"); + COMMAND_MAP_FIELD.setAccessible(true); + KNOWN_COMMANDS_FIELD = SimpleCommandMap.class.getDeclaredField("knownCommands"); + KNOWN_COMMANDS_FIELD.setAccessible(true); + } catch (NoSuchMethodException | NoSuchFieldException e) { + throw new ExceptionInInitializerError(e); } - COMMAND_CONSTRUCTOR = commandConstructor; - - Field commandMapField; - try { - commandMapField = SimplePluginManager.class.getDeclaredField("commandMap"); - commandMapField.setAccessible(true); - } catch (NoSuchFieldException e) { - throw new RuntimeException(e); - } - COMMAND_MAP_FIELD = commandMapField; - - Field knownCommandsField; - try { - knownCommandsField = SimpleCommandMap.class.getDeclaredField("knownCommands"); - knownCommandsField.setAccessible(true); - } catch (NoSuchFieldException e) { - throw new RuntimeException(e); - } - KNOWN_COMMANDS_FIELD = knownCommandsField; } private static CommandMap getCommandMap() { -- cgit