Issue 625 in google-gson: FutureTypeAdapter.read() throws unhelpful exception

35 views
Skip to first unread message

googl...@googlecode.com

unread,
Jan 29, 2015, 12:27:03 PM1/29/15
to google-gson...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 625 by MhaleK...@gmail.com: FutureTypeAdapter.read() throws
unhelpful exception
https://code.google.com/p/google-gson/issues/detail?id=625

What steps will reproduce the problem?
When FutureTypeAdapter's delegate is null, the read() method throws an
IllegalStateException with no message. This then gets turned into a
JsonSyntaxException

These two exceptions don't make it easy to diagnose what went wrong, and
you can't easily tell if the issue is caused by a programming error, a bug
in Gson, or with the json being parsed. There's also no indication of what
the developer can do to avoid hitting this exception. Adding javasdoc and a
helpful method to the exception woudl be very nice.

Below is a sample stack trace.

E/Timber ( 3055): Caused by: retrofit.converter.ConversionException:
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException
E/Timber ( 3055): at
retrofit.converter.GsonConverter.fromBody(GsonConverter.java:67)
E/Timber ( 3055): at
retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:362)
E/Timber ( 3055): ... 9 more
E/Timber ( 3055): Caused by: com.google.gson.JsonSyntaxException:
java.lang.IllegalStateException
E/Timber ( 3055): at
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:187)
E/Timber ( 3055): at com.google.gson.Gson.fromJson(Gson.java:805)
E/Timber ( 3055): at com.google.gson.Gson.fromJson(Gson.java:770)
E/Timber ( 3055): at
retrofit.converter.GsonConverter.fromBody(GsonConverter.java:63)
E/Timber ( 3055): ... 10 more
E/Timber ( 3055): Caused by: java.lang.IllegalStateException
E/Timber ( 3055): at
com.google.gson.Gson$FutureTypeAdapter.read(Gson.java:885)
E/Timber ( 3055): at
com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:40)
E/Timber ( 3055): at
com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:81)
E/Timber ( 3055): at
com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:60)
E/Timber ( 3055): at
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:95)
E/Timber ( 3055): at
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:183)
E/Timber ( 3055): ... 13 more


--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

googl...@googlecode.com

unread,
Feb 17, 2015, 5:45:37 AM2/17/15
to google-gson...@googlegroups.com

Comment #1 on issue 625 by maciej.p...@gmail.com: FutureTypeAdapter.read()
I have the same exact issue and no ideas on how to actually fix it. As far
as I have investigated 'delegate' can be null only when
FutureTypeAdapter.setDelegate() was not called OR was called with a 'null'
object. Seems that the latter is impossible to happen as only call to
setDelegate is from here:

for (TypeAdapterFactory factory : factories) {
TypeAdapter<T> candidate = factory.create(this, type);
if (candidate != null) {
call.setDelegate(candidate);
typeTokenCache.put(type, candidate);
return candidate;
}
}
throw new IllegalArgumentException("GSON cannot handle " + type);

But the exception that should be thrown here when no 'candidate' was found
in the loop is also never thrown or is just ignored somewhere else in the
code.

googl...@googlecode.com

unread,
Feb 17, 2015, 5:55:44 AM2/17/15
to google-gson...@googlegroups.com

Comment #2 on issue 625 by maciej.p...@gmail.com: FutureTypeAdapter.read()
throws unhelpful exception
https://code.google.com/p/google-gson/issues/detail?id=625

I have the same exact issue and no ideas on how to actually fix it. As far
as I have investigated 'delegate' can be null only when
FutureTypeAdapter.setDelegate() was not called OR was called with a 'null'
object. Seems that the latter is impossible to happen as only call to
setDelegate is from Gson.java:355:

for (TypeAdapterFactory factory : factories) {
TypeAdapter<T> candidate = factory.create(this, type);
if (candidate != null) {
call.setDelegate(candidate);
typeTokenCache.put(type, candidate);
return candidate;
}
}
throw new IllegalArgumentException("GSON cannot handle " + type);

But the exception that should be thrown here when no 'candidate' was found
in the loop is also never thrown or is just ignored somewhere else in the
code.

I am reproducing this while trying to parse 8 collections of 100 objects in
separate 8 threads. All of the objects are of the same type. I think an
important factor is that it either happens at the very beginning of parsing
process by the first thread of the first collection element or it never
happens.
Reply all
Reply to author
Forward
0 new messages