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: ServerExceptionMapper does not process a thrown Exception (Kotlin only) #20357

Closed
mschorsch opened this issue Sep 23, 2021 · 4 comments · Fixed by #20364
Closed
Labels
Milestone

Comments

@mschorsch
Copy link
Contributor

Describe the bug

If a (Kotlin-)Rest-Endpoint throws an java.lang.Exception then the Exception does not get processed by a custom ServerExceptionMapper. RuntimeException works as excepted.

org.acme.MyException
	at org.acme.ExceptionTestResource.throwException1Method(ExceptionTestResource.kt:33)
	at org.acme.ExceptionTestResource_Subclass.throwException1Method$$superforward1(ExceptionTestResource_Subclass.zig:113)
	at org.acme.ExceptionTestResource_Subclass$$function$$1.apply(ExceptionTestResource_Subclass$$function$$1.zig:24)
	at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
	at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.proceed(InvocationInterceptor.java:62)
	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 org.acme.ExceptionTestResource_Subclass.throwException1Method(ExceptionTestResource_Subclass.zig:183)
	at org.acme.ExceptionTestResource_ClientProxy.throwException1Method(ExceptionTestResource_ClientProxy.zig:185)
	at org.acme.ExceptionTestResource$quarkusrestinvoker$throwException1Method_4a04d16e4f5785de322606c51c7fc425b79facd0.invoke(ExceptionTestResource$quarkusrestinvoker$throwException1Method_4a04d16e4f5785de322606c51c7fc425b79facd0.zig:33)
	at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:29)
	at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:7)
	at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:141)
	at io.quarkus.vertx.core.runtime.VertxCoreRecorder$13.runWith(VertxCoreRecorder.java:543)
	at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
	at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
	at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:829)
Resulted in: io.quarkus.arc.ArcUndeclaredThrowableException: Error invoking subclass method
	at org.acme.ExceptionTestResource_Subclass.throwException1Method(ExceptionTestResource_Subclass.zig:205)
	... 12 more

Expected behavior

No response

Actual behavior

No response

How to Reproduce?

  1. https://code.quarkus.io/?e=resteasy-reactive-jackson&e=kotlin&extension-search=kotlin
  2. Add the following code
package org.acme

import org.jboss.resteasy.reactive.server.ServerExceptionMapper
import javax.enterprise.context.ApplicationScoped
import javax.ws.rs.GET
import javax.ws.rs.Path
import javax.ws.rs.core.Response

open class SuperException : Exception() // Works if SuperException extends RuntimeException instead of Exception
class MyException : SuperException()

class ExceptionMappers {

    @ServerExceptionMapper
    fun superExceptionHandler(ex: SuperException): Response {
        println("SuperException processed")
        return Response.serverError().build()
    }
}

@ApplicationScoped
@Path("/ex")
class ExceptionTestResource {

    /**
     * Exception is not processed by the ServerExceptionMapper.
     */
    @GET
    @Path("/throw1")
    fun throwException1Method(): String {
        throw MyException()
    }

    /**
     * Exception is processed by the ServerExceptionMapper.
     */
    @GET
    @Path("/throw2")
    @Throws(MyException::class) // see here
    fun throwExceptionMethod(): String {
        throw MyException()
    }
}

Output of uname -a or ver

No response

Output of java -version

Java 11

GraalVM version (if different from Java)

No response

Quarkus version or git rev

Quarkus 2.2.3.Final

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

Maven 3.8.1

Additional information

No response

@mschorsch mschorsch added the kind/bug Something isn't working label Sep 23, 2021
@quarkus-bot
Copy link

quarkus-bot bot commented Sep 23, 2021

@geoand
Copy link
Contributor

geoand commented Sep 23, 2021

I can't reproduce this problem with the snippets included in the description.

Please attach a project that exhibits this behavior (ideally with failing tests).

@geoand geoand added the triage/needs-reproducer We are waiting for a reproducer. label Sep 23, 2021
@mschorsch
Copy link
Contributor Author

I've made a reproducer (see attached), including some tests.

Please note that unfortunately the tests do not fail. The problem can only be reproduced in dev mode.

Run ./mvnw quarkus:dev call http://localhost:8080/ex/throw1 then you get the following exception (console log):

2021-09-23 16:01:39,381 ERROR [io.qua.ver.htt.run.QuarkusErrorHandler] (executor-thread-0) HTTP Request to /ex/throw1 failed, error id: 4c3eb23b-e454-43fb-9c2c-96d44e308b1f-1: io.quarkus.arc.ArcUndeclaredThrowableException: Error invoking subclass method
	at org.acme.ExceptionTestResource_Subclass.throwException1Method(ExceptionTestResource_Subclass.zig:205)
	at org.acme.ExceptionTestResource_ClientProxy.throwException1Method(ExceptionTestResource_ClientProxy.zig:185)
	at org.acme.ExceptionTestResource$quarkusrestinvoker$throwException1Method_4a04d16e4f5785de322606c51c7fc425b79facd0.invoke(ExceptionTestResource$quarkusrestinvoker$throwException1Method_4a04d16e4f5785de322606c51c7fc425b79facd0.zig:33)
	at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:29)
	at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:7)
	at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:141)
	at io.quarkus.vertx.core.runtime.VertxCoreRecorder$13.runWith(VertxCoreRecorder.java:543)
	at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
	at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
	at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: org.acme.MyException
	at org.acme.ExceptionTestResource.throwException1Method(ExceptionTestResource.kt:30)
	at org.acme.ExceptionTestResource_Subclass.throwException1Method$$superforward1(ExceptionTestResource_Subclass.zig:113)
	at org.acme.ExceptionTestResource_Subclass$$function$$1.apply(ExceptionTestResource_Subclass$$function$$1.zig:24)
	at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
	at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.proceed(InvocationInterceptor.java:62)
	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 org.acme.ExceptionTestResource_Subclass.throwException1Method(ExceptionTestResource_Subclass.zig:183)
	... 12 more

2021-09-23 16:01:39,390 ERROR [org.jbo.res.rea.com.cor.AbstractResteasyReactiveContext] (executor-thread-0) Request failed: io.quarkus.arc.ArcUndeclaredThrowableException: Error invoking subclass method
	at org.acme.ExceptionTestResource_Subclass.throwException1Method(ExceptionTestResource_Subclass.zig:205)
	at org.acme.ExceptionTestResource_ClientProxy.throwException1Method(ExceptionTestResource_ClientProxy.zig:185)
	at org.acme.ExceptionTestResource$quarkusrestinvoker$throwException1Method_4a04d16e4f5785de322606c51c7fc425b79facd0.invoke(ExceptionTestResource$quarkusrestinvoker$throwException1Method_4a04d16e4f5785de322606c51c7fc425b79facd0.zig:33)
	at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:29)
	at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:7)
	at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:141)
	at io.quarkus.vertx.core.runtime.VertxCoreRecorder$13.runWith(VertxCoreRecorder.java:543)
	at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
	at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
	at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: org.acme.MyException
	at org.acme.ExceptionTestResource.throwException1Method(ExceptionTestResource.kt:30)
	at org.acme.ExceptionTestResource_Subclass.throwException1Method$$superforward1(ExceptionTestResource_Subclass.zig:113)
	at org.acme.ExceptionTestResource_Subclass$$function$$1.apply(ExceptionTestResource_Subclass$$function$$1.zig:24)
	at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
	at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.proceed(InvocationInterceptor.java:62)
	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 org.acme.ExceptionTestResource_Subclass.throwException1Method(ExceptionTestResource_Subclass.zig:183)
	... 12 more

reproducer20357.zip

@geoand
Copy link
Contributor

geoand commented Sep 23, 2021

#20364 takes care of the issue

geoand added a commit that referenced this issue Sep 24, 2021
Add the exception unwrapping capabilities to RESTEasy Reactive
@quarkus-bot quarkus-bot bot added this to the 2.4 - main milestone Sep 24, 2021
@geoand geoand modified the milestones: 2.4 - main, 2.3.0.Final Sep 28, 2021
geoand added a commit to geoand/quarkus that referenced this issue Sep 28, 2021
@famod famod removed the triage/needs-reproducer We are waiting for a reproducer. label Oct 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants