java.lang.NullPointerException is displayed when CloudTasksClient.create()
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.
Environment details
- Specify the API at the beginning of the title. For example, "[vision]: ..."). General, Core, and Other are also allowed as types : CloudTasksClient.create()
- OS type and version: Windows 10
- Java version: 20
- Version(s):
<groupId>com.google.cloud</groupId> <artifactId>google-cloud-tasks</artifactId> 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.
External references such as API reference guides
- ?
Any additional information below
Following these steps guarantees the quickest resolution possible.
Thanks!
Can you provide more information about your dependencies (perhaps provide your pom.xml/ build.gradle file)? Running this locally for me works.
@JoeWang1127
this is my pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion>
<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>
try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { QueueName name = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); Queue response = cloudTasksClient.getQueue(name); }
with this as well its not working
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>
@lqiu96
I tried with latest bom its not working
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion>
<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>
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
@lqiu96 Its now worked like CHarm Thank you