Better null checking in HikariConnectionFactory (#1408)

This commit is contained in:
Luck 2019-01-30 16:23:13 +00:00
parent 22252fa46d
commit 83db00aef8
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
2 changed files with 9 additions and 3 deletions

View File

@ -49,6 +49,8 @@ public class InfoCommand extends SingleCommand {
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
Map<String, String> storageMeta = plugin.getStorage().getMeta();
Message.INFO_TOP.send(sender,
plugin.getBootstrap().getVersion(),
plugin.getBootstrap().getType().getFriendlyName(),
@ -57,7 +59,7 @@ public class InfoCommand extends SingleCommand {
);
Message.INFO_STORAGE.send(sender, plugin.getStorage().getName());
for (Map.Entry<String, String> e : plugin.getStorage().getMeta().entrySet()) {
for (Map.Entry<String, String> e : storageMeta.entrySet()) {
Message.INFO_STORAGE_META.send(sender, e.getKey(), formatValue(e.getValue()));
}

View File

@ -36,6 +36,7 @@ import java.sql.SQLException;
import java.sql.Statement;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
public abstract class HikariConnectionFactory implements ConnectionFactory {
@ -103,7 +104,7 @@ public abstract class HikariConnectionFactory implements ConnectionFactory {
boolean success = true;
long start = System.currentTimeMillis();
try (Connection c = this.hikari.getConnection()) {
try (Connection c = getConnection()) {
try (Statement s = c.createStatement()) {
s.execute("/* ping */ SELECT 1");
}
@ -124,9 +125,12 @@ public abstract class HikariConnectionFactory implements ConnectionFactory {
@Override
public Connection getConnection() throws SQLException {
if (this.hikari == null) {
throw new SQLException("Unable to get a connection from the pool. (hikari is null)");
}
Connection connection = this.hikari.getConnection();
if (connection == null) {
throw new SQLException("Unable to get a connection from the pool.");
throw new SQLException("Unable to get a connection from the pool. (getConnection returned null)");
}
return connection;
}