aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--spark-bukkit/src/main/java/me/lucko/spark/bukkit/CommandMapUtil.java32
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/heapdump/HeapDumpSummary.java17
2 files changed, 19 insertions, 30 deletions
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<PluginCommand> 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() {
diff --git a/spark-common/src/main/java/me/lucko/spark/common/heapdump/HeapDumpSummary.java b/spark-common/src/main/java/me/lucko/spark/common/heapdump/HeapDumpSummary.java
index 6021d92..867dcc6 100644
--- a/spark-common/src/main/java/me/lucko/spark/common/heapdump/HeapDumpSummary.java
+++ b/spark-common/src/main/java/me/lucko/spark/common/heapdump/HeapDumpSummary.java
@@ -90,12 +90,17 @@ public final class HeapDumpSummary {
return null;
}
- return new Entry(
- Integer.parseInt(matcher.group(1)),
- Integer.parseInt(matcher.group(2)),
- Long.parseLong(matcher.group(3)),
- TypeDescriptors.getJavaType(matcher.group(4))
- );
+ try {
+ return new Entry(
+ Integer.parseInt(matcher.group(1)),
+ Integer.parseInt(matcher.group(2)),
+ Long.parseLong(matcher.group(3)),
+ TypeDescriptors.getJavaType(matcher.group(4))
+ );
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
})
.filter(Objects::nonNull)
.collect(Collectors.toList()));