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

Remove stacktraces from exceptions thrown deliberately in RESTEasy Reactive tests #19579

Merged
merged 1 commit into from
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.quarkus.resteasy.reactive.server.test;

public final class ExceptionUtil {

private static final StackTraceElement[] EMPTY_STACK_TRACE = new StackTraceElement[0];

private ExceptionUtil() {
}

public static <T extends Throwable> T removeStackTrace(T t) {
t.setStackTrace(EMPTY_STACK_TRACE);
return t;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.resteasy.reactive.server.test.ExceptionUtil;
import io.quarkus.test.QuarkusUnitTest;
import io.restassured.RestAssured;

Expand All @@ -22,7 +23,7 @@ public JavaArchive get() {
.addClasses(FirstResource.class, SecondResource.class,
MyException.class, MyOtherException.class, UniException.class, ExtendsUniException.class,
MyOtherExceptionMapper.class, UniExceptionMapper.class,
SomeBean.class);
SomeBean.class, ExceptionUtil.class);
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.quarkus.resteasy.reactive.server.test.customexceptions;

import static io.quarkus.resteasy.reactive.server.test.ExceptionUtil.removeStackTrace;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
Expand All @@ -23,17 +25,17 @@ public class FirstResource {
@Produces("text/plain")
public String throwsVariousExceptions(@RestQuery String name) {
if (name.startsWith("IllegalArgument")) {
throw new IllegalArgumentException();
throw removeStackTrace(new IllegalArgumentException());
} else if (name.startsWith("IllegalState")) {
throw new IllegalStateException("IllegalState");
throw removeStackTrace(new IllegalStateException("IllegalState"));
} else if (name.startsWith("MyOther")) {
throw new MyOtherException();
throw removeStackTrace(new MyOtherException());
} else if (name.startsWith("My")) {
throw new MyException();
throw removeStackTrace(new MyException());
} else if (name.startsWith("Uni")) {
throw new UniException();
throw removeStackTrace(new UniException());
}
throw new RuntimeException();
throw removeStackTrace(new RuntimeException());
}

@GET
Expand All @@ -52,7 +54,7 @@ public Uni<String> uni(@RestQuery String name) {
} else if (name.startsWith("Uni")) {
e = new UniException();
}
return Uni.createFrom().failure(e);
return Uni.createFrom().failure(removeStackTrace(e));
}

@ServerExceptionMapper({ IllegalStateException.class, IllegalArgumentException.class })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.quarkus.resteasy.reactive.server.test.customexceptions;

import static io.quarkus.resteasy.reactive.server.test.ExceptionUtil.*;

import java.util.function.Supplier;

import javax.ws.rs.GET;
Expand Down Expand Up @@ -40,7 +42,7 @@ public static class Resource {
@Path("throwable")
@Produces("text/plain")
public String throwsThrowable() throws Throwable {
throw new Throwable();
throw removeStackTrace(new Throwable());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.quarkus.resteasy.reactive.server.test.customexceptions;

import static io.quarkus.resteasy.reactive.server.test.ExceptionUtil.removeStackTrace;

import java.util.function.Supplier;

import javax.ws.rs.GET;
Expand Down Expand Up @@ -49,7 +51,7 @@ public Response handleThrowable(Throwable t) {
@Path("throwable")
@Produces("text/plain")
public String throwsThrowable() throws Throwable {
throw new Throwable();
throw removeStackTrace(new Throwable());
}
}

Expand All @@ -60,7 +62,7 @@ public static class DoesNotHaveCustomThrowableHandlerResource {
@Path("throwable")
@Produces("text/plain")
public String throwsThrowable() throws Throwable {
throw new Throwable();
throw removeStackTrace(new Throwable());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.quarkus.resteasy.reactive.server.test.customexceptions;

import static io.quarkus.resteasy.reactive.server.test.ExceptionUtil.removeStackTrace;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
Expand All @@ -10,27 +12,27 @@ public class SecondResource {
@GET
@Produces("text/plain")
public String throwsMyException() {
throw new MyException();
throw removeStackTrace(new MyException());
}

@GET
@Path("other")
@Produces("text/plain")
public String throwsMyOtherException() {
throw new MyOtherException();
throw removeStackTrace(new MyOtherException());
}

@GET
@Path("uni")
@Produces("text/plain")
public String throwsUniException() {
throw new UniException();
throw removeStackTrace(new UniException());
}

@GET
@Path("extendsUni")
@Produces("text/plain")
public String throwsExtendsUniException() {
throw new ExtendsUniException();
throw removeStackTrace(new ExtendsUniException());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import org.jboss.resteasy.reactive.server.spi.ResteasyReactiveContainerRequestFilter;
import org.jboss.resteasy.reactive.server.spi.ServerRequestContext;

import io.quarkus.resteasy.reactive.server.test.ExceptionUtil;

public abstract class AsyncRequestFilter implements ResteasyReactiveContainerRequestFilter {

private final String name;
Expand Down Expand Up @@ -58,13 +60,13 @@ public void filter(ResteasyReactiveContainerRequestContext ctx) {
}
resteasyReactiveCallbackContext.registerCompletionCallback((t) -> {
if (callbackException != null)
throw new RuntimeException("Callback called twice");
throw ExceptionUtil.removeStackTrace(new RuntimeException("Callback called twice"));
callbackException = Objects.toString(t);
});
if ("true".equals(ctx.getHeaderString("UseExceptionMapper")))
ctx.resume(new AsyncFilterException("ouch"));
ctx.resume(ExceptionUtil.removeStackTrace(new AsyncFilterException("ouch")));
else
ctx.resume(new Throwable("ouch"));
ctx.resume(ExceptionUtil.removeStackTrace(new Throwable("ouch")));
});
}
LOG.debug("Filter request for " + name + " with action: " + action + " done");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.resteasy.reactive.server.test.ExceptionUtil;
import io.quarkus.resteasy.reactive.server.test.simple.PortProviderUtil;
import io.quarkus.test.QuarkusUnitTest;

Expand All @@ -36,7 +37,7 @@ public JavaArchive get() {
AsyncResponseFilter.class,
AsyncResponseFilter1.class, AsyncResponseFilter2.class, AsyncResponseFilter3.class,
AsyncFilterException.class, AsyncFilterExceptionMapper.class,
AsyncRequestFilterResource.class);
AsyncRequestFilterResource.class, ExceptionUtil.class);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.jboss.resteasy.reactive.server.spi.ResteasyReactiveContainerResponseFilter;
import org.jboss.resteasy.reactive.server.spi.ServerRequestContext;

import io.quarkus.resteasy.reactive.server.test.ExceptionUtil;

public abstract class AsyncResponseFilter implements ResteasyReactiveContainerResponseFilter {

private final String name;
Expand Down Expand Up @@ -70,7 +72,7 @@ public void filter(ResteasyReactiveContainerRequestContext requestContext, Conta
ctx.setEntity(name);
requestContext.resume();
} else if ("sync-throw".equals(action)) {
throw new AsyncFilterException("ouch");
throw ExceptionUtil.removeStackTrace(new AsyncFilterException("ouch"));
} else if ("async-throw-late".equals(action)) {
requestContext.suspend();
ServerRequestContext resteasyReactiveCallbackContext = requestContext.getServerRequestContext();
Expand All @@ -84,13 +86,13 @@ public void filter(ResteasyReactiveContainerRequestContext requestContext, Conta
ctx.setEntity(name);
resteasyReactiveCallbackContext.registerCompletionCallback((t) -> {
if (callbackException != null)
throw new RuntimeException("Callback called twice");
throw ExceptionUtil.removeStackTrace(new RuntimeException("Callback called twice"));
callbackException = Objects.toString(t);
});
if ("true".equals(requestContext.getHeaderString("UseExceptionMapper")))
requestContext.resume(new AsyncFilterException("ouch"));
requestContext.resume(ExceptionUtil.removeStackTrace(new AsyncFilterException("ouch")));
else
requestContext.resume(new Throwable("ouch"));
requestContext.resume(ExceptionUtil.removeStackTrace(new Throwable("ouch")));
});
}
LOG.debug("Filter response for " + name + " with action: " + action + " done");
Expand Down