quarkus-logging-json not working with native images

Created on 25 Apr 2020  路  3Comments  路  Source: quarkusio/quarkus

Describe the bug
When adding quarkus-logging-json dependency, building a native image is still working, but when starting the native image I get this exception and the application exits:

$ ./target/code-with-quarkus-1.0.0-SNAPSHOT-runner                                           
Exception in thread "main" java.lang.RuntimeException: Failed to start quarkus
        at io.quarkus.runner.ApplicationImpl.doStart(ApplicationImpl.zig:240)
        at io.quarkus.runtime.Application.start(Application.java:90)
        at io.quarkus.runtime.Application.run(Application.java:228)
        at io.quarkus.runner.GeneratedMain.main(GeneratedMain.zig:41)
Caused by: javax.json.JsonException: Provider org.glassfish.json.JsonProviderImpl could not be instantiated: java.lang.InstantiationException: Type `org.glassfish.json.JsonProviderImpl` can not be instantiated reflectively as it does not have a no-parameter constructor or the no-parameter constructor has not been added explicitly to the native image.
        at javax.json.spi.JsonProvider.provider(JsonProvider.java:78)
        at javax.json.Json.createGeneratorFactory(Json.java:154)
        at org.jboss.logmanager.formatters.JsonFormatter.<init>(JsonFormatter.java:60)
        at io.quarkus.logging.json.runtime.LoggingJsonRecorder.initializeJsonLogging(LoggingJsonRecorder.java:17)
        at io.quarkus.deployment.steps.LoggingJsonSteps$setUpFormatter8.deploy_0(LoggingJsonSteps$setUpFormatter8.zig:57)
        at io.quarkus.deployment.steps.LoggingJsonSteps$setUpFormatter8.deploy(LoggingJsonSteps$setUpFormatter8.zig:82)
        at io.quarkus.runner.ApplicationImpl.doStart(ApplicationImpl.zig:82)
        ... 3 more
Caused by: java.lang.InstantiationException: Type `org.glassfish.json.JsonProviderImpl` can not be instantiated reflectively as it does not have a no-parameter constructor or the no-parameter constructor has not been added explicitly to the native image.
        at java.lang.Class.newInstance(DynamicHub.java:796)
        at javax.json.spi.JsonProvider.provider(JsonProvider.java:73)
        ... 9 more

Expected behavior
native application starts without errors.

To Reproduce
Steps to reproduce the behavior:

  1. Create a project and add quarkus-logging-json e.g. this zip / configuration
  2. build the application with ./mvnw clean verify -Pnative -Dquarkus.native.container-build=true
  3. The NativeExampleResourceIT will fail with the above Exception.
  4. when starting the app with ./target/code-with-quarkus-1.0.0-SNAPSHOT-runner you will get the same Exception

Environment:

  • Output of uname -a or ver: Linux xxx 5.3.0-46-generic #38-Ubuntu SMP Fri Mar 27 17:37:05 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
  • Output of java -version: openjdk version "11.0.7" 2020-04-14
    OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-2ubuntu219.10)
    OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-2ubuntu219.10, mixed mode, sharing)
  • GraalVM version (if different from Java): no local installation, used the dockerized approach
  • Quarkus version or git rev: 1.3.2.Final
  • Build tool (ie. output of mvnw --version or gradlew --version): Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
arelogging kinbug

All 3 comments

@xtermi2 thanks for reporting. I'll have a look, might be an easy fix.

Thx. I can confirm that adding

<dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-jsonp-deployment</artifactId>
      <version>${quarkus.platform.version}</version>
</dependency>

will fix the issue - as a workaround until the dependency is delivered transitively.

Great thanks for checking.

You can also temporarily fix the issue by adding:

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

as you don't need to add the deployment module in your app (unless otherwise it is compile only scope).

Was this page helpful?
0 / 5 - 0 ratings