From d2c1cbf2a51de07edebbb2b4e3a72abf2e6880e0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 22 Mar 2026 17:22:08 +0000 Subject: [PATCH] Fix Json.ParseJson crash on empty/null input ParseJson now returns null for null, empty, or whitespace-only input instead of throwing JsonReaderException. This matches the behavior of the old hand-rolled parser and is needed because MC protocol packets may contain empty strings where JSON text is expected (e.g. empty chat messages in DeathCombatEvent packets). Discovered during end-to-end testing against a Minecraft 1.21.11 protocol server. Co-authored-by: milutinke <441903+milutinke@users.noreply.github.com> Agent-Logs-Url: https://github.com/milutinke/Minecraft-Console-Client/sessions/34df723e-4a63-45a0-a942-e119d81a575b --- MinecraftClient/Json.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/MinecraftClient/Json.cs b/MinecraftClient/Json.cs index c16ca4ea..827a23f4 100644 --- a/MinecraftClient/Json.cs +++ b/MinecraftClient/Json.cs @@ -16,8 +16,10 @@ public static class Json /// /// Parse a JSON string into a mutable DOM. + /// Returns null for null, empty, or whitespace-only input. /// - public static JsonNode? ParseJson(string json) => JsonNode.Parse(json); + public static JsonNode? ParseJson(string? json) => + string.IsNullOrWhiteSpace(json) ? null : JsonNode.Parse(json); /// /// Escape a string for embedding inside a JSON string literal.