Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IllegalStateException when deserializing message using conversation.history #1426

Closed
rasharab opened this issue Jan 24, 2025 · 4 comments · Fixed by #1429
Closed

IllegalStateException when deserializing message using conversation.history #1426

rasharab opened this issue Jan 24, 2025 · 4 comments · Fixed by #1429
Labels
bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented project:slack-api-client project:slack-api-client project:slack-api-model project:slack-api-model
Milestone

Comments

@rasharab
Copy link

rasharab commented Jan 24, 2025

Using conversations.history, we are getting exceptions when the slack sdk attempts to deserialize a customer's message history.

The issue is in the groups field inside the first attachment of the first file in the 169th message of the messages array in the API response is expected to be an array in your sdk but turned out to be an object.


Got an exception while calling conversations.history API (team: ****, error: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 164106 path $.messages[169].attachments[0].files[0].groups See https://github.com/google/gson/blob/main/Troubleshooting.md#unexpected-json-structure)

 j.l.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 164106 path $.messages[169].attachments[0].files[0].groups
See https://github.com/google/gson/blob/main/Troubleshooting.md#unexpected-json-structure
	at c.g.g.s.JsonReader.unexpectedTokenError(JsonReader.java:1768)
	at c.g.g.s.JsonReader.beginArray(JsonReader.java:430)
	at c.g.g.i.b.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:81)
	at c.g.g.i.b.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:59)
	at c.g.g.i.b.ReflectiveTypeAdapterFactory$2.readIntoField(ReflectiveTypeAdapterFactory.java:267)
	at c.g.g.i.b.ReflectiveTypeAdapterFactory$FieldReflectionAdapter.readField(ReflectiveTypeAdapterFactory.java:558)
	at c.g.g.i.b.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:516)
	... 33 common frames omitted
Wrapped by: c.g.g.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 164106 path $.messages[169].attachments[0].files[0].groups
See https://github.com/google/gson/blob/main/Troubleshooting.md#unexpected-json-structure
	at c.g.g.i.b.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:520)
	at c.g.g.i.b.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:40)
	at c.g.g.i.b.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:83)
	at c.g.g.i.b.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:59)
	at c.g.g.i.b.ReflectiveTypeAdapterFactory$2.readIntoField(ReflectiveTypeAdapterFactory.java:267)
	at c.g.g.i.b.ReflectiveTypeAdapterFactory$FieldReflectionAdapter.readField(ReflectiveTypeAdapterFactory.java:558)
	at c.g.g.i.b.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:516)
	at c.g.g.i.b.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:40)
	at c.g.g.i.b.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:83)
	at c.g.g.i.b.Collect...

@rasharab rasharab changed the title IllegalStateException when deserializing message IllegalStateException when deserializing message using conversation.history Jan 25, 2025
@seratch seratch added bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented project:slack-api-client project:slack-api-client project:slack-api-model project:slack-api-model and removed untriaged labels Jan 25, 2025
@seratch seratch added this to the 1.45.2 milestone Jan 25, 2025
@seratch
Copy link
Member

seratch commented Jan 25, 2025

Hi @rasharab, thanks for taking the time to report this issue and we're sorry for the disruption. We will look into it early next weeek.

@rasharab
Copy link
Author

rasharab commented Jan 25, 2025

Thanks.

We've hit another different exception as well in a different payload for another customer. This is at another point in the payload body: reply_users

Got an exception while calling conversations.history API (team: ***, error: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 93854 path $.messages[142].attachments[0].files[0].shares.public.[0].reply_users See https://github.com/google/gson/blob/main/Troubleshooting.md#unexpected-json-structure)

j.l.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 93854 path $.messages[142].attachments[0].files[0].shares.public.[0].reply_users See https://github.com/google/gson/blob/main/Troubleshooting.md#unexpected-json-structure at c.g.g.s.JsonReader.unexpectedTokenError(JsonReader.java:1768) at c.g.g.s.JsonReader.beginArray(JsonReader.java:430) at c.g.g.i.b.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:81) at c.g.g.i.b.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:59) at c.g.g.i.b.ReflectiveTypeAdapterFactory$2.readIntoField(ReflectiveTypeAdapterFactory.java:267) at c.g.g.i.b.ReflectiveTypeAdapterFactory$FieldReflectionAdapter.readField(ReflectiveTypeAdapterFactory.java:558) at c.g.g.i.b.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:516) ... 45 common frames omitted Wrapped by: c.g.g.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 93854 path $.messages[142].attachments[0].files[0].shares.public.[0].reply_users See https://github.com/google/gson/blob/main/Troubleshooting.md#unexpected-json-structure at c.g.g.i.b.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:520) at c.g.g.i.b.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:40) at c.g.g.i.b.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:83) at c.g.g.i.b.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:59) at c.g.g.i.b.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:40) at c.g.g.i.b.MapTypeAdapterFactory$Adapter.read(MapTypeAdapterFactory.java:200) at c.g.g.i.b.MapTypeAdapterFactory$Adapter.read(MapTypeAdapterFactory.java:154) at c.g.g.i.b.ReflectiveTypeAdapterFactory$2.readIntoField(ReflectiveTypeAdapterFactory.java:267) at c.g.g.i.b.ReflectiveTypeAdapterFactory$FieldReflectionAdapter.readField(ReflectiveTypeAdapterFactory.java:558)

@rasharab
Copy link
Author

rasharab commented Jan 27, 2025

@seratch Thank you so much for your fixes.

Here's another different one:

Got an exception while calling conversations.replies API (team: ***, error: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at path $.file.channels)

 j.l.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at path $.file.channels
	at c.g.g.i.b.JsonTreeReader.expect(JsonTreeReader.java:179)
	at c.g.g.i.b.JsonTreeReader.beginArray(JsonTreeReader.java:78)
	at c.g.g.i.b.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:81)
	at c.g.g.i.b.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:59)
	at c.g.g.i.b.ReflectiveTypeAdapterFactory$2.readIntoField(ReflectiveTypeAdapterFactory.java:267)
	at c.g.g.i.b.ReflectiveTypeAdapterFactory$FieldReflectionAdapter.readField(ReflectiveTypeAdapterFactory.java:558)
	at c.g.g.i.b.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:516)
	... 43 common frames omitted
Wrapped by: c.g.g.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at path $.file.channels
	at c.g.g.i.b.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:520)
	at c.g.g.i.b.ReflectiveTypeAdapterFactory$2.readIntoField(ReflectiveTypeAdapterFactory.java:267)
	at c.g.g.i.b.ReflectiveTypeAdapterFactory$FieldReflectionAdapter.readField(ReflectiveTypeAdapterFactory.java:558)
	at c.g.g.i.b.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:516)
	at c.google.gson.Gson.fromJson(Gson.java:1361)
	at c.google.gson.Gson.fromJson(Gson.java:1463)
	at c.google.gson.Gson.fromJson(Gson.java:1434)
	at c.g.g.i.b.TreeTypeAdapter$GsonContextImpl.deserialize(TreeTypeAdapter.java:199)
	at c.s.a.u.j.GsonLayoutBlockFactory.deserialize(GsonLayoutBlockFactory.java:31)
	at c.s.a.u.j.GsonLayoutBlockFactory.deserialize(GsonLayoutBlockFactory.java:12)
	at c.g.g.i.b.TreeTypeAdapter.read(TreeTypeAdapter.java:95)
	at c.g.g.i.b.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:40)
	at c.g.g.i.b.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:83)
	at c.g.g.i.b.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:59)
	at c.g.g.i.b.ReflectiveTypeAdapt...

@seratch
Copy link
Member

seratch commented Jan 28, 2025

@rasharab thanks for letting me know this. i will add the same workaround to as many array type properties as possible

seratch added a commit to seratch/java-slack-sdk that referenced this issue Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented project:slack-api-client project:slack-api-client project:slack-api-model project:slack-api-model
Projects
None yet
2 participants