I see random NullPointerException when one of my endpoints is accessed.
I know what an NPE is, but please bear with me, I have many issues here :
This is what it is logged :
[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, that's it, nothing more...
The code of the controller is rather straithforward, it looks like this :
@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() {
}
}
The class is annoted with @RepositoryRestController
instead of @RestController
because Spring Data Rest also exposes /animals
.
Any pointers or advice on how to troubleshoot this ?
Edit : other interesting fact, I use sleuth to trace requests. When I get this NullPointerException, I can see that there is no spanId/traceId in my logs ...
Add this JVM argument to disable stacktrace removal optimization
-XX:-OmitStackTraceInFastThrow