quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.64k stars 2.65k forks source link

FrameworkRouter not initialized when access-log is enabled with custom non-application-root-path #40420

Open thomasdarimont opened 5 months ago

thomasdarimont commented 5 months ago

Describe the bug

When using a custom http.root-path together with custom http.non-application-root-path and http.access-log.enabled=true starting a quarkus app fails with a java.lang.NullPointerException.

Example configuration which triggers the problem:

quarkus.http.root-path=/auth
quarkus.http.non-application-root-path=/q
# Setting the following to true triggers the problem
quarkus.http.access-log.enabled=true

Note that this also happens with ealier quarkus versions. So if this is fixed it would be great to backport this :) (Quarkus 3.8.x maybe? :))

Expected behavior

The app should not fail to start

Actual behavior

The following exception is thrown:

$ java -jar target/quarkus-app/quarkus-run.jar 
__  ____  __  _____   ___  __ ____  ______ 
 --/ __ \/ / / / _ | / _ \/ //_/ / / / __/ 
 -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \   
--\___\_\____/_/ |_/_/|_/_/|_|\____/___/   
2024-05-02 22:42:12,818 ERROR [io.qua.run.Application] (main) Failed to start application (with profile [prod]): java.lang.RuntimeException: Failed to start quarkus
    at io.quarkus.runner.ApplicationImpl.doStart(Unknown Source)
    at io.quarkus.runtime.Application.start(Application.java:101)
    at io.quarkus.runtime.ApplicationLifecycleManager.run(ApplicationLifecycleManager.java:111)
    at io.quarkus.runtime.Quarkus.run(Quarkus.java:71)
    at io.quarkus.runtime.Quarkus.run(Quarkus.java:44)
    at io.quarkus.runtime.Quarkus.run(Quarkus.java:124)
    at io.quarkus.runner.GeneratedMain.main(Unknown Source)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at io.quarkus.bootstrap.runner.QuarkusEntryPoint.doRun(QuarkusEntryPoint.java:62)
    at io.quarkus.bootstrap.runner.QuarkusEntryPoint.main(QuarkusEntryPoint.java:33)
Caused by: java.lang.NullPointerException: Cannot invoke "io.quarkus.runtime.RuntimeValue.getValue()" because "frameworkRouter" is null
    at io.quarkus.vertx.http.runtime.VertxHttpRecorder.finalizeRouter(VertxHttpRecorder.java:499)
    at io.quarkus.deployment.steps.VertxHttpProcessor$finalizeRouter2040953008.deploy_0(Unknown Source)
    at io.quarkus.deployment.steps.VertxHttpProcessor$finalizeRouter2040953008.deploy(Unknown Source)
    ... 11 more

How to Reproduce?

See example in this gist: https://gist.github.com/thomasdarimont/458dd8ce85dd347ddf3c690d61944559

Output of uname -a or ver

Linux neumann 6.8.7-100.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Apr 17 19:34:28 UTC 2024 x86_64 GNU/Linux

Output of java -version

openjdk version "22.0.1" 2024-04-16 OpenJDK Runtime Environment Temurin-22.0.1+8 (build 22.0.1+8) OpenJDK 64-Bit Server VM Temurin-22.0.1+8 (build 22.0.1+8, mixed mode, sharing)

Quarkus version or git rev

3.10.0

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.9.6

Additional information

This is also reproducible with Quarkus 3.8.3 currently used by Keycloak (24.0.3).

The problem is triggered here: https://github.com/quarkusio/quarkus/blob/3.8.3/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java#L471

but I think the cause for this is here: https://github.com/quarkusio/quarkus/blob/3.8.3/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/VertxHttpProcessor.java#L272.

The problem is that the frameworkRouter is not initialized, since the check && route.isRouterFramework() returns false for the non-application-root-path (the router type errornously set to APPLICATION instead of FRAMEWORK).

If I set the proper Router type with a debugger in io.quarkus.vertx.http.deployment.RouteBuildItem#isRouterFramework during augmentation then the application can start fine.

AndreasFagschlunger commented 5 months ago

I stumbled about this too, but in my case it was a missing dependency to quarkus-opentelemetry:

        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-opentelemetry</artifactId>
        </dependency>

Another library enabled access logs and opentelemetry, but I didn't had the dependency in my pom.xml and had the same error. But only in run mode, dev mode had no issues.

geoand commented 4 months ago

@thomasdarimont thanks for the detailed report!

As you have already analyzed the code, would you like to contribute the fix you have in mind?