angelo57 / google-gson

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

Threading issue in FieldAttributes? #354

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
We're using gson on a high-load system, and when we recently bumped version to 
1.7.1 we're starting having sporadic exceptions as shown in the following 
stacktrace:

java.lang.NullPointerException
        at com.google.gson.FieldAttributes.getAnnotationFromArray(FieldAttributes.java:231)
        at com.google.gson.FieldAttributes.getAnnotation(FieldAttributes.java:150)
        at com.google.gson.SerializedNameAnnotationInterceptingNamingPolicy.translateName(SerializedNameAnnotationInterceptingNamingPolicy.java:45)
        at com.google.gson.JsonSerializationVisitor.addChildAsElement(JsonSerializationVisitor.java:132)
        at com.google.gson.JsonSerializationVisitor.visitFieldUsingCustomHandler(JsonSerializationVisitor.java:206)
        at com.google.gson.ReflectingFieldNavigator.visitFieldsReflectively(ReflectingFieldNavigator.java:63)
        at com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:120)
        at com.google.gson.JsonSerializationVisitor.getJsonElementForChild(JsonSerializationVisitor.java:147)
        at com.google.gson.JsonSerializationVisitor.addAsChildOfObject(JsonSerializationVisitor.java:127)
        at com.google.gson.JsonSerializationVisitor.visitObjectField(JsonSerializationVisitor.java:114)
        at com.google.gson.ReflectingFieldNavigator.visitFieldsReflectively(ReflectingFieldNavigator.java:69)
        at com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:120)
        at com.google.gson.JsonSerializationContextDefault.serialize(JsonSerializationContextDefault.java:62)
        at com.google.gson.JsonSerializationContextDefault.serialize(JsonSerializationContextDefault.java:53)
        at com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter.serialize(DefaultTypeAdapters.java:643)
        at com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter.serialize(DefaultTypeAdapters.java:624)
        at com.google.gson.JsonSerializationVisitor.findAndInvokeCustomSerializer(JsonSerializationVisitor.java:184)
        at com.google.gson.JsonSerializationVisitor.visitFieldUsingCustomHandler(JsonSerializationVisitor.java:204)
        at com.google.gson.ReflectingFieldNavigator.visitFieldsReflectively(ReflectingFieldNavigator.java:63)
        at com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:120)
        at com.google.gson.JsonSerializationContextDefault.serialize(JsonSerializationContextDefault.java:62)
        at com.google.gson.JsonSerializationContextDefault.serialize(JsonSerializationContextDefault.java:53)
        at com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter.serialize(DefaultTypeAdapters.java:643)
        at com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter.serialize(DefaultTypeAdapters.java:624)
        at com.google.gson.JsonSerializationVisitor.findAndInvokeCustomSerializer(JsonSerializationVisitor.java:184)
        at com.google.gson.JsonSerializationVisitor.visitFieldUsingCustomHandler(JsonSerializationVisitor.java:204)
        at com.google.gson.ReflectingFieldNavigator.visitFieldsReflectively(ReflectingFieldNavigator.java:63)
        at com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:120)
        at com.google.gson.JsonSerializationContextDefault.serialize(JsonSerializationContextDefault.java:62)
        at com.google.gson.JsonSerializationContextDefault.serialize(JsonSerializationContextDefault.java:53)
        at com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter.serialize(DefaultTypeAdapters.java:643)
        at com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter.serialize(DefaultTypeAdapters.java:624)
        at com.google.gson.JsonSerializationVisitor.findAndInvokeCustomSerializer(JsonSerializationVisitor.java:184)
        at com.google.gson.JsonSerializationVisitor.visitFieldUsingCustomHandler(JsonSerializationVisitor.java:204)
        at com.google.gson.ReflectingFieldNavigator.visitFieldsReflectively(ReflectingFieldNavigator.java:63)
        at com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:120)
        at com.google.gson.JsonSerializationContextDefault.serialize(JsonSerializationContextDefault.java:62)
        at com.google.gson.BaseMapTypeAdapter.serialize(BaseMapTypeAdapter.java:34)
        at com.google.gson.MapTypeAdapter.serialize(MapTypeAdapter.java:53)
        at com.google.gson.MapTypeAdapter.serialize(MapTypeAdapter.java:33)
        at com.google.gson.JsonSerializationVisitor.findAndInvokeCustomSerializer(JsonSerializationVisitor.java:184)
        at com.google.gson.JsonSerializationVisitor.visitUsingCustomHandler(JsonSerializationVisitor.java:160)
        at com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:101)
        at com.google.gson.JsonSerializationContextDefault.serialize(JsonSerializationContextDefault.java:62)
        at com.google.gson.JsonSerializationContextDefault.serialize(JsonSerializationContextDefault.java:53)
        at com.google.gson.Gson.toJsonTree(Gson.java:220)
        at com.google.gson.Gson.toJson(Gson.java:260)
...

This doesn't happen all the time, even with the same data. The exception always 
appears on portions of code that are ran in a thread pool, and each worker 
shares the same GsonBuilder.

Original issue reported on code.google.com by aba...@gmail.com on 4 Aug 2011 at 3:19

GoogleCodeExporter commented 9 years ago
This is fixed in source. It'll be available in the next GSON release.

Original comment by limpbizkit on 5 Aug 2011 at 10:45

GoogleCodeExporter commented 9 years ago
When is planned to put Gson 1.7.2 at the market?
The Roadmap states that it was intended to July 2011.

Original comment by Ricardo....@gmail.com on 24 Aug 2011 at 7:32

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I've been getting exactly the same exception, again since upgrading to 1.7.1.

I'm glad that it is fixed in the next release. Any idea of when that might be?

If this isn't due soon, any chance you could point me at the svn revision where 
the fix was made, so that I can do a custom patch whilst I'm waiting.

Original comment by t.denley on 29 Aug 2011 at 9:21

GoogleCodeExporter commented 9 years ago
Since I couldn't wait for a new version of Gson and using an svn snapshot is 
out of the question, I switched to Jackson. Its interface it's pretty similar 
to that of Gson.

Original comment by aba...@gmail.com on 29 Aug 2011 at 11:50

GoogleCodeExporter commented 9 years ago
You can grab GSON 1.7.2 source here:
http://code.google.com/p/google-gson/source/browse/tags/gson-1.7.2/

I'll talk to our Maven guy to upload a Maven-built binary.

Original comment by limpbizkit on 29 Aug 2011 at 9:51

GoogleCodeExporter commented 9 years ago
Thanks limpbiz, a 1.7.2 release binary would be fantastic.

Original comment by t.denley on 30 Aug 2011 at 10:21

GoogleCodeExporter commented 9 years ago
any news on that binary?

Original comment by t.denley on 5 Sep 2011 at 10:07

GoogleCodeExporter commented 9 years ago
Any news?

Original comment by Ricardo....@gmail.com on 17 Sep 2011 at 1:44

GoogleCodeExporter commented 9 years ago
Any updates?

Original comment by matt.hug...@gmail.com on 17 Sep 2011 at 6:37

GoogleCodeExporter commented 9 years ago
I am our Maven guy but I dont quite know how to do a release from a subversion 
tagged version. As you probably know, the main Gson tree has digressed 
substantially. If someone can help me figure out how to do 1.7.2, I am happy to 
do so.

Otherwise, we will have to wait for the next release, Gson 2.0. However, that 
is probably a few weeks away.

Original comment by inder123 on 17 Sep 2011 at 9:14

GoogleCodeExporter commented 9 years ago
You can try

mvn release:perform 
-DconnectionUrl=scm:svn:https://google-gson.googlecode.com/svn/tags/gson-1.7.2

Original comment by car...@carlossanchez.eu on 30 Sep 2011 at 4:27

GoogleCodeExporter commented 9 years ago
btw for more info 
http://maven.apache.org/plugins/maven-release-plugin/examples/perform-release.ht
ml

Original comment by car...@carlossanchez.eu on 30 Sep 2011 at 4:29

GoogleCodeExporter commented 9 years ago
Thanks for the instructions on releasing a specific version of Gson!
I have now completed the promotion of Gson 1.7.2 to Maven Central. Should sync 
in about an hour. 

Original comment by inder123 on 30 Sep 2011 at 7:07

GoogleCodeExporter commented 9 years ago
Fantastic. thanks.

Original comment by t.denley on 30 Sep 2011 at 7:18