From c6c2ff99c3925b16585bcb4da8936bd62ed78a67 Mon Sep 17 00:00:00 2001 From: Redned Date: Wed, 29 Dec 2021 10:29:48 -0600 Subject: [PATCH] Fix NPE and API contract breakage for Component deserialization --- .../geyser/text/GsonComponentSerializerWrapper.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/text/GsonComponentSerializerWrapper.java b/core/src/main/java/org/geysermc/geyser/text/GsonComponentSerializerWrapper.java index 930d4a62c..9e038db34 100644 --- a/core/src/main/java/org/geysermc/geyser/text/GsonComponentSerializerWrapper.java +++ b/core/src/main/java/org/geysermc/geyser/text/GsonComponentSerializerWrapper.java @@ -31,7 +31,6 @@ import com.google.gson.JsonElement; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.function.UnaryOperator; @@ -62,9 +61,14 @@ public record GsonComponentSerializerWrapper(GsonComponentSerializer source) imp } @Override - public @Nullable Component deserialize(@NotNull String input) { + public @NotNull Component deserialize(@NotNull String input) { // See https://github.com/KyoriPowered/adventure/issues/447 - return this.serializer().fromJson(input, Component.class); + Component component = this.serializer().fromJson(input, Component.class); + if (component == null) { + return Component.empty(); + } + + return component; } @Override