mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 23:38:25 +01:00
Safer JSON Loading
By: Suddenly <suddenly@suddenly.coffee>
This commit is contained in:
parent
c4d2bdfd85
commit
0076297721
2 changed files with 24 additions and 2 deletions
|
@ -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();
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
JsonObject jsonobject = new JsonObject();
|
||||
|
||||
Objects.requireNonNull(jsonlistentry);
|
||||
@@ -171,7 +172,7 @@
|
||||
@@ -171,9 +172,17 @@
|
||||
StoredUserEntry<K> 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 {
|
||||
|
|
Loading…
Reference in a new issue