You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SimplePerformantInstrumentation hooks declares InstrumentationState non-null but createState returns null by default #4433
Describe the bug
In graphql-java 26, SimplePerformantInstrumentation is annotated with @NullMarked. Its unannotated InstrumentationState callback parameters are therefore exposed to Kotlin as non-null.
However, createState() and createStateAsync() remain explicitly nullable, and the default SimplePerformantInstrumentation.createState() implementation returns null.
The callback state parameters should either be annotated @Nullable, matching the existing optional-state behavior, or graphql-java should guarantee a non-null empty state. Making the parameters nullable would preserve the existing runtime contract.
To Reproduce
Please provide a code example or even better a test to reproduce the bug.
importgraphql.ExecutionResultimportgraphql.GraphQLimportgraphql.execution.instrumentation.InstrumentationContextimportgraphql.execution.instrumentation.InstrumentationStateimportgraphql.execution.instrumentation.SimplePerformantInstrumentationimportgraphql.execution.instrumentation.parameters.InstrumentationExecutionParametersimportgraphql.schema.idl.RuntimeWiringimportgraphql.schema.idl.SchemaGeneratorimportgraphql.schema.idl.SchemaParserimportkotlin.test.TestclassInstrumentationStateNullabilityTest {
privateclassStatelessInstrumentation : SimplePerformantInstrumentation() {
overridefunbeginExecution(
parameters:InstrumentationExecutionParameters,
state:InstrumentationState
): InstrumentationContext<ExecutionResult>?=null
}
@Test
fun`stateless Kotlin instrumentation should execute without an NPE`() {
val typeRegistry =SchemaParser().parse(
""" type Query { hello: String }""".trimIndent()
)
val schema =SchemaGenerator().makeExecutableSchema(
typeRegistry,
RuntimeWiring.MOCKED_WIRING
)
val graphQL =GraphQL.newGraphQL(schema)
.instrumentation(StatelessInstrumentation())
.build()
graphQL.execute("{ hello }")
}
}
The execution fails when beginExecution is invoked:
java.lang.NullPointerException:
Parameter specified as non-null is null:
method StatelessInstrumentation.beginExecution, parameter state
A current workaround is to return a non-null marker state:
Activity
chore: update to graphql-java 26 (#2205)
fix: mark InstrumentationState callback params as @nullable