From c52aa3cb7bd06a5be45bf9e771c01c1be593dc07 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 17 Mar 2014 20:38:23 +0100 Subject: [PATCH] Delete JSON file in case of an error. --- src/main/java/net/pterodactylus/rhynodge/states/StateManager.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/pterodactylus/rhynodge/states/StateManager.java b/src/main/java/net/pterodactylus/rhynodge/states/StateManager.java index 35125bb..a52e74d 100644 --- a/src/main/java/net/pterodactylus/rhynodge/states/StateManager.java +++ b/src/main/java/net/pterodactylus/rhynodge/states/StateManager.java @@ -96,8 +96,9 @@ public class StateManager { * The state to save */ public void saveState(String reactionName, State state) { + File stateFile = null; try { - File stateFile = stateFile(reactionName, "last"); + stateFile = stateFile(reactionName, "last"); objectMapper.writeValue(stateFile, state); if (state.success()) { stateFile = stateFile(reactionName, "success"); @@ -105,10 +106,13 @@ public class StateManager { } } catch (JsonGenerationException jge1) { logger.warn(String.format("State for Reaction “%s” could not be generated.", reactionName), jge1); + stateFile.delete(); } catch (JsonMappingException jme1) { logger.warn(String.format("State for Reaction “%s” could not be generated.", reactionName), jme1); + stateFile.delete(); } catch (IOException ioe1) { logger.warn(String.format("State for Reaction “%s” could not be written.", reactionName)); + stateFile.delete(); } } -- 2.7.4