discomarathon / google-gson

Automatically exported from code.google.com/p/google-gson
0 stars 0 forks source link

ObjectTypePair obj and type mismatch possible. #261

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Put gson under load with mutliple threads.
2. cause the setObject method in ObjectTypePair to be called.
3. note that the type does not get updated, leading to the ObjectTypePair 
having the wrong type for an object.

What is the expected output? What do you see instead?

Any call to setObject should update the type to the type of the current object 
using a getClass on the object.

What version of the product are you using? On what operating system?
JRE 1.5 and 1.6 on Windows/Mac/linux/IBM JVM.

Original issue reported on code.google.com by rojo...@gmail.com on 3 Nov 2010 at 10:35

GoogleCodeExporter commented 9 years ago
There is a race condition that occurs around this that will cause gson to fail 
to put JSON data into Java classes when the ObjectTypePair is out of sync.

Original comment by rojo...@gmail.com on 3 Nov 2010 at 10:37

GoogleCodeExporter commented 9 years ago
I'm having trouble finding the place where an ObjectTypePair instance is 
visible to multiple threads. Can you tell me what public API you're using to 
get ObjectTypePair.setObject() to be called?

Original comment by limpbizkit on 4 Nov 2010 at 10:33

GoogleCodeExporter commented 9 years ago
I don't have a deep understanding of the code, and the change does seem to be a 
side effect - but in ObjectNavigator.java in the accept method there is a call 
to objTypePair.setObject(objectToVisit);

The original type was an object, not the type of the objectToVisit.

This lack of type causes the deserialisation to fail.

The root cause seems to be earlier in the system, but once gson gets into the 
state where this mismatch happens it continues to be in the bad state.

In our system we have forked gson in order to ensure that it works correctly.

Original comment by rojo...@gmail.com on 9 Nov 2010 at 3:07

GoogleCodeExporter commented 9 years ago
Despite significant effort, I can't reproduce this in the current GSON tree. 
I'm guessing this has already been fixed.

Original comment by limpbizkit on 24 Jan 2011 at 10:36