Skip to content

[BUG] SkinUploadSocket.onClose throws JsonSyntaxException when close reason is a JSON primitive #655

@CristianVGdev

Description

@CristianVGdev

SkinUploadSocket.onClose assumes the WebSocket close reason is always a JsonObject.

That assumption is not always valid. In some cases the close reason is a JSON primitive or plain string, but the code still attempts to deserialize it directly as JsonObject, which causes Gson to throw.

Exception observed:

com.google.gson.JsonSyntaxException: Expected a com.google.gson.JsonObject but was com.google.gson.JsonPrimitive; at path $

Stack trace:

[21:07:33] [WebSocketConnectReadThread-92/ERROR]: [floodgate] [debug] Got an error
com.google.gson.JsonSyntaxException: Expected a com.google.gson.JsonObject but was com.google.gson.JsonPrimitive; at path $
	at com.google.gson.internal.bind.TypeAdapters$32$1.read(TypeAdapters.java:923)
	at com.google.gson.Gson.fromJson(Gson.java:1358)
	at com.google.gson.Gson.fromJson(Gson.java:1259)
	at com.google.gson.Gson.fromJson(Gson.java:1169)
	at com.google.gson.Gson.fromJson(Gson.java:1106)
	at org.geysermc.floodgate.skin.SkinUploadSocket.onClose(SkinUploadSocket.java:155)
	at org.java_websocket.client.WebSocketClient.onWebsocketClose(WebSocketClient.java:688)
	at org.java_websocket.WebSocketImpl.closeConnection(WebSocketImpl.java:557)
	at org.java_websocket.WebSocketImpl.eot(WebSocketImpl.java:612)
	at org.java_websocket.client.WebSocketClient.run(WebSocketClient.java:546)
	at java.base/java.lang.Thread.run(Thread.java:1474)

The problem is the unconditional deserialization as JsonObject. If the close reason is not an object (for example a primitive JSON value), Gson throws and the close handler fails.

The close reason format is not guaranteed to always be a JSON object, so this path should handle it defensively.

A safer approach would be:

  • parse the payload as JsonElement
  • check isJsonObject() before accessing object fields
  • otherwise ignore or log the raw reason

Environment

  1. Floodgate: Build #130
  2. Geyser: Build #1093
  3. Server software: Spigot
  4. Server version: 1.21.11 (4596)
  5. Java: 25

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions