From d8a7d8de4abbf57d477026316f33acbef83167db Mon Sep 17 00:00:00 2001 From: Luck Date: Fri, 4 May 2018 21:27:57 +0100 Subject: [PATCH] Throw a more detailed error when database connection info is missing --- .../dependencies/classloader/IsolatedClassLoader.java | 2 +- .../luckperms/common/storage/StorageCredentials.java | 9 +++++---- .../luckperms/common/treeview/PermissionRegistry.java | 2 +- .../me/lucko/luckperms/common/treeview/TreeNode.java | 6 +++++- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/common/src/main/java/me/lucko/luckperms/common/dependencies/classloader/IsolatedClassLoader.java b/common/src/main/java/me/lucko/luckperms/common/dependencies/classloader/IsolatedClassLoader.java index 2f3ebac3..ff32c7a0 100644 --- a/common/src/main/java/me/lucko/luckperms/common/dependencies/classloader/IsolatedClassLoader.java +++ b/common/src/main/java/me/lucko/luckperms/common/dependencies/classloader/IsolatedClassLoader.java @@ -44,7 +44,7 @@ public class IsolatedClassLoader extends URLClassLoader { * ClassLoader#getSystemClassLoader returns the AppClassLoader * * Calling #getParent on this returns the ExtClassLoader (Java 8) or - * the PlatformClassLoader (Java 8). Since we want this classloader to + * the PlatformClassLoader (Java 9). Since we want this classloader to * be isolated from the Minecraft server (the app), we set the parent * to be the platform class loader. */ diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/StorageCredentials.java b/common/src/main/java/me/lucko/luckperms/common/storage/StorageCredentials.java index f888fbcc..39d33f9c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/StorageCredentials.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/StorageCredentials.java @@ -26,6 +26,7 @@ package me.lucko.luckperms.common.storage; import java.util.Map; +import java.util.Objects; public class StorageCredentials { @@ -52,19 +53,19 @@ public class StorageCredentials { } public String getAddress() { - return this.address; + return Objects.requireNonNull(this.address, "address"); } public String getDatabase() { - return this.database; + return Objects.requireNonNull(this.database, "database"); } public String getUsername() { - return this.username; + return Objects.requireNonNull(this.username, "username"); } public String getPassword() { - return this.password; + return Objects.requireNonNull(this.password, "password"); } public int getMaxPoolSize() { diff --git a/common/src/main/java/me/lucko/luckperms/common/treeview/PermissionRegistry.java b/common/src/main/java/me/lucko/luckperms/common/treeview/PermissionRegistry.java index 568d7855..b58b843a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/treeview/PermissionRegistry.java +++ b/common/src/main/java/me/lucko/luckperms/common/treeview/PermissionRegistry.java @@ -111,7 +111,7 @@ public class PermissionRegistry extends RepeatingTask { // insert the permission into the node structure TreeNode current = this.rootNode; for (String part : parts) { - current = current.getChildMap().computeIfAbsent(part, s -> new TreeNode()); + current = current.resolve(part); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/treeview/TreeNode.java b/common/src/main/java/me/lucko/luckperms/common/treeview/TreeNode.java index 2b743068..3ef500cd 100644 --- a/common/src/main/java/me/lucko/luckperms/common/treeview/TreeNode.java +++ b/common/src/main/java/me/lucko/luckperms/common/treeview/TreeNode.java @@ -38,13 +38,17 @@ public class TreeNode { private Map children = null; // lazy init - public synchronized Map getChildMap() { + private synchronized Map getChildMap() { if (this.children == null) { this.children = new ConcurrentHashMap<>(); } return this.children; } + public TreeNode resolve(String s) { + return getChildMap().computeIfAbsent(s, x -> new TreeNode()); + } + public Optional> getChildren() { return Optional.ofNullable(this.children); }