czyzby/gdx-lml

Invalid enum ordinal

bergice opened this issue · 4 comments

There seems to be an intermittent issue with deserializing messages in my program.

Sometimes, a SerializationException will be thrown, indicating that the message has not been serialised/deserialised correctly.

I have no idea how to replicate it, and the exception is still thrown, even when I try to catch the exception, which means it always breaks the program.

This seems to not be an issue when using GWT, which could indicate this is a threading problem.

Any tips on how to trace down the issue would be appreciated.

The stack trace:

Message: Invalid enum ordinal: 3840
com.github.czyzby.websocket.serialization.SerializationException: Invalid enum ordinal: 3840
	at com.github.czyzby.websocket.serialization.impl.Deserializer.validateEnumOrdinal(Deserializer.java:161)
	at com.github.czyzby.websocket.serialization.impl.Deserializer.deserializeEnum(Deserializer.java:154)
	at com.github.czyzby.websocket.serialization.impl.Deserializer.deserializeEnum(Deserializer.java:143)
	at io.lurkers.game.Message.deserialize(Message.java:155)
	at io.lurkers.game.Message.deserialize(Message.java:10)
	at com.github.czyzby.websocket.serialization.impl.Deserializer.deserializeTransferable(Deserializer.java:626)
	at com.github.czyzby.websocket.serialization.impl.ManualSerializer.deserialize(ManualSerializer.java:84)
	at com.github.czyzby.websocket.AbstractWebSocketListener.onMessage(AbstractWebSocketListener.java:38)
	at com.github.czyzby.websocket.impl.AbstractWebSocket.postMessageEvent(AbstractWebSocket.java:98)
	at com.github.czyzby.websocket.impl.NvWebSocketListener.onBinaryMessage(NvWebSocketListener.java:65)
	at com.neovisionaries.ws.client.ListenerManager.callOnBinaryMessage(ListenerManager.java:368)
	at com.neovisionaries.ws.client.ReadingThread.callOnBinaryMessage(ReadingThread.java:272)
	at com.neovisionaries.ws.client.ReadingThread.handleBinaryFrame(ReadingThread.java:992)
	at com.neovisionaries.ws.client.ReadingThread.handleFrame(ReadingThread.java:751)
	at com.neovisionaries.ws.client.ReadingThread.main(ReadingThread.java:110)
	at com.neovisionaries.ws.client.ReadingThread.run(ReadingThread.java:66)
Websocket: Unable to handle the received packet: null
com.github.czyzby.websocket.impl.NvWebSocket@699d3d0f: Web socket reported an error.
com.github.czyzby.websocket.data.WebSocketException: Unable to handle the received packet: null
	at com.github.czyzby.websocket.WebSocketHandler.onMessage(WebSocketHandler.java:51)
	at com.github.czyzby.websocket.AbstractWebSocketListener.onMessage(AbstractWebSocketListener.java:38)
	at com.github.czyzby.websocket.impl.AbstractWebSocket.postMessageEvent(AbstractWebSocket.java:98)
	at com.github.czyzby.websocket.impl.NvWebSocketListener.onBinaryMessage(NvWebSocketListener.java:65)
	at com.neovisionaries.ws.client.ListenerManager.callOnBinaryMessage(ListenerManager.java:368)
	at com.neovisionaries.ws.client.ReadingThread.callOnBinaryMessage(ReadingThread.java:272)
	at com.neovisionaries.ws.client.ReadingThread.handleBinaryFrame(ReadingThread.java:992)
	at com.neovisionaries.ws.client.ReadingThread.handleFrame(ReadingThread.java:751)
	at com.neovisionaries.ws.client.ReadingThread.main(ReadingThread.java:110)
	at com.neovisionaries.ws.client.ReadingThread.run(ReadingThread.java:66)
Caused by: java.lang.NullPointerException
	at com.github.czyzby.websocket.WebSocketHandler.onMessage(WebSocketHandler.java:49)
	... 9 more

I have no idea how to replicate it, and the exception is still thrown, even when I try to catch the exception, which means it always breaks the program.

Seems like you're trying to catch it in the incorrect place. Try modifying these methods. You could also add a synchronized block there to see if threading is the cause.

Anyway, the message suggests that you're sending an invalid enum index (3840). Just to confirm - are you trying to serialize an enum variable? Have you tried changing it to an int (enum ordinal) or a string (enum name) and deserializing it manually?

Client and server could be also out of sync. Maybe you modified the serialized class in only one of the applications and it tries to deserialize it differently.

Seems like you're trying to catch it in the incorrect place. Try modifying these methods. You could also add a synchronized block there to see if threading is the cause.

Thanks, this might help mitigate the problem.

Anyway, the message suggests that you're sending an invalid enum index (3840). Just to confirm - are you trying to serialize an enum variable?

Yes, it is the enum describing what type of message is being sent/received (for the Message class).

Have you tried changing it to an int (enum ordinal) or a string (enum name) and deserializing it manually?

No.

Client and server could be also out of sync. Maybe you modified the serialized class in only one of the applications and it tries to deserialize it differently.

This has been happening for a long time, so that should not be possible.

The external web socket client might spawn multiple threads and try to deserialize multiple packets at once. Synchronizing the methods I posted should fix the issue, if this happens to be the cause. You could also look into nv-websocket-client initiation, there might be a concurrency setting there.

Closing for now as this doesn't look like a problem with the library.