Skip to content

fromJson intermittently fails with IllegalStateException when deserializing recursive structures in parallel #1829

Closed

Description

@mwalkerr

We are seeing an issue where fromJson results in a JsonSyntaxException with the root cause being an IllegalStateException. The stacktrace that comes from within the GSON library is:

Caused by: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:226)
at com.google.gson.Gson.fromJson(Gson.java:927)
at com.google.gson.Gson.fromJson(Gson.java:892)
at com.google.gson.Gson.fromJson(Gson.java:841)
at com.google.gson.Gson.fromJson(Gson.java:813)
at com.stripe.net.LiveStripeResponseGetter.request(LiveStripeResponseGetter.java:66)
... 136 common frames omitted
Caused by: java.lang.IllegalStateException: null
at com.google.gson.Gson$FutureTypeAdapter.read(Gson.java:1009)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:131)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:222)
... 141 common frames omitted

This seems to be due to a race condition in Gson.getAdapter where a FutureTypeAdapter is created by one thread and accessed by another before the delegate is set

public <T> TypeAdapter<T> getAdapter(TypeToken<T> type) {

edit: This looks to be well described by the comment on #625 : #625 (comment)

Activity

  1. Marcono1234 commented on Dec 1, 2020

    @Marcono1234
    Contributor

    This appears to be the same issue as #625

  2. changed the title [-]fromJson intermittently fails with IllegalStateException[/-] [+]fromJson intermittently fails with IllegalStateException when deserializing recursive structures in parallel[/+] on Dec 2, 2020
  3. mwalkerr commented on Dec 2, 2020

    @mwalkerr
    Author

    This appears to be the same issue as #625

    @Marcono1234 I believe you're right, thank you for linking that. Wish I would have found that sooner!

  4. Marcono1234 commented on Dec 5, 2022

    @Marcono1234
    Contributor

    This should be fixed by #1832, which will be available in the next release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions