mirror of
https://hub.spigotmc.org/stash/scm/spigot/spigot.git
synced 2025-08-05 16:48:51 +00:00
44 lines
2 KiB
Diff
44 lines
2 KiB
Diff
From b541633c6f6e70ec00b0f34b1adf03dccd3a9fa6 Mon Sep 17 00:00:00 2001
|
|
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
|
|
index 1834cb5ac..0859c7eb2 100644
|
|
--- a/src/main/java/net/minecraft/server/JsonList.java
|
|
+++ b/src/main/java/net/minecraft/server/JsonList.java
|
|
@@ -172,6 +172,14 @@ public class JsonList<K, V extends JsonListEntry<K>> {
|
|
try {
|
|
bufferedreader = Files.newReader(this.c, StandardCharsets.UTF_8);
|
|
collection = (Collection) ChatDeserializer.a(this.b, (Reader) bufferedreader, (Type) JsonList.f);
|
|
+ // Spigot Start
|
|
+ } catch ( com.google.gson.JsonParseException ex )
|
|
+ {
|
|
+ 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 );
|
|
+ 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
|
|
index d34768f8d..487fc11f1 100644
|
|
--- a/src/main/java/net/minecraft/server/UserCache.java
|
|
+++ b/src/main/java/net/minecraft/server/UserCache.java
|
|
@@ -215,6 +215,11 @@ public class UserCache {
|
|
}
|
|
} 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." );
|
|
+ this.h.delete();
|
|
+ // Spigot End
|
|
} catch (JsonParseException jsonparseexception) {
|
|
;
|
|
} finally {
|
|
--
|
|
2.14.1
|
|
|