2020-06-25 10:00:00 +10:00
From 86692a83543e1072622de9c65db76c530a474305 Mon Sep 17 00:00:00 2001
2014-07-08 09:44:30 +10: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
2020-06-25 10:00:00 +10:00
index 13b32a9ae..5b01e4edb 100644
2014-07-08 09:44:30 +10:00
--- a/src/main/java/net/minecraft/server/JsonList.java
+++ b/src/main/java/net/minecraft/server/JsonList.java
2020-06-25 10:00:00 +10:00
@@ -172,6 +172,14 @@ public abstract class JsonList<K, V extends JsonListEntry<K>> {
this.d.put(this.a(jsonlistentry.getKey()), (V) jsonlistentry); // CraftBukkit - fix decompile error
2018-07-15 10:00:00 +10:00
}
}
2017-05-19 21:00:22 +10:00
+ // Spigot Start
2017-06-21 18:42:31 +10:00
+ } catch ( com.google.gson.JsonParseException ex )
2017-05-19 21:00:22 +10:00
+ {
2017-06-21 18:42:31 +10:00
+ org.bukkit.Bukkit.getLogger().log( java.util.logging.Level.WARNING, "Unable to read file " + this.c + ", backing it up to {0}.backup and creating new copy.", ex );
2017-05-19 21:00:22 +10:00
+ File backup = new File( this.c + ".backup" );
+ this.c.renameTo( backup );
+ this.c.delete();
+ // Spigot End
2020-06-25 10:00:00 +10:00
} catch (Throwable throwable1) {
throwable = throwable1;
throw throwable1;
2014-07-08 09:44:30 +10:00
diff --git a/src/main/java/net/minecraft/server/UserCache.java b/src/main/java/net/minecraft/server/UserCache.java
2020-06-25 10:00:00 +10:00
index 31f8000a7..b21160999 100644
2014-07-08 09:44:30 +10:00
--- a/src/main/java/net/minecraft/server/UserCache.java
+++ b/src/main/java/net/minecraft/server/UserCache.java
2020-06-25 10:00:00 +10:00
@@ -196,6 +196,11 @@ public class UserCache {
2014-07-08 09:44:30 +10:00
}
2015-05-09 21:23:26 +01:00
} catch (FileNotFoundException filenotfoundexception) {
;
+ // Spigot Start
+ } catch (com.google.gson.JsonSyntaxException ex) {
2019-04-25 12:00:00 +10:00
+ JsonList.LOGGER.warn( "Usercache.json is corrupted or has bad formatting. Deleting it to prevent further issues." );
2016-03-01 08:33:06 +11:00
+ this.h.delete();
2015-05-09 21:23:26 +01:00
+ // Spigot End
} catch (JsonParseException jsonparseexception) {
;
} finally {
2014-07-08 09:44:30 +10:00
--
2020-05-09 18:48:11 +10:00
2.25.1
2014-07-08 09:44:30 +10:00