From c0128c69127842c78f5efb03710adf3b3d09e0a4 Mon Sep 17 00:00:00 2001 From: riking Date: Sat, 5 Oct 2013 16:14:46 -0700 Subject: [PATCH] Flatfile loadProfile - place newUser() inside of try block This fixes incorrect behavior in the edge-case where an IOException occurs when reading (but not writing) the flatfile database. --- .../database/FlatfileDatabaseManager.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/database/FlatfileDatabaseManager.java b/src/main/java/com/gmail/nossr50/database/FlatfileDatabaseManager.java index f98825d45..a6c454f5d 100644 --- a/src/main/java/com/gmail/nossr50/database/FlatfileDatabaseManager.java +++ b/src/main/java/com/gmail/nossr50/database/FlatfileDatabaseManager.java @@ -387,22 +387,30 @@ public final class FlatfileDatabaseManager implements DatabaseManager { } PlayerProfile p = loadFromLine(character); - in.close(); return p; } + + // Didn't find the player, create a new one + if (create) { + newUser(playerName); + return new PlayerProfile(playerName, true); + } } catch (Exception e) { e.printStackTrace(); } finally { - tryClose(in); + // Silly inlining of tryClose() because the compiler is giving a warning when I use tryClose() + try { + if (in != null) { + in.close(); + } + } + catch (IOException ignored) {} } } - if (create) { - newUser(playerName); - return new PlayerProfile(playerName, true); - } + // Return unloaded profile return new PlayerProfile(playerName); }