Azure / azure-sdk-for-java

This repository is for active development of the Azure SDK for Java. For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/java/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-java.
MIT License
2.35k stars 1.99k forks source link

[BUG] java.lang.NoSuchMethodError: 'void com.azure.core.util.BinaryData.writeTo(java.nio.channels.WritableByteChannel)' #39057

Closed blessonmathewsam closed 8 months ago

blessonmathewsam commented 8 months ago

Describe the bug

Getting a NoSuchMethodError exception. Exception or Stack Trace

20:35:42.913 [main] ERROR c.a.i.implementation.IdentityClient - com.microsoft.aad.msal4j.MsalClientException: Token not found in the cache
20:35:42.928 [main] ERROR c.a.i.implementation.IdentityClient - java.util.concurrent.ExecutionException: java.lang.NoSuchMethodError: 'void com.azure.core.util.BinaryData.writeTo(java.nio.channels.WritableByteChannel)'
20:35:42.929 [main] ERROR c.a.identity.ClientSecretCredential - Azure Identity => ERROR in getToken() call for scopes [https://graph.microsoft.com/.default]: java.util.concurrent.ExecutionException: java.lang.NoSuchMethodError: 'void com.azure.core.util.BinaryData.writeTo(java.nio.channels.WritableByteChannel)'

Code Snippet

    public void sendMessage() {
        String clientId = "";
        String clientSecret = "";
        String tenantId = "";
        String teamId = "";
        String channelId = "";

        String[] scopes = new String[] { "https://graph.microsoft.com/.default" };

        ClientSecretCredential credential = new ClientSecretCredentialBuilder()
                .clientId(clientId).tenantId(tenantId).clientSecret(clientSecret).build();

        GraphServiceClient graphClient = new GraphServiceClient(credential, scopes);
        ChatMessage chatMessage = new ChatMessage();
        ItemBody body = new ItemBody();
        body.setContent("Hello World");

        graphClient.teams().byTeamId(teamId).channels().byChannelId(channelId).messages().post(chatMessage);
    }

pom.xml dependencies

                <dependency>
            <!-- Include the sdk as a dependency -->
            <groupId>com.microsoft.graph</groupId>
            <artifactId>microsoft-graph-beta</artifactId>
            <version>6.4.0</version>
        </dependency>

        <dependency>
            <groupId>com.azure</groupId>
            <artifactId>azure-identity</artifactId>
            <version>1.11.0</version>
            <exclusions>
                <exclusion>
                    <groupId>com.azure</groupId>
                    <artifactId>azure-core-http-netty</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.azure</groupId>
            <artifactId>azure-core-http-okhttp</artifactId>
            <version>1.11.19</version>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-stdlib</artifactId>
            <version>1.9.10</version>
        </dependency>

Dependency Tree

[INFO] +- com.microsoft.graph:microsoft-graph-beta:jar:6.4.0:compile
[INFO] |  +- com.microsoft.graph:microsoft-graph-core:jar:3.1.5:compile
[INFO] |  |  \- com.microsoft.kiota:microsoft-kiota-abstractions:jar:1.0.4:compile
[INFO] |  |     \- io.github.std-uritemplate:std-uritemplate:jar:0.0.53:runtime
[INFO] |  +- com.squareup.okhttp3:okhttp:jar:4.12.0:compile
[INFO] |  |  +- com.squareup.okio:okio:jar:3.6.0:compile
[INFO] |  |  \- org.jetbrains.kotlin:kotlin-stdlib-jdk8:jar:1.2.71:compile
[INFO] |  |     \- org.jetbrains.kotlin:kotlin-stdlib-jdk7:jar:1.2.71:compile
[INFO] |  +- jakarta.annotation:jakarta.annotation-api:jar:2.1.1:runtime
[INFO] |  +- com.microsoft.kiota:microsoft-kiota-authentication-azure:jar:1.0.4:runtime
[INFO] |  |  +- io.opentelemetry:opentelemetry-api:jar:1.35.0:runtime
[INFO] |  |  \- io.opentelemetry:opentelemetry-context:jar:1.35.0:runtime
[INFO] |  +- com.microsoft.kiota:microsoft-kiota-http-okHttp:jar:1.0.4:runtime
[INFO] |  |  \- io.opentelemetry.semconv:opentelemetry-semconv:jar:1.23.1-alpha:runtime
[INFO] |  +- com.microsoft.kiota:microsoft-kiota-serialization-json:jar:1.0.4:runtime
[INFO] |  +- com.microsoft.kiota:microsoft-kiota-serialization-text:jar:1.0.4:runtime
[INFO] |  +- com.microsoft.kiota:microsoft-kiota-serialization-form:jar:1.0.4:runtime
[INFO] |  \- com.microsoft.kiota:microsoft-kiota-serialization-multipart:jar:1.0.4:runtime
[INFO] +- com.azure:azure-identity:jar:1.11.0:compile
[INFO] |  +- com.azure:azure-core:jar:1.45.0:compile
[INFO] |  |  \- com.azure:azure-json:jar:1.1.0:compile
[INFO] |  +- com.microsoft.azure:msal4j-persistence-extension:jar:1.2.0:compile
[INFO] |  \- net.java.dev.jna:jna-platform:jar:4.5.2:compile
[INFO] +- com.azure:azure-core-http-okhttp:jar:1.11.19:compile
[INFO] |  \- com.squareup.okio:okio-jvm:jar:3.6.0:compile
[INFO] +- org.jetbrains.kotlin:kotlin-stdlib:jar:1.9.10:compile
[INFO] |  +- org.jetbrains.kotlin:kotlin-stdlib-common:jar:1.9.10:compile
[INFO] |  \- org.jetbrains:annotations:jar:13.0:compile
[INFO] \- com.azure.tools:azure-sdk-build-tool:jar:1.0.0:compile
[INFO]    +- org.apache.maven:maven-plugin-api:jar:3.8.6:compile
[INFO]    |  +- org.apache.maven:maven-model:jar:3.8.6:compile
[INFO]    |  +- org.apache.maven:maven-artifact:jar:3.8.6:compile
[INFO]    |  +- org.eclipse.sisu:org.eclipse.sisu.plexus:jar:0.3.5:compile
[INFO]    |  |  +- org.eclipse.sisu:org.eclipse.sisu.inject:jar:0.3.5:compile
[INFO]    |  |  \- org.codehaus.plexus:plexus-component-annotations:jar:1.5.5:compile
[INFO]    |  +- org.codehaus.plexus:plexus-utils:jar:3.3.1:compile
[INFO]    |  \- org.codehaus.plexus:plexus-classworlds:jar:2.6.0:compile
[INFO]    +- org.apache.maven.plugin-tools:maven-plugin-annotations:jar:3.6.4:compile
[INFO]    +- org.apache.maven:maven-project:jar:2.2.1:compile
[INFO]    |  +- org.apache.maven:maven-settings:jar:2.2.1:compile
[INFO]    |  +- org.apache.maven:maven-profile:jar:2.2.1:compile
[INFO]    |  +- org.apache.maven:maven-artifact-manager:jar:2.2.1:compile
[INFO]    |  |  +- org.apache.maven:maven-repository-metadata:jar:2.2.1:compile
[INFO]    |  |  +- org.apache.maven.wagon:wagon-provider-api:jar:1.0-beta-6:compile
[INFO]    |  |  \- backport-util-concurrent:backport-util-concurrent:jar:3.1:compile
[INFO]    |  +- org.apache.maven:maven-plugin-registry:jar:2.2.1:compile
[INFO]    |  +- org.codehaus.plexus:plexus-interpolation:jar:1.11:compile
[INFO]    |  \- org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9-stable-1:compile
[INFO]    |     \- classworlds:classworlds:jar:1.1-alpha-2:compile
[INFO]    +- com.github.javaparser:javaparser-core:jar:3.24.2:compile
[INFO]    +- net.oneandone.reflections8:reflections8:jar:0.11.7:compile
[INFO]    \- com.azure:azure-core-http-netty:jar:1.13.5:compile
[INFO]       +- io.netty:netty-handler-proxy:jar:4.1.36.Final:compile
[INFO]       |  \- io.netty:netty-codec-socks:jar:4.1.36.Final:compile
[INFO]       +- io.netty:netty-codec-http:jar:4.1.36.Final:compile
[INFO]       +- io.netty:netty-codec-http2:jar:4.1.36.Final:compile
[INFO]       +- io.netty:netty-transport-native-unix-common:jar:4.1.36.Final:compile
[INFO]       +- io.netty:netty-transport-native-epoll:jar:linux-x86_64:4.1.36.Final:compile
[INFO]       +- io.netty:netty-transport-native-kqueue:jar:osx-x86_64:4.1.36.Final:compile
[INFO]       +- io.netty:netty-tcnative-boringssl-static:jar:2.0.25.Final:compile
[INFO]       \- io.projectreactor.netty:reactor-netty-http:jar:1.0.33:compile
[INFO]          +- io.netty:netty-resolver-dns:jar:4.1.36.Final:compile
[INFO]          |  \- io.netty:netty-codec-dns:jar:4.1.36.Final:compile
[INFO]          +- io.netty:netty-resolver-dns-native-macos:jar:osx-x86_64:4.1.93.Final:compile
[INFO]          |  \- io.netty:netty-resolver-dns-classes-macos:jar:4.1.93.Final:compile
[INFO]          \- io.projectreactor.netty:reactor-netty-core:jar:1.0.33:compile
blessonmathewsam commented 8 months ago

Included the latest azure core dependency and it worked.

        <dependency>
            <groupId>com.azure</groupId>
            <artifactId>azure-core</artifactId>
            <version>1.47.0</version>
        </dependency>