There is a problem that causes the code to land in the handleAmbiguousException method, but I do not know what the problem is that causes the code to get there. My question is this: how can I rewrite the code below in order to actually figure out what the real exception is?
Inside handleAmbiguousException, it says there is a problem calling an upstream service, but I have determined that there is no problem from the upstream service. So I think the issue must be in one of the following methods.
First there is the doSomething() method, which calls retrieveConfiguration(). retrieveConfiguration() accepts a func, which I believe is where the problem is.
public void doSomething(final HttpServletRequest httpServletRequest,
final AbstractCreateTokenRequest request,
final AsyncResponse asyncResponse){
retrieveConfiguration(asyncResponse,
configuration -> doInternalMethod(asyncResponse, request, configuration), InternalConfiguration.class);
}`
private <T extends SomeConfiguration> void
retrieveConfiguration(final AsyncResponse asyncResponse,
final Consumer<T> func,
final Class<T> configClass) {
CompletionStage<T> configuration = configurationService.getConfiguration(configClass);
configuration.thenAccept(func).
exceptionally(throwable -> {
handleAmbiguousException(asyncResponse, throwable);
return null;
});
}`
Based off log statements I added, I don't think the code ever reaches doInternalMethod, but I have pasted it below here in case it is helpful:
private CompletionStage<Either<ServiceErrorResponse, TokenResponse>>
doInternalMethod(final AsyncResponse asyncResponse,
final AbstractCreateTokenRequest request,
final TokenConfiguration configuration) {
final CompletionStage<Either<ServiceErrorResponse, TokenResponse>> stage = tokenCreator
.createToken(configuration)
.exceptionally(this::nestedException);
stage.whenComplete((response, throwable) -> {
MDC.clear();
});
setAsyncResponseFromEither(stage, asyncResponse, REQUEST_TIMEOUT_MS, request.toString());
return stage;
}`
I tried adding log statements right before configuration.thenAccept(func), and they successfully logged to console. But my logs in doInternalMethod() were never reached. So it seems like something is happening at the configuration.thenAccept(func) part. But I do not know how to debug/troubleshoot this to figure out what exactly the error is.
People asked for handleAmbiguousException code, and here it is. This is also where I got the stack trace from:
private void
handleAmibguousException(final AsyncResponse asyncResponse,
final Throwable throwable) {
asyncResponse.resume(ExceptionHandler.mapTheError(throwable));
}
Printing the stack trace only gives me this: java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:273)
Converting the throwable to string gets me this: java.util.concurrent.CompletionException: java.lang.NullPointerException
Printing the message of the throwable gets me this: MESSAGE java.lang.NullPointerException