DispatcherServlet 中缺少堆栈跟踪的随机 NullPointerExceptions
Random NullPointerExceptions with missing stacktrace in DispatcherServlet
访问我的端点之一时,我看到随机 NullPointerException。
我知道 NPE 是什么,但请耐心等待,我这里有很多问题:
- 问题可能每 10000 次调用就会发生一次
- 如果我第二次重播同一个请求,它就可以正常工作
- 它看起来好像没有到达我的控制器中的代码(没有记录任何语句)
- 而且,最烦人的是...我没有堆栈跟踪来帮助我查明问题。
这是记录的内容:
[p-nio-80-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
java.lang.NullPointerException: null
Annnnnd,就是这样,仅此而已...
控制器的代码比较简单,看起来像这样:
@RepositoryRestController
@ResponseBody
public class AnimalImportEndpoint {
@Inject
private animalImportService;
@RequestMapping(value = "/animals/import", method = RequestMethod.POST)
public AnimalImportResult import(@Valid @RequestBody Animal animal) {
return animalImportService.import(animal);
}
@ResponseStatus(value = HttpStatus.BAD_REQUEST, reason = "Illegal arguments")
@ExceptionHandler(IllegalArgumentException.class)
public void illegalArguments() {
}
}
class 被注释为 @RepositoryRestController
而不是 @RestController
因为 Spring Data Rest 也公开了 /animals
.
关于如何解决此问题的任何指示或建议?
编辑:其他有趣的事实,我使用 sleuth 来跟踪请求。当我得到这个 NullPointerException 时,我可以看到我的日志中没有 spanId/traceId ...
添加此 JVM 参数以禁用堆栈跟踪删除优化
-XX:-OmitStackTraceInFastThrow
访问我的端点之一时,我看到随机 NullPointerException。
我知道 NPE 是什么,但请耐心等待,我这里有很多问题:
- 问题可能每 10000 次调用就会发生一次
- 如果我第二次重播同一个请求,它就可以正常工作
- 它看起来好像没有到达我的控制器中的代码(没有记录任何语句)
- 而且,最烦人的是...我没有堆栈跟踪来帮助我查明问题。
这是记录的内容:
[p-nio-80-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
java.lang.NullPointerException: null
Annnnnd,就是这样,仅此而已...
控制器的代码比较简单,看起来像这样:
@RepositoryRestController
@ResponseBody
public class AnimalImportEndpoint {
@Inject
private animalImportService;
@RequestMapping(value = "/animals/import", method = RequestMethod.POST)
public AnimalImportResult import(@Valid @RequestBody Animal animal) {
return animalImportService.import(animal);
}
@ResponseStatus(value = HttpStatus.BAD_REQUEST, reason = "Illegal arguments")
@ExceptionHandler(IllegalArgumentException.class)
public void illegalArguments() {
}
}
class 被注释为 @RepositoryRestController
而不是 @RestController
因为 Spring Data Rest 也公开了 /animals
.
关于如何解决此问题的任何指示或建议?
编辑:其他有趣的事实,我使用 sleuth 来跟踪请求。当我得到这个 NullPointerException 时,我可以看到我的日志中没有 spanId/traceId ...
添加此 JVM 参数以禁用堆栈跟踪删除优化
-XX:-OmitStackTraceInFastThrow