Skip to content

Commit ddc97b3

Browse files
test to reproduce the issue 3787
1 parent a866a9f commit ddc97b3

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package io.jooby.i3787;
2+
3+
import io.jooby.Jooby;
4+
import io.jooby.problem.HttpProblem;
5+
6+
class Application extends Jooby {
7+
{
8+
get("/throw", ctx -> {
9+
throw new CustomException();
10+
});
11+
12+
error(CustomException.class, (ctx, throwable, statusCode) -> {
13+
var problem = HttpProblem.badRequest("A Client Error — Obviously");
14+
ctx.getRouter().getErrorHandler().apply(ctx, problem, statusCode);
15+
});
16+
}
17+
18+
public static void main(String[] args) {
19+
runApp(args, Application::new);
20+
}
21+
22+
static class CustomException extends RuntimeException {}
23+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package io.jooby.i3787;
2+
3+
import io.jooby.StatusCode;
4+
import io.jooby.test.MockContext;
5+
import io.jooby.test.MockRouter;
6+
import org.junit.jupiter.api.Test;
7+
8+
import static org.junit.jupiter.api.Assertions.assertEquals;
9+
10+
public class Issue3787 {
11+
12+
private final MockRouter router = new MockRouter(new Application()).setFullExecution(true);
13+
14+
@Test
15+
void test() {
16+
var ctx = new MockContext();
17+
router.tryError(new Application.CustomException(), ctx); // throws java.lang.NullPointerException
18+
assertEquals(StatusCode.BAD_REQUEST, ctx.getResponseCode());
19+
}
20+
}

0 commit comments

Comments
 (0)