From 0076297721133fda27c89f858dd8749fbfd8554d Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Tue, 8 Jul 2014 09:44:18 +1000 Subject: [PATCH] Safer JSON Loading By: Suddenly --- .../server/players/GameProfileCache.java.patch | 14 +++++++++++++- .../server/players/StoredUserList.java.patch | 12 +++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/paper-server/patches/sources/net/minecraft/server/players/GameProfileCache.java.patch b/paper-server/patches/sources/net/minecraft/server/players/GameProfileCache.java.patch index 9dc80133ec..7f90aa3cd8 100644 --- a/paper-server/patches/sources/net/minecraft/server/players/GameProfileCache.java.patch +++ b/paper-server/patches/sources/net/minecraft/server/players/GameProfileCache.java.patch @@ -53,7 +53,19 @@ Objects.requireNonNull(list); optional.ifPresent(list::add); -@@ -261,7 +261,7 @@ +@@ -250,6 +250,11 @@ + } + } catch (FileNotFoundException filenotfoundexception) { + ; ++ // Spigot Start ++ } catch (com.google.gson.JsonSyntaxException | NullPointerException ex) { ++ GameProfileCache.LOGGER.warn( "Usercache.json is corrupted or has bad formatting. Deleting it to prevent further issues." ); ++ this.file.delete(); ++ // Spigot End + } catch (JsonParseException | IOException ioexception) { + GameProfileCache.LOGGER.warn("Failed to load profile cache {}", this.file, ioexception); + } +@@ -261,7 +266,7 @@ JsonArray jsonarray = new JsonArray(); DateFormat dateformat = GameProfileCache.createDateFormat(); diff --git a/paper-server/patches/sources/net/minecraft/server/players/StoredUserList.java.patch b/paper-server/patches/sources/net/minecraft/server/players/StoredUserList.java.patch index 1580322705..f5936fe15e 100644 --- a/paper-server/patches/sources/net/minecraft/server/players/StoredUserList.java.patch +++ b/paper-server/patches/sources/net/minecraft/server/players/StoredUserList.java.patch @@ -44,7 +44,7 @@ JsonObject jsonobject = new JsonObject(); Objects.requireNonNull(jsonlistentry); -@@ -171,7 +172,7 @@ +@@ -171,9 +172,17 @@ StoredUserEntry jsonlistentry = this.createEntry(jsonobject); if (jsonlistentry.getUser() != null) { @@ -52,4 +52,14 @@ + this.map.put(this.getKeyForUser(jsonlistentry.getUser()), (V) jsonlistentry); // CraftBukkit - decompile error } } ++ // Spigot Start ++ } catch ( com.google.gson.JsonParseException | NullPointerException ex ) ++ { ++ org.bukkit.Bukkit.getLogger().log( java.util.logging.Level.WARNING, "Unable to read file " + this.file + ", backing it up to {0}.backup and creating new copy.", ex ); ++ File backup = new File( this.file + ".backup" ); ++ this.file.renameTo( backup ); ++ this.file.delete(); ++ // Spigot End } catch (Throwable throwable) { + if (bufferedreader != null) { + try {