2016-03-01 00:23:45 +00:00
From 00ba6b1058d452bd2e2ecd6e7246de98b74581a7 Mon Sep 17 00:00:00 2001
2014-07-21 20:46:54 +00:00
From: Suddenly <suddenly@suddenly.coffee>
Date: Tue, 8 Jul 2014 09:44:18 +1000
Subject: [PATCH] Safer JSON Loading
diff --git a/src/main/java/net/minecraft/server/JsonList.java b/src/main/java/net/minecraft/server/JsonList.java
2015-02-28 11:36:22 +00:00
index f5c3aae..8e4ecfd 100644
2014-07-21 20:46:54 +00:00
--- a/src/main/java/net/minecraft/server/JsonList.java
+++ b/src/main/java/net/minecraft/server/JsonList.java
2015-02-28 11:36:22 +00:00
@@ -170,6 +170,17 @@ public class JsonList<K, V extends JsonListEntry<K>> {
2014-07-21 20:46:54 +00:00
try {
bufferedreader = Files.newReader(this.c, Charsets.UTF_8);
2014-11-28 01:17:45 +00:00
collection = (Collection) this.b.fromJson(bufferedreader, JsonList.f);
2014-07-21 20:46:54 +00:00
+ // Spigot Start
+ } catch ( java.io.FileNotFoundException ex )
+ {
2014-08-11 20:49:06 +00:00
+ org.bukkit.Bukkit.getLogger().log( java.util.logging.Level.INFO, "Unable to find file {0}, creating it.", this.c );
2014-11-28 01:17:45 +00:00
+ } catch ( com.google.gson.JsonSyntaxException ex )
2014-07-21 20:46:54 +00:00
+ {
2014-08-11 20:49:06 +00:00
+ org.bukkit.Bukkit.getLogger().log( java.util.logging.Level.WARNING, "Unable to read file {0}, backing it up to {0}.backup and creating new copy.", this.c );
2014-07-21 20:46:54 +00:00
+ File backup = new File( this.c + ".backup" );
+ this.c.renameTo( backup );
+ this.c.delete();
+ // Spigot End
} finally {
IOUtils.closeQuietly(bufferedreader);
}
diff --git a/src/main/java/net/minecraft/server/UserCache.java b/src/main/java/net/minecraft/server/UserCache.java
2016-02-29 21:33:06 +00:00
index 825fed6..46129d8 100644
2014-07-21 20:46:54 +00:00
--- a/src/main/java/net/minecraft/server/UserCache.java
+++ b/src/main/java/net/minecraft/server/UserCache.java
2016-02-29 21:33:06 +00:00
@@ -211,6 +211,11 @@ public class UserCache {
2014-07-21 20:46:54 +00:00
}
2015-05-09 20:23:26 +00:00
} catch (FileNotFoundException filenotfoundexception) {
;
+ // Spigot Start
+ } catch (com.google.gson.JsonSyntaxException ex) {
+ JsonList.a.warn( "Usercache.json is corrupted or has bad formatting. Deleting it to prevent further issues." );
2016-02-29 21:33:06 +00:00
+ this.h.delete();
2015-05-09 20:23:26 +00:00
+ // Spigot End
} catch (JsonParseException jsonparseexception) {
;
} finally {
2014-07-21 20:46:54 +00:00
--
2016-02-29 21:33:06 +00:00
2.5.0
2014-07-21 20:46:54 +00:00