Hello,
I wanted to send a set from my client to my server, but I got the following ERROR:
[java]Termining connection due to unhandled error
java.lang.NullPointerException
at com.jme3.network.serializing.serializers.EnumSerializer.readObject(EnumSerializer.java:51)
at com.jme3.network.serializing.serializers.MapSerializer.readObject(MapSerializer.java:118)
at com.jme3.network.serializing.Serializer.readClassAndObject(Serializer.java:335)
at com.jme3.network.serializing.serializers.FieldSerializer.readObject(FieldSerializer.java:140)
at com.jme3.network.serializing.Serializer.readClassAndObject(Serializer.java:335)
at com.jme3.network.base.MessageProtocol.createMessage(MessageProtocol.java:157)
at com.jme3.network.base.MessageProtocol.addBuffer(MessageProtocol.java:137)
at com.jme3.network.base.ConnectorAdapter.run(ConnectorAdapter.java:138)[/java]
When I sent the data with Lists everything was fine.
Did I make some mistake, or are sets not suited to be used in the messages?
Thanks for your help.
Hamsterpower
Could it be you’re using different versions of the library on server and client?
I think the problem is that Java internally uses a Map to represent the Set. Map has an internal object that it uses as a value that seems to be confusing SpiderMonkey. Or at least in my version of the JDK Map is just storing a raw Object as the value and this may confuse spider monkey. Maybe you are not using a standard JDK Set?
At any rate, it’s weird that it is not using the normal CollectionSerializer.since that’s specifically registered for the normal types of Java Sets.
Can you tell us what kind of Set you are trying to send? Maybe there is a bug in the registration.
normen said:
Could it be you're using different versions of the library on server and client?
No, i'm sure that I use the same library.
pspeed said:
I think the problem is that Java internally uses a Map to represent the Set. Map has an internal object that it uses as a value that seems to be confusing SpiderMonkey. Or at least in my version of the JDK Map is just storing a raw Object as the value and this may confuse spider monkey. Maybe you are not using a standard JDK Set?
At any rate, it's weird that it is not using the normal CollectionSerializer.since that's specifically registered for the normal types of Java Sets.
Can you tell us what kind of Set you are trying to send? Maybe there is a bug in the registration.
I use a HashSet. I believe that HashSets are represented internal as Maps.
But I intended to send also Maps with an other message.. So changing the HashSet to an other type isn't the solution in my case.
Thank you for your quick answers :)
Maps work. It’s something internal to the way that HashSets use the map that isn’t working.
But what I can’t figure out is why it isn’t using the CollectionSerializer instead. HashSet.class is specifically registered with CollectionSerializer.
…so something is getting confused. I will try and test this myself at some point but it won’t be for a while… heading to bed soon.
Thank you.
I did finally test this. I added a Set as a field on one of my existing messages and set it to a HashSet with three strings in it. I was able to send and receive it just fine without any additional configuration or registration.
So it seems like there might be something about the rest of your setup that makes this not work right.
Strange…
My only suggestion at the moment would be, that using a combination of Hashset and Enumerations is the problem.
When I have the time, I will look at my code. Maybe I find and solve the problem and can post it here.
Thank you for your investigation.