slackapi / java-slack-sdk

Slack Developer Kit (including Bolt for Java) for any JVM language
https://slack.dev/java-slack-sdk/
MIT License
570 stars 209 forks source link

Can not get an instance of class Slack #1244

Closed ayoubAnbara closed 9 months ago

ayoubAnbara commented 9 months ago

Reproducible in:

[INFO] - com.slack.api:slack-api-client:jar:1.36.1:compile [INFO] +- com.slack.api:slack-api-model:jar:1.36.1:compile openjdk version "21" 2023-09-19 LTS OpenJDK Runtime Environment Temurin-21+35 (build 21+35-LTS) OpenJDK 64-Bit Server VM Temurin-21+35 (build 21+35-LTS, mixed mode, sharing) zsh: command not found: sw_vers

The Slack SDK version

[INFO] - com.slack.api:slack-api-client:jar:1.36.1:compile [INFO] +- com.slack.api:slack-api-model:jar:1.36.1:compile

Java Runtime version

openjdk version "21" 2023-09-19 LTS OpenJDK Runtime Environment Temurin-21+35 (build 21+35-LTS) OpenJDK 64-Bit Server VM Temurin-21+35 (build 21+35-LTS, mixed mode, sharing)

OS info

output of cat /etc/os-release

PRETTY_NAME="Ubuntu 22.04.3 LTS" NAME="Ubuntu" VERSION_ID="22.04" VERSION="22.04.3 LTS (Jammy Jellyfish)" VERSION_CODENAME=jammy ID=ubuntu ID_LIKE=debian HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" UBUNTU_CODENAME=jammy

Steps to reproduce:

(Share the commands to run, source code, and project settings (e.g., pom.xml/build.gradle))

I use Spring Boot 3.2.0 with Java 21, when I call Slack slack = Slack.getInstance();, it throw an exception which is java.lang.NoSuchFieldError

Expected result:

Getting instance of class Slack

Actual result:

Caused by: java.lang.NoSuchFieldError: Class okio.ByteString does not have member field 'okio.ByteString$Companion Companion'
    at okhttp3.internal.Util.<clinit>(Util.kt:71) ~[okhttp-4.12.0.jar:na]
    at okhttp3.internal.concurrent.TaskRunner.<clinit>(TaskRunner.kt:309) ~[okhttp-4.12.0.jar:na]
    at okhttp3.ConnectionPool.<init>(ConnectionPool.kt:41) ~[okhttp-4.12.0.jar:na]
    at okhttp3.ConnectionPool.<init>(ConnectionPool.kt:47) ~[okhttp-4.12.0.jar:na]
    at okhttp3.OkHttpClient$Builder.<init>(OkHttpClient.kt:471) ~[okhttp-4.12.0.jar:na]
    at com.slack.api.util.http.SlackHttpClient.buildOkHttpClient(SlackHttpClient.java:45) ~[slack-api-client-1.36.1.jar:1.36.1]
    at com.slack.api.util.http.SlackHttpClient.<init>(SlackHttpClient.java:102) ~[slack-api-client-1.36.1.jar:1.36.1]
    at com.slack.api.util.http.SlackHttpClient.<init>(SlackHttpClient.java:98) ~[slack-api-client-1.36.1.jar:1.36.1]
    at com.slack.api.util.http.SlackHttpClient.<init>(SlackHttpClient.java:94) ~[slack-api-client-1.36.1.jar:1.36.1]
    at com.slack.api.Slack.<clinit>(Slack.java:73) ~[slack-api-client-1.36.1.jar:1.36.1]
    at multichannel.management.monitoring.SlackChannelErrorReporter.<init>(SlackChannelErrorReporter.java:23) ~[classes/:na]
    at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62) ~[na:na]
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502) ~[na:na]
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:486) ~[na:na]
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:197) ~[spring-beans-6.1.1.jar:6.1.1]
    ... 36 common frames omitted
seratch commented 9 months ago

Hi @ayoubAnbara, thanks for taking the time to write in. As you can see by searching this issue tracker, Spring Boot's pom has been causing a similar binary-compatibility issue as it forcibly overwrites the version of okhttp and its dependencies. This SDK's latest version expects the following versions (or other versions that are binary compatible with). So, could you try explicitly specifying these versions in your pom.xml or build.gradle?

If the kotlin version is the only cause of this issue, we may consider switching to an old enough version for smoother adoption in Spring Boot apps. However, if the cause is okhttp/okio, we won't change our current policies. The reason why we depend on the latest version is to resolve publicly reported security issues.

I hope this clarifies.

ayoubAnbara commented 9 months ago

Hi @seratch , Could you please mention which artifact id of Kotlin should I use in my pom.xml? It is this:

       <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-stdlib</artifactId>
            <version>1.9.20</version>
        </dependency>
seratch commented 9 months ago

As you can find here, the depedency must be:

    <dependency>
      <groupId>org.jetbrains.kotlin</groupId>
      <artifactId>kotlin-stdlib-jdk8</artifactId>
      <version>1.8.21</version>
      <scope>compile</scope>
    </dependency>

EDIT: If the difference of the kotlin version (1.8 vs 1.9) is causing the issue, we will downgrade the kotlin minor version in future releases.

ayoubAnbara commented 9 months ago

I discovered that there is a dependency on my pom.xml that has as transitive dependency okhttp com.squareup.okhttp:okhttp:2.7.5 not okhttp3

I tested slack-api with just spring boot 3.2.0 starters and it works fine. If you know any method to force slack-api to use their own transitive dependencies without upgrading dependency okhttp in the other dependency, please let me know. thank you @seratch for your assistance.