Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

ErrorHandlerSupplier not always initialized when we first need it #937

Open
rems opened this issue Apr 12, 2023 · 0 comments
Open

ErrorHandlerSupplier not always initialized when we first need it #937

rems opened this issue Apr 12, 2023 · 0 comments
Labels

Comments

@rems
Copy link

rems commented Apr 12, 2023

The ErrorHandlerSupplier might not be fully initialized when we first need it.

As such, a nasty NPE might arise.

java.lang.NullPointerException: Cannot invoke "graphql.kickstart.execution.error.GraphQLErrorHandler.errorsPresent(java.util.List)" because "errorHandler" is null
	at graphql.kickstart.execution.GraphQLObjectMapper.sanitizeErrors(GraphQLObjectMapper.java:131)
	at graphql.kickstart.execution.GraphQLObjectMapper.createResultFromExecutionResult(GraphQLObjectMapper.java:140)
	at graphql.kickstart.execution.GraphQLObjectMapper.serializeResultAsBytes(GraphQLObjectMapper.java:118)
	at graphql.kickstart.servlet.SingleQueryResponseWriter.write(SingleQueryResponseWriter.java:23)
	at graphql.kickstart.servlet.HttpRequestInvokerImpl.writeResultResponse(HttpRequestInvokerImpl.java:149)
	at graphql.kickstart.servlet.HttpRequestInvokerImpl.writeErrorResponse(HttpRequestInvokerImpl.java:163)
	at graphql.kickstart.servlet.HttpRequestInvokerImpl.lambda$handleInternal$5(HttpRequestInvokerImpl.java:137)
	at java.base/java.util.concurrent.CompletableFuture.uniExceptionally(CompletableFuture.java:990)
	at java.base/java.util.concurrent.CompletableFuture.uniExceptionallyStage(CompletableFuture.java:1008)
	at java.base/java.util.concurrent.CompletableFuture.exceptionally(CompletableFuture.java:2364)
	at graphql.kickstart.servlet.HttpRequestInvokerImpl.handleInternal(HttpRequestInvokerImpl.java:135)
	at graphql.kickstart.servlet.HttpRequestInvokerImpl.handle(HttpRequestInvokerImpl.java:109)

It's a bit of a race condition when starting the app, so it's a bit tricky to provide steps to reproduce.

Before

public class GraphQLErrorStartupListener implements ApplicationListener<ApplicationReadyEvent> {

  // ... omitted for brevity

  @Override
  public void onApplicationEvent(ApplicationReadyEvent event) {
     // omitted for brevity
  }
}

Suggested

Change the type of event being listened, from ApplicationReadyEvent to ApplicationStartedEvent

public class GraphQLErrorStartupListener implements ApplicationListener<ApplicationStartedEvent> {

  // ... omitted for brevity

  @Override
  public void onApplicationEvent(ApplicationStartedEvent event) {
     // unchanged body method
  }
}
@rems rems added the bug label Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant