java-slack-sdk icon indicating copy to clipboard operation
java-slack-sdk copied to clipboard

Deserialization on attachment id as Integer out of range

Open jbenallen opened this issue 8 months ago • 3 comments

Slack has generated attachments with id values that cannot be parsed into Java Integers. As a result, the Bolt SDK fails when reading those messages.

Team: T34263EUF / E7T5PNK3P Channel: C08KGS622HL Message TS: 1746210816.491199

  "attachments": [
    {
      ...
      "id": 8861161648288
    }
  ]

Reproducible in:

The Slack SDK version

1.45.2

Java Runtime version

17

OS info

n/a

Steps to reproduce:

Deserializing a message with an attachment that has an id that is too large for a Java Integer fails.

Expected result:

Parsing succeeds

Actual result:

An exception is thrown:

java.lang.NumberFormatException: Expected an int but was 8861161648288 at line 157 column 26 path $.attachments[0].id
com.google.gson.JsonSyntaxException: 
	at com.google.gson.internal.bind.TypeAdapters$7.read(TypeAdapters.java:229)
	at com.google.gson.internal.bind.TypeAdapters$7.read(TypeAdapters.java:219)
	at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:131)
	at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:222)
	at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:41)
	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.read(ReflectiveTypeAdapterFactory.java:131)
	at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:222)
	at com.google.gson.Gson.fromJson(Gson.java:963)
	at com.google.gson.Gson.fromJson(Gson.java:928)
	at com.google.gson.Gson.fromJson(Gson.java:877)
	at com.google.gson.Gson.fromJson(Gson.java:848)

Requirements

Please make sure if this topic is specific to this SDK. For general questions/issues about Slack API platform or its server-side, could you submit questions at https://my.slack.com/help/requests/new instead. :bow:

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you agree to those rules.

jbenallen avatar May 05 '25 16:05 jbenallen

Hi @jbenallen thanks for bringing this up 💯

It does seem like the "id" value 8,861,161,648,288 is larger then an integer 2,147,483,647 and raising a JSON syntax exception

Changing it to expect a long might resolve this issue, do you know what payload this might be originating from?

WilliamBergamin avatar May 05 '25 17:05 WilliamBergamin

Update changing the type of Attachment.id from 'inttolong` does resolve the issue but it leads to a breaking change in the SDK 🤔 more time needs to be put in this to come up with a non breaking change

https://github.com/slackapi/java-slack-sdk/blob/093d734985065797408c091bd21c126109d14064/slack-api-model/src/main/java/com/slack/api/model/Attachment.java#L91

WilliamBergamin avatar May 05 '25 20:05 WilliamBergamin

This was identified as a backend issue but this issue may be worth revisiting in our next major version bump

WilliamBergamin avatar May 06 '25 16:05 WilliamBergamin