googleapis / java-bigquery

Apache License 2.0
108 stars 119 forks source link

BigQuery: java.lang.NoSuchMethodError: 'java.lang.Object com.google.common.collect.Iterables.getFirst(java.lang.Iterable, java.lang.Object)' #3413

Closed niketan-nath closed 4 weeks ago

niketan-nath commented 1 month ago

Hi everyone,

I'm trying to query a BigQuery dataset from my Java application running on Java 17. I have exported the path to the Service Account Key in my environment. Also, the required workload identity annotations are set up to provide access to the SA for which I have the keys locally.

BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();

When I try to execute this line, I get the following error: java.lang.NoSuchMethodError: 'java.lang.Object com.google.common.collect.Iterables.getFirst(java.lang.Iterable, java.lang.Object)'

I'm using Maven as a build tool and this is what my pom.xml file contains:

<dependency>
            <groupId>com.google.cloud</groupId>
            <artifactId>google-cloud-bigquery</artifactId>
            <version>2.40.2</version>
</dependency>

I tried adding the Guava dependency separately as well:

<dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>33.1.0-jre</version>
</dependency>

Could someone add any pointers on how to proceed further?

PhongChuong commented 1 month ago

Hi @niketan-nath , Can you please post a stack trace?

niketan-nath commented 1 month ago

Hi @PhongChuong, sure. Following is the stack trace:

java.lang.NoSuchMethodError: 'java.lang.Object com.google.common.collect.Iterables.getFirst(java.lang.Iterable, java.lang.Object)'
    at com.google.auth.oauth2.OAuth2Credentials.getFromServiceLoader(OAuth2Credentials.java:477)
    at com.google.auth.oauth2.UserCredentials.<init>(UserCredentials.java:104)
    at com.google.auth.oauth2.UserCredentials.<init>(UserCredentials.java:62)
    at com.google.auth.oauth2.UserCredentials$Builder.build(UserCredentials.java:477)
    at com.google.auth.oauth2.UserCredentials.fromJson(UserCredentials.java:141)
    at com.google.auth.oauth2.GoogleCredentials.fromStream(GoogleCredentials.java:169)
    at com.google.auth.oauth2.DefaultCredentialsProvider.getDefaultCredentialsUnsynchronized(DefaultCredentialsProvider.java:190)
    at com.google.auth.oauth2.DefaultCredentialsProvider.getDefaultCredentials(DefaultCredentialsProvider.java:126)
    at com.google.auth.oauth2.GoogleCredentials.getApplicationDefault(GoogleCredentials.java:125)
    at com.google.auth.oauth2.GoogleCredentials.getApplicationDefault(GoogleCredentials.java:97)
    at com.google.cloud.ServiceOptions.defaultCredentials(ServiceOptions.java:345)
    at com.google.cloud.ServiceOptions.<init>(ServiceOptions.java:310)
    at com.google.cloud.bigquery.BigQueryOptions.<init>(BigQueryOptions.java:91)
    at com.google.cloud.bigquery.BigQueryOptions.<init>(BigQueryOptions.java:30)
    at com.google.cloud.bigquery.BigQueryOptions$Builder.build(BigQueryOptions.java:86)
    at com.google.cloud.bigquery.BigQueryOptions.getDefaultInstance(BigQueryOptions.java:161)
    at io.harness.adminportal.configuration.BigQueryDataFetch.fetchBQData(BigQueryDataFetch.java:21)

Please let me know if you need any other details. Thanks! 🙌

PhongChuong commented 1 month ago

I don't think this is specific to BigQuery. Can you ask the same question in google-auth-library-java?

PhongChuong commented 4 weeks ago

Closing this item. Feel free to create a new issue if there are further questions.