Skip to content

Commit 639a0a7

Browse files
fix NPE
1 parent ddc97b3 commit 639a0a7

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

modules/jooby-test/src/main/java/io/jooby/test/MockRouter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,8 @@ public void tryError(Throwable cause, Consumer<MockResponse> consumer) {
472472
*/
473473
public void tryError(Throwable cause, Context ctx) {
474474
var app = supplier.get();
475+
MockContext findContext = ctx instanceof MockContext ? (MockContext) ctx : newContext();
476+
findContext.setRouter(app);
475477
var handler = app.getErrorHandler();
476478
handler.apply(ctx, cause, app.errorCode(cause));
477479
}

tests/src/test/java/io/jooby/i3787/Issue3787.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ public class Issue3787 {
1212
private final MockRouter router = new MockRouter(new Application()).setFullExecution(true);
1313

1414
@Test
15-
void test() {
15+
void issue3787() {
1616
var ctx = new MockContext();
17-
router.tryError(new Application.CustomException(), ctx); // throws java.lang.NullPointerException
17+
router.tryError(new Application.CustomException(), ctx);
1818
assertEquals(StatusCode.BAD_REQUEST, ctx.getResponseCode());
1919
}
2020
}

0 commit comments

Comments
 (0)