From 9d950b9b4a7d3c6f1cd02e26017676acace4b0a4 Mon Sep 17 00:00:00 2001 From: Xephi59 Date: Thu, 20 Aug 2015 18:39:40 +0200 Subject: [PATCH 1/3] Potential NPE --- .../xephi/authme/process/quit/AsyncronousQuit.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/fr/xephi/authme/process/quit/AsyncronousQuit.java b/src/main/java/fr/xephi/authme/process/quit/AsyncronousQuit.java index 585ab6fa1..40a71247d 100644 --- a/src/main/java/fr/xephi/authme/process/quit/AsyncronousQuit.java +++ b/src/main/java/fr/xephi/authme/process/quit/AsyncronousQuit.java @@ -21,7 +21,7 @@ public class AsyncronousQuit { protected AuthMe plugin; protected DataSource database; - protected Player p; + protected Player player; protected Utils utils = Utils.getInstance(); private String name; private ItemStack[] armor = null; @@ -33,7 +33,7 @@ public class AsyncronousQuit { public AsyncronousQuit(Player p, AuthMe plugin, DataSource database, boolean isKick) { - this.p = p; + this.player = p; this.plugin = plugin; this.database = database; this.name = p.getName().toLowerCase(); @@ -41,7 +41,8 @@ public class AsyncronousQuit { } public void process() { - final Player player = p; + if (player == null) + return; if (plugin.getCitizensCommunicator().isNPC(player) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) { return; } @@ -64,7 +65,8 @@ public class AsyncronousQuit { inv = limbo.getInventory(); armor = limbo.getArmour(); } - utils.addNormal(player, limbo.getGroup()); + if (limbo.getGroup() != null && !limbo.getGroup().equals("")) + utils.addNormal(player, limbo.getGroup()); needToChange = true; isOp = limbo.getOperator(); isFlying = limbo.isFlying(); @@ -94,6 +96,7 @@ public class AsyncronousQuit { database.setUnlogged(name); } AuthMePlayerListener.gameMode.remove(name); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new ProcessSyncronousPlayerQuit(plugin, player, inv, armor, isOp, isFlying, needToChange)); + final Player p = player; + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new ProcessSyncronousPlayerQuit(plugin, p, inv, armor, isOp, isFlying, needToChange)); } } From b84d96360e83c8e44a6d6d1f54e0c243bb421735 Mon Sep 17 00:00:00 2001 From: Xephi59 Date: Thu, 20 Aug 2015 18:49:22 +0200 Subject: [PATCH 2/3] TEMP FIX - Catch all Exception instance due to HikariCP thrown --- .../fr/xephi/authme/datasource/MySQL.java | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/main/java/fr/xephi/authme/datasource/MySQL.java b/src/main/java/fr/xephi/authme/datasource/MySQL.java index 9509192d8..201e6f146 100644 --- a/src/main/java/fr/xephi/authme/datasource/MySQL.java +++ b/src/main/java/fr/xephi/authme/datasource/MySQL.java @@ -196,7 +196,7 @@ public class MySQL implements DataSource { pst.setString(1, user); rs = pst.executeQuery(); return rs.next(); - } catch (SQLException ex) { + } catch (Exception ex) { ConsoleLogger.showError(ex.getMessage()); return false; } finally { @@ -246,7 +246,7 @@ public class MySQL implements DataSource { } else { return null; } - } catch (SQLException ex) { + } catch (Exception ex) { ConsoleLogger.showError(ex.getMessage()); return null; } finally { @@ -456,7 +456,7 @@ public class MySQL implements DataSource { if (rs != null && !rs.isClosed()) rs.close(); } - } catch (SQLException ex) { + } catch (Exception ex) { ConsoleLogger.showError(ex.getMessage()); return false; } finally { @@ -501,7 +501,7 @@ public class MySQL implements DataSource { if (rs != null && !rs.isClosed()) rs.close(); } - } catch (SQLException ex) { + } catch (Exception ex) { ConsoleLogger.showError(ex.getMessage()); return false; } finally { @@ -523,7 +523,7 @@ public class MySQL implements DataSource { pst.setString(3, auth.getRealName()); pst.setString(4, auth.getNickname()); pst.executeUpdate(); - } catch (SQLException ex) { + } catch (Exception ex) { ConsoleLogger.showError(ex.getMessage()); return false; } finally { @@ -542,7 +542,7 @@ public class MySQL implements DataSource { pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnLastLogin + "(); } finally { @@ -606,7 +606,7 @@ public class MySQL implements DataSource { pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;"); pst.setString(1, user); pst.executeUpdate(); - } catch (SQLException ex) { + } catch (Exception ex) { ConsoleLogger.showError(ex.getMessage()); return false; } finally { @@ -629,7 +629,7 @@ public class MySQL implements DataSource { pst.setString(4, auth.getWorld()); pst.setString(5, auth.getNickname()); pst.executeUpdate(); - } catch (SQLException ex) { + } catch (Exception ex) { ConsoleLogger.showError(ex.getMessage()); return false; } finally { @@ -654,7 +654,7 @@ public class MySQL implements DataSource { countIp++; } return countIp; - } catch (SQLException ex) { + } catch (Exception ex) { ConsoleLogger.showError(ex.getMessage()); return 0; } finally { @@ -674,7 +674,7 @@ public class MySQL implements DataSource { pst.setString(1, auth.getEmail()); pst.setString(2, auth.getNickname()); pst.executeUpdate(); - } catch (SQLException ex) { + } catch (Exception ex) { ConsoleLogger.showError(ex.getMessage()); return false; } finally { @@ -697,7 +697,7 @@ public class MySQL implements DataSource { pst.setString(1, auth.getSalt()); pst.setString(2, auth.getNickname()); pst.executeUpdate(); - } catch (SQLException ex) { + } catch (Exception ex) { ConsoleLogger.showError(ex.getMessage()); return false; } finally { @@ -732,7 +732,7 @@ public class MySQL implements DataSource { if (st != null) { try { st.close(); - } catch (SQLException ex) { + } catch (Exception ex) { ConsoleLogger.showError(ex.getMessage()); } } @@ -742,7 +742,7 @@ public class MySQL implements DataSource { if (rs != null) { try { rs.close(); - } catch (SQLException ex) { + } catch (Exception ex) { ConsoleLogger.showError(ex.getMessage()); } } @@ -752,7 +752,7 @@ public class MySQL implements DataSource { if (con != null) { try { con.close(); - } catch (SQLException ex) { + } catch (Exception ex) { ConsoleLogger.showError(ex.getMessage()); } } @@ -773,7 +773,7 @@ public class MySQL implements DataSource { countIp.add(rs.getString(columnName)); } return countIp; - } catch (SQLException ex) { + } catch (Exception ex) { ConsoleLogger.showError(ex.getMessage()); return new ArrayList(); } finally { @@ -798,7 +798,7 @@ public class MySQL implements DataSource { countIp.add(rs.getString(columnName)); } return countIp; - } catch (SQLException ex) { + } catch (Exception ex) { ConsoleLogger.showError(ex.getMessage()); return new ArrayList(); } finally { @@ -823,7 +823,7 @@ public class MySQL implements DataSource { countEmail.add(rs.getString(columnName)); } return countEmail; - } catch (SQLException ex) { + } catch (Exception ex) { ConsoleLogger.showError(ex.getMessage()); return new ArrayList(); } finally { @@ -844,7 +844,7 @@ public class MySQL implements DataSource { pst.setString(1, name); pst.executeUpdate(); } - } catch (SQLException ex) { + } catch (Exception ex) { ConsoleLogger.showError(ex.getMessage()); } finally { close(pst); @@ -890,7 +890,7 @@ public class MySQL implements DataSource { while (con == null) try { con = ds.getConnection(); - } catch (SQLException e) { + } catch (Exception e) { try { reconnect(false); con = ds.getConnection(); @@ -937,7 +937,7 @@ public class MySQL implements DataSource { rs = pst.executeQuery(); if (rs.next()) return (rs.getInt(columnLogged) == 1); - } catch (SQLException ex) { + } catch (Exception ex) { ConsoleLogger.showError(ex.getMessage()); return false; } finally { @@ -958,7 +958,7 @@ public class MySQL implements DataSource { pst.setInt(1, 1); pst.setString(2, user); pst.executeUpdate(); - } catch (SQLException ex) { + } catch (Exception ex) { ConsoleLogger.showError(ex.getMessage()); return; } finally { @@ -979,7 +979,7 @@ public class MySQL implements DataSource { pst.setInt(1, 0); pst.setString(2, user); pst.executeUpdate(); - } catch (SQLException ex) { + } catch (Exception ex) { ConsoleLogger.showError(ex.getMessage()); return; } finally { @@ -999,7 +999,7 @@ public class MySQL implements DataSource { pst.setInt(1, 0); pst.setInt(2, 1); pst.executeUpdate(); - } catch (SQLException ex) { + } catch (Exception ex) { ConsoleLogger.showError(ex.getMessage()); return; } finally { @@ -1022,7 +1022,7 @@ public class MySQL implements DataSource { if (rs != null && rs.next()) { result = rs.getInt(1); } - } catch (SQLException ex) { + } catch (Exception ex) { ConsoleLogger.showError(ex.getMessage()); return result; } finally { @@ -1042,7 +1042,7 @@ public class MySQL implements DataSource { pst.setString(1, newone); pst.setString(2, oldone); pst.executeUpdate(); - } catch (SQLException ex) { + } catch (Exception ex) { ConsoleLogger.showError(ex.getMessage()); return; } finally { @@ -1092,7 +1092,7 @@ public class MySQL implements DataSource { if (pAuth != null) auths.add(pAuth); } - } catch (SQLException ex) { + } catch (Exception ex) { ConsoleLogger.showError(ex.getMessage()); return auths; } finally { @@ -1143,7 +1143,7 @@ public class MySQL implements DataSource { if (pAuth != null) auths.add(pAuth); } - } catch (SQLException ex) { + } catch (Exception ex) { ConsoleLogger.showError(ex.getMessage()); return auths; } finally { From 86e1b8df7c1c4dc3b6387065fb79e81da11a75fb Mon Sep 17 00:00:00 2001 From: Xephi59 Date: Thu, 20 Aug 2015 18:59:41 +0200 Subject: [PATCH 3/3] Define a max life time of a pool --- src/main/java/fr/xephi/authme/datasource/MySQL.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/fr/xephi/authme/datasource/MySQL.java b/src/main/java/fr/xephi/authme/datasource/MySQL.java index 201e6f146..45c9c651f 100644 --- a/src/main/java/fr/xephi/authme/datasource/MySQL.java +++ b/src/main/java/fr/xephi/authme/datasource/MySQL.java @@ -121,6 +121,7 @@ public class MySQL implements DataSource { config.addDataSourceProperty("prepStmtCacheSize", "250"); config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); config.addDataSourceProperty("autoReconnect", true); + config.setMaxLifetime(12000); config.setInitializationFailFast(false); ds = new HikariDataSource(config); ConsoleLogger.info("Connection pool ready"); @@ -914,6 +915,7 @@ public class MySQL implements DataSource { config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); config.addDataSourceProperty("autoReconnect", true); config.setInitializationFailFast(false); + config.setMaxLifetime(12000); config.setPoolName("AuthMeMYSQLPool"); ds = new HikariDataSource(config); if (!reload)