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

Most upvoted comments

@jdlee726 Thanks to your latest reply, I managed to reproduce the error. Here is an example conversations.history API response to reproduce the error:

{
  "ok": true,
  "oldest": "1695106171.334469",
  "messages": [
    {
      "client_msg_id": "xxx",
      "type": "message",
      "text": "test\n<https://xxx.slack.com/archives/C123/p1695106171334469>",
      "user": "U123",
      "ts": "1695106171.334469",
      "blocks": [
        {
          "type": "rich_text",
          "block_id": "Qkc",
          "elements": [
            {
              "type": "rich_text_section",
              "elements": [
                {
                  "type": "text",
                  "text": "test\n"
                },
                {
                  "type": "link",
                  "url": "https://xxx.slack.com/archives/C123/p1695106171334469"
                }
              ]
            }
          ]
        }
      ],
      "team": "T123",
      "edited": {
        "user": "U123",
        "ts": "1695106197.000000"
      },
      "attachments": [
        {
          "from_url": "https://xxx.slack.com/archives/C123/p1695106171334469",
          "ts": "1695106171.334469",
          "author_id": "U123",
          "channel_id": "C123",
          "channel_team": "T123",
          "is_msg_unfurl": true,
          "message_blocks": [
            {
              "team": "T123",
              "channel": "C123",
              "ts": "1695106171.334469",
              "message": {
                "blocks": [
                  {
                    "type": "rich_text",
                    "block_id": "Qkc",
                    "elements": [
                      {
                        "type": "rich_text_section",
                        "elements": [
                          {
                            "type": "text",
                            "text": "test\n"
                          },
                          {
                            "type": "link",
                            "url": "https://xxx.slack.com/archives/C123/p1695106171334469"
                          }
                        ]
                      }
                    ]
                  }
                ]
              }
            }
          ],
          "id": 1,
          "original_url": "https://xxx.slack.com/archives/C123/p1695106171334469",
          "fallback": "fallback",
          "text": "test\n<https://xxx.slack.com/archives/C123/p1695106171334469>",
          "author_name": "Kaz",
          "author_link": "https://xxx.slack.com/team/U123",
          "author_icon": "https://avatars.slack-edge.com/2023-09-19/5927659638721_20cd515c6ad81ae7b17a_48.jpg",
          "author_subname": "Kaz Sera",
          "mrkdwn_in": [
            "text"
          ],
          "footer": "Slack conversation"
        }
      ]
    }
  ],
  "has_more": false,
  "pin_count": 0,
  "channel_actions_ts": 1638492970,
  "channel_actions_count": 0
}

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.