Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.NullPointerException is displayed when CloudTasksClient.create() #10804

Closed
RYenike opened this issue May 7, 2024 · 7 comments
Closed
Labels
needs more info This issue needs more information from the customer to proceed. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@RYenike
Copy link

RYenike commented May 7, 2024

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.lastIndexOf(int)" because "endpoint" is null
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.validateEndpoint(InstantiatingGrpcChannelProvider.java:746)
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.withEndpoint(InstantiatingGrpcChannelProvider.java:195)
at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:199)
at com.google.cloud.tasks.v2.stub.GrpcCloudTasksStub.create(GrpcCloudTasksStub.java:254)
at com.google.cloud.tasks.v2.stub.CloudTasksStubSettings.createStub(CloudTasksStubSettings.java:407)
at com.google.cloud.tasks.v2.CloudTasksClient.(CloudTasksClient.java:533)
at com.google.cloud.tasks.v2.CloudTasksClient.create(CloudTasksClient.java:516)
at com.google.cloud.tasks.v2.CloudTasksClient.create(CloudTasksClient.java:508)

Environment details

  1. Specify the API at the beginning of the title. For example, "[vision]: ...").
    General, Core, and Other are also allowed as types : CloudTasksClient.create()
  2. OS type and version: Windows 10
  3. Java version: 20
  4. Version(s):
    com.google.cloud
    google-cloud-tasks
    2.42.0

Steps to reproduce

CloudTasksClient client = CloudTasksClient.create()

Code example

// example

CloudTasksClient client = CloudTasksClient.create()

Stack trace

Any relevant stacktrace here.

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.lastIndexOf(int)" because "endpoint" is null
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.validateEndpoint(InstantiatingGrpcChannelProvider.java:746)
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.withEndpoint(InstantiatingGrpcChannelProvider.java:195)
at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:199)
at com.google.cloud.tasks.v2.stub.GrpcCloudTasksStub.create(GrpcCloudTasksStub.java:254)
at com.google.cloud.tasks.v2.stub.CloudTasksStubSettings.createStub(CloudTasksStubSettings.java:407)
at com.google.cloud.tasks.v2.CloudTasksClient.(CloudTasksClient.java:533)
at com.google.cloud.tasks.v2.CloudTasksClient.create(CloudTasksClient.java:516)
at com.google.cloud.tasks.v2.CloudTasksClient.create(CloudTasksClient.java:508)

External references such as API reference guides

  • ?

Any additional information below

Following these steps guarantees the quickest resolution possible.

Thanks!

@mpeddada1 mpeddada1 added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. labels May 8, 2024
@lqiu96
Copy link
Contributor

lqiu96 commented May 9, 2024

Can you provide more information about your dependencies (perhaps provide your pom.xml/ build.gradle file)? Running this locally for me works.

@JoeWang1127 JoeWang1127 added the needs more info This issue needs more information from the customer to proceed. label May 17, 2024
@RYenike
Copy link
Author

RYenike commented May 28, 2024

@JoeWang1127

this is my pom.xml


4.0.0

<groupId>com.autozone</groupId>
<artifactId>data-sync</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
   <groupId>com.azo.qa.flex</groupId>
   <artifactId>legacy-parent</artifactId>
   <version>1.1.11-SNAPSHOT</version>
</parent>

<properties>
   <maven.compiler.source>1.8</maven.compiler.source>
   <maven.compiler.target>1.8</maven.compiler.target>
   <main.class>com.autozone.datasyncautomation.testrunner.TestRunner</main.class>
</properties>

<dependencies>
   <dependency>
      <groupId>org.java-websocket</groupId>
      <artifactId>Java-WebSocket</artifactId>
      <version>1.5.0</version>
   </dependency>
   <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>libraries-bom</artifactId>
      <version>26.1.5</version>
      <type>pom</type>
   </dependency>
   <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>google-cloud-pubsub</artifactId>
      <version>1.122.2</version>
   </dependency>
   <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>google-cloud-storage</artifactId>
      <version>2.16.0</version>
   </dependency>
   <!-- https://mvnrepository.com/artifact/com.google.cloud/google-cloud-bigquery -->
   <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>google-cloud-bigquery</artifactId>
      <version>2.35.0</version>
   </dependency>
   <!-- https://mvnrepository.com/artifact/com.google.cloud/google-cloud-tasks -->
   <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>google-cloud-tasks</artifactId>
      <version>2.42.0</version>
   </dependency>


</dependencies>
<profiles>
   <profile>
      <id>shade</id>
      <activation>
         <activeByDefault>true</activeByDefault>
      </activation>
      <build>
         <resources>
            <resource>
               <directory>resources/</directory>
            </resource>
         </resources>
         <plugins>
            <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-checkstyle-plugin</artifactId>
               <executions>
                  <execution>
                     <id>validate</id>
                     <phase>validate</phase>
                  </execution>
               </executions>
               <configuration>
            <failOnViolation>false</failOnViolation>
         </configuration>
            </plugin>
            <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-shade-plugin</artifactId>
               <executions>
                  <execution>
                     <id>build</id>
                  </execution>
               </executions>
            </plugin>
         </plugins>
      </build>
   </profile>
</profiles>

@RYenike
Copy link
Author

RYenike commented May 28, 2024

try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) {
QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]");
Queue response = cloudTasksClient.getQueue(name);
}

with this as well its not working

@lqiu96
Copy link
Contributor

lqiu96 commented May 28, 2024

There error is most likely due to how we resolve the endpoint. I see your dependencies are a bit old and it is probably due to a combo of old client library + new runtime library and the is unable to determine the endpoint. Can you try and change your pom.xml to use the latest libraries-bom and let us know if that works?

i.e.

<dependencyManagement>
   <dependencies>
   <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>libraries-bom</artifactId>
      <version>26.39.0</version> <!-- Latest libraries bom version -->
      <type>pom</type>
      <scope>import</scope>
   </dependency>
   </dependencies>
</dependencyManagement>

<dependencies>
   <dependency>
      <groupId>org.java-websocket</groupId>
      <artifactId>Java-WebSocket</artifactId>
      <version>1.5.0</version>
   </dependency>
   <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>google-cloud-pubsub</artifactId>  <!-- Version is managed by libraries-bom above -->
   </dependency>
   <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>google-cloud-storage</artifactId> <!-- Version is managed by libraries-bom above -->
   </dependency>
   <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>google-cloud-bigquery</artifactId> <!-- Version is managed by libraries-bom above -->
   </dependency>
   <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>google-cloud-tasks</artifactId> <!-- Version is managed by libraries-bom above -->
   </dependency>
</dependencies>

@RYenike
Copy link
Author

RYenike commented May 28, 2024

@lqiu96

I tried with latest bom its not working


4.0.0

<groupId>com.autozone</groupId>
<artifactId>data-sync</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
   <groupId>com.azo.qa.flex</groupId>
   <artifactId>legacy-parent</artifactId>
   <version>1.1.11-SNAPSHOT</version>
</parent>

<properties>
   <maven.compiler.source>1.8</maven.compiler.source>
   <maven.compiler.target>1.8</maven.compiler.target>
   <main.class>com.autozone.datasyncautomation.testrunner.TestRunner</main.class>
</properties>

<dependencies>
   <dependency>
      <groupId>org.java-websocket</groupId>
      <artifactId>Java-WebSocket</artifactId>
      <version>1.5.0</version>
   </dependency>
   <!-- https://mvnrepository.com/artifact/com.google.cloud/libraries-bom -->
   <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>libraries-bom</artifactId>
      <version>26.39.0</version>
      <type>pom</type>
   </dependency>

   <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>google-cloud-pubsub</artifactId>
      <version>1.122.2</version>
   </dependency>
   <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>google-cloud-storage</artifactId>
      <version>2.16.0</version>
   </dependency>
   <!-- https://mvnrepository.com/artifact/com.google.cloud/google-cloud-bigquery -->
   <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>google-cloud-bigquery</artifactId>
      <version>2.35.0</version>
   </dependency>
   <!-- https://mvnrepository.com/artifact/com.google.cloud/google-cloud-tasks -->
   <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>google-cloud-tasks</artifactId>
      <version>2.42.0</version>
   </dependency>


</dependencies>
<profiles>
   <profile>
      <id>shade</id>
      <activation>
         <activeByDefault>true</activeByDefault>
      </activation>
      <build>
         <resources>
            <resource>
               <directory>resources/</directory>
            </resource>
         </resources>
         <plugins>
            <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-checkstyle-plugin</artifactId>
               <executions>
                  <execution>
                     <id>validate</id>
                     <phase>validate</phase>
                  </execution>
               </executions>
               <configuration>
            <failOnViolation>false</failOnViolation>
         </configuration>
            </plugin>
            <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-shade-plugin</artifactId>
               <executions>
                  <execution>
                     <id>build</id>
                  </execution>
               </executions>
            </plugin>
         </plugins>
      </build>
   </profile>
</profiles>

@lqiu96
Copy link
Contributor

lqiu96 commented May 28, 2024

You're declaring it in the <dependencies> section. You need to declare the <dependencyManagement> section.

Additionally, you are also specifying the versions and not letting the bom set the versions for you:
i.e.

   <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>google-cloud-tasks</artifactId>
      <version>2.42.0</version>
   </dependency>

It should be

   <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>google-cloud-tasks</artifactId>
   </dependency>

once you add in the bom

@RYenike
Copy link
Author

RYenike commented May 31, 2024

@lqiu96 Its now worked like CHarm Thank you

@RYenike RYenike closed this as completed May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more info This issue needs more information from the customer to proceed. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

4 participants