2021-04-07 15:03:34 +10:00
From 8996ca37d0f31b5397efaaa7a242cad4ae4fe9c5 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
2021-03-16 09:00:00 +11:00
diff --git a/src/main/java/net/minecraft/server/players/JsonList.java b/src/main/java/net/minecraft/server/players/JsonList.java
index fb6456f51..52256f72b 100644
--- a/src/main/java/net/minecraft/server/players/JsonList.java
+++ b/src/main/java/net/minecraft/server/players/JsonList.java
@@ -174,6 +174,14 @@ public abstract class JsonList<K, V extends JsonListEntry<K>> {
2020-06-25 10:00:00 +10:00
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
2021-01-22 16:51:21 +11:00
+ } catch ( com.google.gson.JsonParseException | NullPointerException 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;
2021-03-16 09:00:00 +11:00
diff --git a/src/main/java/net/minecraft/server/players/UserCache.java b/src/main/java/net/minecraft/server/players/UserCache.java
2021-04-07 15:03:34 +10:00
index ac0952b4d..5694ba68a 100644
2021-03-16 09:00:00 +11:00
--- a/src/main/java/net/minecraft/server/players/UserCache.java
+++ b/src/main/java/net/minecraft/server/players/UserCache.java
2021-04-07 15:03:34 +10:00
@@ -221,6 +221,11 @@ public class UserCache {
2020-08-12 07:00:00 +10:00
return arraylist1;
2015-05-09 21:23:26 +01:00
} catch (FileNotFoundException filenotfoundexception) {
;
+ // Spigot Start
2021-01-22 16:51:21 +11:00
+ } catch (com.google.gson.JsonSyntaxException | NullPointerException 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." );
2020-08-12 07:00:00 +10:00
+ this.g.delete();
2015-05-09 21:23:26 +01:00
+ // Spigot End
2020-08-12 07:00:00 +10:00
} catch (JsonParseException | IOException ioexception) {
UserCache.LOGGER.warn("Failed to load profile cache {}", this.g, ioexception);
}
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