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

Resteasy Reactive - NPE when a filter throws exceptions #16620

Closed
Postremus opened this issue Apr 19, 2021 · 1 comment · Fixed by #16628
Closed

Resteasy Reactive - NPE when a filter throws exceptions #16620

Postremus opened this issue Apr 19, 2021 · 1 comment · Fixed by #16628
Labels
area/resteasy-reactive env/windows Impacts Windows machines kind/bug Something isn't working
Milestone

Comments

@Postremus
Copy link
Member

Describe the bug

My application throws an exception inside a ContainerRequestFilter. This exception is then catched an converted to a 400 status code inside an ExceptionMapper.

This setup works fine in Resteasy Classic - status code 400 ist returned, and no exception.
In Resteasy Reactive, I get the exception from below and an 500 status code.

When I remove the ExceptionMapper, the RuntimeException is logged as expected, but no NPE is thrown.

Expected behavior

No exceptions. Correct response that was set in the ExceptionMapper.

Actual behavior

__  ____  __  _____   ___  __ ____  ______ 
 --/ __ \/ / / / _ | / _ \/ //_/ / / / __/ 
 -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \   
--\___\_\____/_/ |_/_/|_/_/|_|\____/___/   
2021-04-19 11:30:50,075 INFO  [io.quarkus] (Quarkus Main Thread) rr-rest-metrics 1.0.0-SNAPSHOT on JVM (powered by Quarkus 1.13.2.Final) started in 3.215s. Listening on: http://localhost:8080
2021-04-19 11:30:50,077 INFO  [io.quarkus] (Quarkus Main Thread) Profile dev activated. Live Coding activated.
2021-04-19 11:30:50,077 INFO  [io.quarkus] (Quarkus Main Thread) Installed features: [cdi, mutiny, resteasy-reactive, smallrye-context-propagation, smallrye-metrics]
2021-04-19 11:31:11,471 ERROR [io.qua.ver.htt.run.QuarkusErrorHandler] (vert.x-eventloop-thread-2) HTTP Request to /hello-resteasy-reactive failed, error id: 6347e5ea-b5a9-4ec4-94f6-e06d7ec92ebd-1: java.lang.NullPointerException
        at io.quarkus.smallrye.metrics.runtime.QuarkusRestMetricsFilter.filter(QuarkusRestMetricsFilter.java:15)
        at io.quarkus.smallrye.metrics.runtime.QuarkusRestMetricsFilter$GeneratedServerResponseFilter$filter.filter(QuarkusRestMetricsFilter$GeneratedServerResponseFilter$filter.zig:68)
        at io.quarkus.smallrye.metrics.runtime.QuarkusRestMetricsFilter$GeneratedServerResponseFilter$filter_Subclass.filter$$superaccessor1(QuarkusRestMetricsFilter$GeneratedServerResponseFilter$filter_Subclass.zig:213)
        at io.quarkus.smallrye.metrics.runtime.QuarkusRestMetricsFilter$GeneratedServerResponseFilter$filter_Subclass$$function$$1.apply(QuarkusRestMetricsFilter$GeneratedServerResponseFilter$filter_Subclass$$function$$1.zig:41)
        at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
        at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.proceed(InvocationInterceptor.java:63)
        at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.monitor(InvocationInterceptor.java:49)
        at io.quarkus.arc.runtime.devconsole.InvocationInterceptor_Bean.intercept(InvocationInterceptor_Bean.zig:521)
        at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
        at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:41)
        at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:32)
        at io.quarkus.smallrye.metrics.runtime.QuarkusRestMetricsFilter$GeneratedServerResponseFilter$filter_Subclass.filter(QuarkusRestMetricsFilter$GeneratedServerResponseFilter$filter_Subclass.zig:168)
        at org.jboss.resteasy.reactive.server.handlers.ResourceResponseFilterHandler.handle(ResourceResponseFilterHandler.java:24)
        at org.jboss.resteasy.reactive.server.handlers.ResourceResponseFilterHandler.handle(ResourceResponseFilterHandler.java:9)
        at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:122)
        at org.jboss.resteasy.reactive.server.handlers.RestInitialHandler.beginProcessing(RestInitialHandler.java:47)
        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:1038)
        at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:137)
        at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:132)
        at io.quarkus.vertx.http.runtime.StaticResourcesRecorder.lambda$start$1(StaticResourcesRecorder.java:65)
        at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1038)
        at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:101)
        at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:132)
        at io.vertx.ext.web.handler.impl.StaticHandlerImpl.lambda$sendStatic$1(StaticHandlerImpl.java:206)
        at io.vertx.core.impl.ContextImpl.lambda$null$0(ContextImpl.java:327)
        at io.vertx.core.impl.ContextImpl.executeTask(ContextImpl.java:366)
        at io.vertx.core.impl.EventLoopContext.lambda$executeAsync$0(EventLoopContext.java:38)
        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
        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:834)

2021-04-19 11:31:11,480 ERROR [org.jbo.res.rea.com.cor.AbstractResteasyReactiveContext] (vert.x-eventloop-thread-2) Request failed: java.lang.NullPointerException
        at io.quarkus.smallrye.metrics.runtime.QuarkusRestMetricsFilter.filter(QuarkusRestMetricsFilter.java:15)
        at io.quarkus.smallrye.metrics.runtime.QuarkusRestMetricsFilter$GeneratedServerResponseFilter$filter.filter(QuarkusRestMetricsFilter$GeneratedServerResponseFilter$filter.zig:68)
        at io.quarkus.smallrye.metrics.runtime.QuarkusRestMetricsFilter$GeneratedServerResponseFilter$filter_Subclass.filter$$superaccessor1(QuarkusRestMetricsFilter$GeneratedServerResponseFilter$filter_Subclass.zig:213)
        at io.quarkus.smallrye.metrics.runtime.QuarkusRestMetricsFilter$GeneratedServerResponseFilter$filter_Subclass$$function$$1.apply(QuarkusRestMetricsFilter$GeneratedServerResponseFilter$filter_Subclass$$function$$1.zig:41)
        at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
        at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.proceed(InvocationInterceptor.java:63)
        at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.monitor(InvocationInterceptor.java:49)
        at io.quarkus.arc.runtime.devconsole.InvocationInterceptor_Bean.intercept(InvocationInterceptor_Bean.zig:521)
        at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
        at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:41)
        at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:32)
        at io.quarkus.smallrye.metrics.runtime.QuarkusRestMetricsFilter$GeneratedServerResponseFilter$filter_Subclass.filter(QuarkusRestMetricsFilter$GeneratedServerResponseFilter$filter_Subclass.zig:168)
        at org.jboss.resteasy.reactive.server.handlers.ResourceResponseFilterHandler.handle(ResourceResponseFilterHandler.java:24)
        at org.jboss.resteasy.reactive.server.handlers.ResourceResponseFilterHandler.handle(ResourceResponseFilterHandler.java:9)
        at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:122)
        at org.jboss.resteasy.reactive.server.handlers.RestInitialHandler.beginProcessing(RestInitialHandler.java:47)
        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:1038)
        at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:137)
        at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:132)
        at io.quarkus.vertx.http.runtime.StaticResourcesRecorder.lambda$start$1(StaticResourcesRecorder.java:65)
        at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1038)
        at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:101)
        at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:132)
        at io.vertx.ext.web.handler.impl.StaticHandlerImpl.lambda$sendStatic$1(StaticHandlerImpl.java:206)
        at io.vertx.core.impl.ContextImpl.lambda$null$0(ContextImpl.java:327)
        at io.vertx.core.impl.ContextImpl.executeTask(ContextImpl.java:366)
        at io.vertx.core.impl.EventLoopContext.lambda$executeAsync$0(EventLoopContext.java:38)
        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
        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:834)

To Reproduce

Link to a small reproducer (preferably a Maven project if the issue is not Gradle-specific).

Or attach an archive containing the reproducer to the issue.

Steps to reproduce the behavior:

  1. Download the reproducer: rr-rest-metrics.zip
  2. mvn quarkus:dev
  3. Visit http://localhost:8080/hello-resteasy-reactive
  4. The exception happens

Configuration

quarkus.smallrye-metrics.jaxrs.enabled=true

Environment (please complete the following information):

Output of uname -a or ver

MSYS_NT-10.0 NANB7NLNVP2 2.10.0(0.325/5/3) 2018-06-13 23:34 x86_64 Msys

Quarkus version or git rev

1.13.2.Final

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

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: C:\eclipse\tools\apache-maven\bin..
Java version: 11.0.7, vendor: Azul Systems, Inc., runtime: C:\eclipse\tools\zulu11.39.15-ca-jdk11.0.7-win_x64
Default locale: de_DE, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

@Postremus Postremus added the kind/bug Something isn't working label Apr 19, 2021
@quarkus-bot
Copy link

quarkus-bot bot commented Apr 19, 2021

/cc @FroMage, @geoand, @stuartwdouglas

@quarkus-bot quarkus-bot bot added area/resteasy-reactive env/windows Impacts Windows machines labels Apr 19, 2021
geoand added a commit to geoand/quarkus that referenced this issue Apr 19, 2021
The NPE could happen if an exception was thrown
in a ContainerRequestFilter

Fixes: quarkusio#16620
geoand added a commit to geoand/quarkus that referenced this issue Apr 19, 2021
The NPE could happen if an exception was thrown
in a ContainerRequestFilter

Fixes: quarkusio#16620
geoand added a commit that referenced this issue Apr 19, 2021
Avoid potential NPE in Metrics filter
@quarkus-bot quarkus-bot bot added this to the 2.0 - main milestone Apr 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/resteasy-reactive env/windows Impacts Windows machines kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant