java-slack-sdk: A recursive message reference causes a JSON data parsing error
(Describe your issue and goal here)
Reproducible in:
having the follwing json string for an message from slack platform. apparently, there is no ‘type’ field in response, but, GsonLayoutBlockFactory.deserialize() requires “type” field.
{
"team": "<Team ID>",
"channel": "<Channel ID>",
"ts": "<timestamp>",
"message": {
"blocks": [
{
"type": "rich_text",
"block_id": "rVD",
"elements": [
{
"type": "rich_text_section",
"elements": [
{
"type": "text",
"text": "TEXT\n"
}
]
},
{
"type": "rich_text_list",
"elements": [
{
"type": "rich_text_section",
"elements": [
{
"type": "text",
"text": "TEXT"
}
]
},
{
"type": "rich_text_section",
"elements": [
{
"type": "text",
"text": "TEXT"
}
]
},
{
"type": "rich_text_section",
"elements": [
{
"type": "text",
"text": "TEXT"
}
]
},
{
"type": "rich_text_section",
"elements": [
{
"type": "text",
"text": "TEXT"
}
]
}
],
"style": "ordered",
"indent": 0,
"border": 0
}
]
}
]
}
}
The Slack SDK version
google gson 2.10.1
[INFO] +- com.slack.api:slack-api-client:jar:1.32.0:compile
[INFO] | +- com.slack.api:slack-api-model:jar:1.32.0:compile
[INFO] +- com.slack.api:bolt:jar:1.32.0:compile
[INFO] | +- com.slack.api:slack-app-backend:jar:1.32.0:compile
[INFO] +- com.slack.api:bolt-socket-mode:jar:1.32.0:compile
[INFO] +- com.slack.api:bolt-jakarta-servlet:jar:1.32.0:compile
[INFO] +- com.slack.api:slack-api-client:jar:1.32.0:compile
[INFO] | +- com.slack.api:slack-api-model:jar:1.32.0:compile
[INFO] +- com.slack.api:bolt:jar:1.32.0:compile
[INFO] | +- com.slack.api:slack-app-backend:jar:1.32.0:compile
[INFO] +- com.slack.api:bolt-jakarta-servlet:jar:1.32.0:compile
[INFO] | +- com.slack.api:slack-api-client:jar:1.32.0:compile
[INFO] | | +- com.slack.api:slack-api-model:jar:1.32.0:compile
[INFO] | +- com.slack.api:bolt:jar:1.32.0:compile
[INFO] | | \- com.slack.api:slack-app-backend:jar:1.32.0:compile
[INFO] | \- com.slack.api:bolt-jakarta-servlet:jar:1.32.0:compile
[INFO] | | +- com.slack.api:slack-api-client:jar:1.32.0:compile
[INFO] | | | +- com.slack.api:slack-api-model:jar:1.32.0:compile
[INFO] | | +- com.slack.api:bolt:jar:1.32.0:compile
[INFO] | | | \- com.slack.api:slack-app-backend:jar:1.32.0:compile
[INFO] | | \- com.slack.api:bolt-jakarta-servlet:jar:1.32.0:compile
Java Runtime version
openjdk 20.0.2 2023-07-18 OpenJDK Runtime Environment (build 20.0.2+9-78) OpenJDK 64-Bit Server VM (build 20.0.2+9-78, mixed mode, sharing)
OS info
ProductName: macOS ProductVersion: 13.5.2 BuildVersion: 22G91 Darwin Kernel Version 22.6.0: Wed Jul 5 22:21:56 PDT 2023; root:xnu-8796.141.3~6/RELEASE_X86_64
Steps to reproduce:
methodClient.conversationsHistory()
Expected result:
normal conversion history
Actual result:
call stack
java.lang.NullPointerException: Cannot invoke "com.google.gson.JsonPrimitive.getAsString()" because "prim" is null
at com.slack.api.util.json.GsonLayoutBlockFactory.deserialize(GsonLayoutBlockFactory.java:29)
at com.slack.api.util.json.GsonLayoutBlockFactory.deserialize(GsonLayoutBlockFactory.java:12)
at com.google.gson.internal.bind.TreeTypeAdapter.read(TreeTypeAdapter.java:76)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:40)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:82)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.readIntoField(ReflectiveTypeAdapterFactory.java:212)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$FieldReflectionAdapter.readField(ReflectiveTypeAdapterFactory.java:433)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:393)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:40)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:82)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.readIntoField(ReflectiveTypeAdapterFactory.java:212)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$FieldReflectionAdapter.readField(ReflectiveTypeAdapterFactory.java:433)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:393)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:40)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:82)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.readIntoField(ReflectiveTypeAdapterFactory.java:212)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$FieldReflectionAdapter.readField(ReflectiveTypeAdapterFactory.java:433)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:393)
at com.google.gson.Gson.fromJson(Gson.java:1227)
at com.google.gson.Gson.fromJson(Gson.java:1137)
at com.google.gson.Gson.fromJson(Gson.java:1047)
at com.google.gson.Gson.fromJson(Gson.java:982)
at com.slack.api.methods.impl.MethodsClientImpl.parseJsonResponseAndRunListeners(MethodsClientImpl.java:3539)
at com.slack.api.methods.impl.MethodsClientImpl.parseJsonResponseAndRunListeners(MethodsClientImpl.java:3526)
at com.slack.api.methods.impl.MethodsClientImpl.postFormWithTokenAndParseResponse(MethodsClientImpl.java:3433)
at com.slack.api.methods.impl.MethodsClientImpl.conversationsHistory(MethodsClientImpl.java:1796)
at com.slack.api.methods.impl.MethodsClientImpl.conversationsHistory(MethodsClientImpl.java:1801)
Requirements
About this issue
- Original URL
- State: closed
- Created 9 months ago
- Comments: 18 (7 by maintainers)
Commits related to this issue
- Fix #1207 by correcting the typing introduced by #1181 — committed to seratch/java-slack-sdk by seratch 9 months ago
- Fix #1207 by correcting the typing introduced by #1181 (#1208) * Fix #1207 by correcting the typing introduced by #1181 * Run ./scripts/run_no_prep_tests.sh — committed to slackapi/java-slack-sdk by seratch 9 months ago
@jdlee726 Thanks to your latest reply, I managed to reproduce the error. Here is an example
conversations.history
API response to reproduce the error:We will fix this issue as soon as possible and then release a patch. Thank you again for taking the time to report this and we apologize for the disruption.
Thanks for sharing the details. I tried to reproduce the error with JDK 20 + Vavr but still no luck. The NPE itself is just an outcome of the GSON misbehavior (please note that I am still unsure if this could be an issue on GSON side), so avoiding the exception is not a solution for you. Even if I change the code to not throw the exception, your code still fails to load the API response.
I’m sorry to say this, but I don’t have any further ideas to figure out the cause of your issue now. Please let us know whenever you find anything new on this.