NPE when RESTEasy-Reactive and Picocli both in deps

See original GitHub issue

Describe the bug

If you have both RESTEasy-Reactive and Picocli in your dependencies, RESTEasy endpoints throws an NPE exception:

  • NullPointerException: Cannot invoke "io.quarkus.arc.ArcContainer.getActiveContext(java.lang.Class)" because the return value of "io.quarkus.arc.Arc.container()" is null

To reproduce, just create a new application at https://code.quarkus.io that has both RESTEasy-Reactive + Picocli, start it, and try to hit the /hello endpoint:

image

As an aside to the actual bug report – I am really curious what is happening here? These two things seem wildly unrelated, how is it that having Picocli in your deps could cause an error with RESTEasy Reactive 🤔

(It took me 30 minutes of trying different combinations of dependencies to figure out what the minimal reproduction/cause was)

java.lang.NullPointerException: Cannot invoke "io.quarkus.arc.ArcContainer.getActiveContext(java.lang.Class)" because the return value of "io.quarkus.arc.Arc.container()" is null
	at io.quarkus.arc.runtime.devconsole.EventsMonitor_Observer_notify_513ab14b479908baeab956aa73f8a6221325887f.notify(Unknown Source)
	at io.quarkus.arc.impl.EventImpl$Notifier.notifyObservers(EventImpl.java:320)
	at io.quarkus.arc.impl.EventImpl$Notifier.notify(EventImpl.java:308)
	at io.quarkus.arc.impl.EventImpl$Notifier.notify(EventImpl.java:238)
	at io.quarkus.arc.impl.RequestContext.fireIfNotEmpty(RequestContext.java:209)
	at io.quarkus.arc.impl.RequestContext.activate(RequestContext.java:123)
	at io.quarkus.arc.ManagedContext.activate(ManagedContext.java:15)
	at io.quarkus.resteasy.reactive.common.runtime.ArcThreadSetupAction.activateInitial(ArcThreadSetupAction.java:18)
	at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.requireCDIRequestScope(AbstractResteasyReactiveContext.java:236)
	at org.jboss.resteasy.reactive.server.handlers.InstanceHandler.handle(InstanceHandler.java:25)
	at org.jboss.resteasy.reactive.server.handlers.InstanceHandler.handle(InstanceHandler.java:7)
	at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:141)
	at org.jboss.resteasy.reactive.server.handlers.RestInitialHandler.beginProcessing(RestInitialHandler.java:49)
	at org.jboss.resteasy.reactive.server.vertx.ResteasyReactiveVertxHandler.handle(ResteasyReactiveVertxHandler.java:17)
	at org.jboss.resteasy.reactive.server.vertx.ResteasyReactiveVertxHandler.handle(ResteasyReactiveVertxHandler.java:7)
	at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1212)
	at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:163)
	at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:141)
	at io.quarkus.vertx.http.runtime.StaticResourcesRecorder$2.handle(StaticResourcesRecorder.java:67)
	at io.quarkus.vertx.http.runtime.StaticResourcesRecorder$2.handle(StaticResourcesRecorder.java:55)
	at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1212)
	at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:126)
	at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:141)
	at io.vertx.ext.web.handler.impl.StaticHandlerImpl.lambda$sendStatic$1(StaticHandlerImpl.java:274)
	at io.vertx.core.impl.future.FutureImpl$3.onSuccess(FutureImpl.java:141)
	at io.vertx.core.impl.future.FutureBase.lambda$emitSuccess$0(FutureBase.java:54)
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:469)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:503)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:833)

image

Expected behavior

No response

Actual behavior

No response

How to Reproduce?

No response

Output of uname -a or ver

Microsoft Windows [Version 10.0.22000.376]

Output of java -version

OpenJDK Runtime Environment GraalVM CE 22.0.0-dev (build 17.0.2+5-jvmci-22.0-b02)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.7.3-Final

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

Gradle 7.3.3

Additional information

Have a great day 🙂

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:14 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
geoandcommented, Mar 11, 2022

I’m gonna close this as it’s not a Quarkus issue.

Thanks everyone for your input

1reaction
mkoubacommented, Mar 10, 2022

What do you do if your quarkus app is a web application that also has a CLI?

I think that this is not a common use case 😉. In this case, just use Quarkus.waitForExit() as mentioned above.

What is confusing is that the webserver still works – IE if you go to http://localhost:8080 it serves the index.html page. It’s only the RESTEasy endpoints that throw an NPE.

That’s probably because of how the dev mode works. In prod mode the app is just shut down. BTW you can press space to run your command again.

The code for the reproduction is just this:

Just do:

@Command(name = "greeting", mixinStandardHelpOptions = true)
public class GreetingCommand implements Runnable {

    @Parameters(paramLabel = "<name>", defaultValue = "picocli", description = "Your name.")
    String name;

    @Override
    public void run() {
        System.out.printf("Hello %s, go go commando!\n", name);
        Quarkus.waitForExit(); // <== this should solve your problem
    }

Read more comments on GitHub >

github_iconTop Results From Across the Web

Errors after switching to quarkus-resteasy-reactive
I'm using Quarkus 2.8.2. So far I have been using the quarkus-resteasy dependencies in my project. The release notes for 2.8 tell me...
Read more >
chore(deps): update dependency io.quarkus:quarkus ... - GitLab
An error occurred while retrieving approval data for this merge request. chore(deps): update dependency io.quarkus:quarkus ...
Read more >
Quarkus changelog - Awesome Java - LibHunt
Major changes. Complete changelog. ⚡️ #13739 - Updates XStream due to published CVE; #13727 - Fix dev mode when the same file is...
Read more >
Home of Quarkus Cheat-Sheet - GitHub Pages
A RESTEasy Reactive-based REST Client extension. You only need to replace the quarkus-rest-client to quarkus-rest-client-reactive . Multipart.
Read more >
quarkusio/quarkus 1.10.0.CR1 on GitHub - NewReleases.io
#13194 - Update SmallRye Reactive Messaging to version 2.5.0 ... #13096 - Make sure Maven commands use the effective project deps, props and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found