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

v0.7.2 java.lang.NullPointerException: Cannot invoke "java.lang.String.replaceAll(java.lang.String, java.lang.String)" because the return value of "java.lang.Package.getImplementationTitle()" is null #2061

Open
abcfy2 opened this issue Jan 1, 2025 · 5 comments
Assignees
Labels

Comments

@abcfy2
Copy link
Contributor

abcfy2 commented Jan 1, 2025

Describe the bug

This is the new BUG only in 0.7.2, but 0.7.1 is working very well.

I have this code in my project:

public class DbService {
  private static final Logger logger = LogManager.getLogger(DbService.class);
  private final Client client;

  public DbService() {
    this.client = new Client.Builder()
      .addEndpoint("http://localhost:8123")
      .setUsername("default")
      .setPassword("")
      .build();
  }
// ... SNIP ...
}

This code runs in Vertx worker verticle (which is VIRTUAL THREAD environment)

And I will see this stracetrack:

java.lang.ExceptionInInitializerError: null
	at java.lang.J9VMInternals.recordInitializationFailure(J9VMInternals.java:185) ~[?:?]
	at com.shifudao.datahub.RouteBuilder.lambda$initLegacyRoutes$8(RouteBuilder.java:83) ~[datahub-ng-all.jar:?]
	at com.shifudao.datahub.utils.RouteHelper.lambda$addQueryRoute$1(RouteHelper.java:89) ~[datahub-ng-all.jar:?]
	at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1281) ~[datahub-ng-all.jar:?]
	at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:177) ~[datahub-ng-all.jar:?]
	at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:145) ~[datahub-ng-all.jar:?]
	at io.vertx.ext.web.handler.impl.LoggerHandlerImpl.handle(LoggerHandlerImpl.java:189) ~[datahub-ng-all.jar:?]
	at io.vertx.ext.web.handler.impl.LoggerHandlerImpl.handle(LoggerHandlerImpl.java:48) ~[datahub-ng-all.jar:?]
	at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1281) ~[datahub-ng-all.jar:?]
	at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:177) ~[datahub-ng-all.jar:?]
	at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:145) ~[datahub-ng-all.jar:?]
	at io.vertx.ext.web.impl.RoutingContextImpl.route(RoutingContextImpl.java:94) ~[datahub-ng-all.jar:?]
	at io.vertx.ext.web.impl.RouterImpl.handle(RouterImpl.java:69) ~[datahub-ng-all.jar:?]
	at io.vertx.ext.web.impl.RouterImpl.handle(RouterImpl.java:37) ~[datahub-ng-all.jar:?]
	at io.vertx.core.http.impl.Http1xServerRequestHandler.handle(Http1xServerRequestHandler.java:150) ~[datahub-ng-all.jar:?]
	at io.vertx.core.http.impl.Http1xServerRequestHandler.handle(Http1xServerRequestHandler.java:42) ~[datahub-ng-all.jar:?]
	at io.vertx.core.impl.ContextImpl.emit(ContextImpl.java:342) ~[datahub-ng-all.jar:?]
	at io.vertx.core.impl.ContextImpl.lambda$emit$8(ContextImpl.java:349) ~[datahub-ng-all.jar:?]
	at io.vertx.core.impl.WorkerExecutor$1.execute(WorkerExecutor.java:70) ~[datahub-ng-all.jar:?]
	at io.vertx.core.impl.WorkerTask.run(WorkerTask.java:56) ~[datahub-ng-all.jar:?]
	at io.vertx.core.impl.TaskQueue.run(TaskQueue.java:81) ~[datahub-ng-all.jar:?]
	at io.vertx.core.impl.ThreadPerTaskExecutorService.lambda$execute$0(ThreadPerTaskExecutorService.java:82) ~[datahub-ng-all.jar:?]
	at java.lang.VirtualThread.run(VirtualThread.java:335) [?:?]
Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.String.replaceAll(java.lang.String, java.lang.String)" because the return value of "java.lang.Package.getImplementationTitle()" is null
	at com.clickhouse.client.api.internal.HttpAPIClientHelper.buildDefaultUserAgent(HttpAPIClientHelper.java:691) ~[datahub-ng-all.jar:?]
	at com.clickhouse.client.api.internal.HttpAPIClientHelper.<init>(HttpAPIClientHelper.java:116) ~[datahub-ng-all.jar:?]
	at com.clickhouse.client.api.Client.<init>(Client.java:180) ~[datahub-ng-all.jar:?]
	at com.clickhouse.client.api.Client.<init>(Client.java:127) ~[datahub-ng-all.jar:?]
	at com.clickhouse.client.api.Client$Builder.build(Client.java:1068) ~[datahub-ng-all.jar:?]
	at com.shifudao.datahub.services.DbService.<init>(DbService.java:25) ~[datahub-ng-all.jar:?]
	at com.shifudao.datahub.queries.Query.<clinit>(Query.java:18) ~[datahub-ng-all.jar:?]
	... 22 more

The NPE is from

.append(this.httpClient.getClass().getPackage().getImplementationTitle().replaceAll(" ", "-"))

Error log

java.lang.ExceptionInInitializerError: null
	at java.lang.J9VMInternals.recordInitializationFailure(J9VMInternals.java:185) ~[?:?]
	at com.shifudao.datahub.RouteBuilder.lambda$initLegacyRoutes$8(RouteBuilder.java:83) ~[datahub-ng-all.jar:?]
	at com.shifudao.datahub.utils.RouteHelper.lambda$addQueryRoute$1(RouteHelper.java:89) ~[datahub-ng-all.jar:?]
	at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1281) ~[datahub-ng-all.jar:?]
	at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:177) ~[datahub-ng-all.jar:?]
	at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:145) ~[datahub-ng-all.jar:?]
	at io.vertx.ext.web.handler.impl.LoggerHandlerImpl.handle(LoggerHandlerImpl.java:189) ~[datahub-ng-all.jar:?]
	at io.vertx.ext.web.handler.impl.LoggerHandlerImpl.handle(LoggerHandlerImpl.java:48) ~[datahub-ng-all.jar:?]
	at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1281) ~[datahub-ng-all.jar:?]
	at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:177) ~[datahub-ng-all.jar:?]
	at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:145) ~[datahub-ng-all.jar:?]
	at io.vertx.ext.web.impl.RoutingContextImpl.route(RoutingContextImpl.java:94) ~[datahub-ng-all.jar:?]
	at io.vertx.ext.web.impl.RouterImpl.handle(RouterImpl.java:69) ~[datahub-ng-all.jar:?]
	at io.vertx.ext.web.impl.RouterImpl.handle(RouterImpl.java:37) ~[datahub-ng-all.jar:?]
	at io.vertx.core.http.impl.Http1xServerRequestHandler.handle(Http1xServerRequestHandler.java:150) ~[datahub-ng-all.jar:?]
	at io.vertx.core.http.impl.Http1xServerRequestHandler.handle(Http1xServerRequestHandler.java:42) ~[datahub-ng-all.jar:?]
	at io.vertx.core.impl.ContextImpl.emit(ContextImpl.java:342) ~[datahub-ng-all.jar:?]
	at io.vertx.core.impl.ContextImpl.lambda$emit$8(ContextImpl.java:349) ~[datahub-ng-all.jar:?]
	at io.vertx.core.impl.WorkerExecutor$1.execute(WorkerExecutor.java:70) ~[datahub-ng-all.jar:?]
	at io.vertx.core.impl.WorkerTask.run(WorkerTask.java:56) ~[datahub-ng-all.jar:?]
	at io.vertx.core.impl.TaskQueue.run(TaskQueue.java:81) ~[datahub-ng-all.jar:?]
	at io.vertx.core.impl.ThreadPerTaskExecutorService.lambda$execute$0(ThreadPerTaskExecutorService.java:82) ~[datahub-ng-all.jar:?]
	at java.lang.VirtualThread.run(VirtualThread.java:335) [?:?]
Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.String.replaceAll(java.lang.String, java.lang.String)" because the return value of "java.lang.Package.getImplementationTitle()" is null
	at com.clickhouse.client.api.internal.HttpAPIClientHelper.buildDefaultUserAgent(HttpAPIClientHelper.java:691) ~[datahub-ng-all.jar:?]
	at com.clickhouse.client.api.internal.HttpAPIClientHelper.<init>(HttpAPIClientHelper.java:116) ~[datahub-ng-all.jar:?]
	at com.clickhouse.client.api.Client.<init>(Client.java:180) ~[datahub-ng-all.jar:?]
	at com.clickhouse.client.api.Client.<init>(Client.java:127) ~[datahub-ng-all.jar:?]
	at com.clickhouse.client.api.Client$Builder.build(Client.java:1068) ~[datahub-ng-all.jar:?]
	at com.shifudao.datahub.services.DbService.<init>(DbService.java:25) ~[datahub-ng-all.jar:?]
	at com.shifudao.datahub.queries.Query.<clinit>(Query.java:18) ~[datahub-ng-all.jar:?]
	... 22 more

Configuration

Environment

  • Client version: 0.7.2
  • Language version: Java 21 LTS
  • OS: Archlinux
@abcfy2 abcfy2 added the bug label Jan 1, 2025
@abcfy2 abcfy2 changed the title java.lang.NullPointerException: Cannot invoke "java.lang.String.replaceAll(java.lang.String, java.lang.String)" because the return value of "java.lang.Package.getImplementationTitle()" is null v0.7.2 java.lang.NullPointerException: Cannot invoke "java.lang.String.replaceAll(java.lang.String, java.lang.String)" because the return value of "java.lang.Package.getImplementationTitle()" is null Jan 1, 2025
@abcfy2
Copy link
Contributor Author

abcfy2 commented Jan 1, 2025

I create a repo to reproduce this issue: https://github.com/abcfy2/clickhouse_java_issue_2061

This will cause when using gradle shadow plugin

@abcfy2
Copy link
Contributor Author

abcfy2 commented Jan 1, 2025

I find the reason. shadow plugin will bundle all the dependencies into one fat jar, so MANIFEST file will not contains Implementation-Title and Implementation-Version in fat jar.

As a quick and dirty sulotion, I have to add a FAKE Implementation-Title to my fat jar:

tasks.withType<ShadowJar> {
  archiveClassifier.set("all")
  archiveVersion.set("")
  manifest {
    attributes(
      mapOf(
        "Implementation-Title" to "ClickHouse Client API",
        "Implementation-Version" to "client-v2 $clickhouseClientV2Version",
        // other attributes
      )
    )
  }
  mergeServiceFiles()
}

@grant-guo
Copy link

grant-guo commented Jan 3, 2025

I got the same issue when using the assembly plugin in Maven. the solution looks like this:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>${maven.assembly.plugin.version}</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>

However I think the library should provide the setters or functions to allow the user to set both "Implementation-title" and "Implementation-version" manually.

@chernser
Copy link
Contributor

chernser commented Jan 6, 2025

Good day, @abcfy2 !
Thank you for reporting! We will look into it.

@chernser chernser self-assigned this Jan 6, 2025
@chernser
Copy link
Contributor

chernser commented Jan 6, 2025

Good day, @grant-guo!
Thank you for the hint!
Library provides setClientName() what is more DB specific.
We are using getImplementationTitle just to get version of http client that is used.
We've moved from this in the library itself and using version from a file. But for the client we do not have such possibility because dependency may be user defined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants