From 7ae726ce8d62161b44b08d2f2edab7a232c64678 Mon Sep 17 00:00:00 2001 From: PatoTheBest Date: Sun, 21 Jun 2020 21:59:34 -0500 Subject: [PATCH] Fix NPE on TileEntitySkull (#3598) The setGameProfile method on TileEntitySkull is annotated with the @nullable annotation, but the skull didn't check for null profiles before attempting to retrieve cached skin. This bug was introduced by the commit making the skull use spigot's User Cache. Additionally, CraftMetaSkull also had the same issue with a null GameProfile, so this also ensures it doesn't break. The whole CraftPlayerProfile class is not null-safe, it requires a GameProfile that isn't null so we add a Validation on the constructor, that way it is easier to catch this kind of issue in the future. --- Spigot-Server-Patches/Basic-PlayerProfile-API.patch | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Spigot-Server-Patches/Basic-PlayerProfile-API.patch b/Spigot-Server-Patches/Basic-PlayerProfile-API.patch index 3e606e69bb..79329ad63c 100644 --- a/Spigot-Server-Patches/Basic-PlayerProfile-API.patch +++ b/Spigot-Server-Patches/Basic-PlayerProfile-API.patch @@ -20,6 +20,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +import com.mojang.authlib.properties.PropertyMap; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.UserCache; ++import org.apache.commons.lang3.Validate; +import org.bukkit.craftbukkit.entity.CraftPlayer; +import org.spigotmc.SpigotConfig; + @@ -46,6 +47,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + } + + public CraftPlayerProfile(GameProfile profile) { ++ Validate.notNull(profile, "GameProfile cannot be null!"); + this.profile = profile; + } + @@ -463,7 +465,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 private void f() { // Spigot start GameProfile profile = this.gameProfile; -+ if (profile.isComplete() && profile.getProperties().containsKey("textures")) return; // Paper ++ if (profile != null && profile.isComplete() && profile.getProperties().containsKey("textures")) return; // Paper b(profile, new Predicate() { @Override @@ -589,9 +591,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 private void setProfile(GameProfile profile) { + // Paper start -+ com.destroystokyo.paper.profile.CraftPlayerProfile paperProfile = new com.destroystokyo.paper.profile.CraftPlayerProfile(profile); -+ paperProfile.completeFromCache(); -+ profile = paperProfile.getGameProfile(); ++ if (profile != null) { ++ com.destroystokyo.paper.profile.CraftPlayerProfile paperProfile = new com.destroystokyo.paper.profile.CraftPlayerProfile(profile); ++ paperProfile.completeFromCache(); ++ profile = paperProfile.getGameProfile(); ++ } + // Paper end this.profile = profile; this.serializedProfile = (profile == null) ? null : GameProfileSerializer.serialize(new NBTTagCompound(), profile);