Skip to content

Add JSpecify annotations to execution instrumentation classes (10 more)#4272

Open
dondonz wants to merge 5 commits intomasterfrom
jspecify-execution-instrumentation-classes
Open

Add JSpecify annotations to execution instrumentation classes (10 more)#4272
dondonz wants to merge 5 commits intomasterfrom
jspecify-execution-instrumentation-classes

Conversation

@dondonz
Copy link
Member

@dondonz dondonz commented Feb 27, 2026

Summary

Annotates execution instrumentation public API classes with @NullMarked and appropriate @Nullable annotations, removing them from the JSpecify archunit exemption list.

Classes annotated:

  • DeferredExecutionlabel is @Nullable per the GraphQL spec (@defer label is optional)
  • ResponseMapFactory — map values are @Nullable Object since GraphQL fields can resolve to null
  • ChainedInstrumentation — removes redundant @NonNull on instrument* overrides (covered by @NullMarked); propagates @Nullable from the Instrumentation interface onto all begin* return types and onCompleted parameters
  • DocumentAndVariables@NullUnmarked on Builder (uninitialized fields)
  • NoContextChainedInstrumentationrunAll() return type annotated @Nullable T (always returns null)
  • SimpleInstrumentation@NullMarked only; all methods delegate to the interface defaults
  • SimpleInstrumentationContextcodeToRunOnComplete and codeToRunOnDispatch fields are @Nullable (set to null by the no-arg constructor); nonNullCtx parameter and onCompleted params annotated @Nullable
  • SimplePerformantInstrumentation — removes redundant @NonNull on instrument* overrides
  • FieldAndArgumentsgetParentFieldAndArguments() is @Nullable (root field has no parent); getArgumentValue() returns @Nullable T (argument values can be absent/null)
  • FieldValidationEnvironment@NullMarked only; all return types are non-null

Also fixes a pre-existing gap in Instrumentation: beginDeferredField was the only begin* method missing @Nullable on its return type, despite the Javadoc stating it returns "a nullable InstrumentationContext". This would have caused a nullability conflict once Instrumentation itself becomes @NullMarked.

Test plan

  • Archunit JSpecifyAnnotationsCheck passes — the 10 exemptions for these classes are removed
  • All existing tests pass

dondonz and others added 2 commits February 26, 2026 21:03
Annotates the following classes with @NullMarked and appropriate
@nullable annotations:
- DeferredExecution (label is @nullable per GraphQL spec)
- ChainedInstrumentation (removes @nonnull, propagates @nullable from Instrumentation interface)
- DocumentAndVariables (@NullUnmarked on Builder)
- NoContextChainedInstrumentation (runAll returns @nullable T)
- ResponseMapFactory (values are @nullable per Javadoc contract)
- SimpleInstrumentation
- SimpleInstrumentationContext (@nullable fields, params, onCompleted)
- SimplePerformantInstrumentation (removes @nonnull on instrument* overrides)
- FieldAndArguments (getParentFieldAndArguments @nullable, getArgumentValue @nullable T)
- FieldValidationEnvironment

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@dondonz dondonz marked this pull request as draft February 27, 2026 21:04
@github-actions
Copy link
Contributor

github-actions bot commented Feb 27, 2026

Test Results

  335 files  ±0    335 suites  ±0   5m 2s ⏱️ -7s
5 378 tests ±0  5 369 ✅  - 1  9 💤 +1  0 ❌ ±0 
5 467 runs  ±0  5 458 ✅  - 1  9 💤 +1  0 ❌ ±0 

Results for commit 15696d4. ± Comparison against base commit 1e867c2.

This pull request removes 196 and adds 172 tests. Note that renamed tests count towards both.
	?

	, expected: combo-\"\\\b\f\n\r\t, #4]
                __schema { types { fields { args { type { name fields { name }}}}}}
                __schema { types { fields { type { name fields { name }}}}}
                __schema { types { inputFields { type { inputFields { name }}}}}
                __schema { types { interfaces { fields { type { interfaces { name } } } } } }
                __schema { types { name} }
                __type(name : "t") { name }
                a1: __schema { types { name} }
                a1: __type(name : "t") { name }
…
graphql.AssertTest ‑ assertFalse with different number of error args but false does not throw assertions [toRun: <graphql.AssertTest$__spock_feature_0_21prov0_closure23@1f346ad2 delegate=inaccessible owner=inaccessible thisObject=inaccessible resolveStrategy=inaccessible directive=inaccessible parameterTypes=inaccessible maximumNumberOfParameters=inaccessible bcw=inaccessible thisType=inaccessible>, expectedMessage: error arg1, #0]
graphql.AssertTest ‑ assertFalse with different number of error args but false does not throw assertions [toRun: <graphql.AssertTest$__spock_feature_0_21prov0_closure24@46a145ba delegate=inaccessible owner=inaccessible thisObject=inaccessible resolveStrategy=inaccessible directive=inaccessible parameterTypes=inaccessible maximumNumberOfParameters=inaccessible bcw=inaccessible thisType=inaccessible>, expectedMessage: error arg1 arg2, #1]
graphql.AssertTest ‑ assertFalse with different number of error args but false does not throw assertions [toRun: <graphql.AssertTest$__spock_feature_0_21prov0_closure25@7ab34619 delegate=inaccessible owner=inaccessible thisObject=inaccessible resolveStrategy=inaccessible directive=inaccessible parameterTypes=inaccessible maximumNumberOfParameters=inaccessible bcw=inaccessible thisType=inaccessible>, expectedMessage: error arg1 arg2 arg3, #2]
graphql.AssertTest ‑ assertFalse with different number of error args throws assertions [toRun: <graphql.AssertTest$__spock_feature_0_20prov0_closure20@64d4f7c7 delegate=inaccessible owner=inaccessible thisObject=inaccessible resolveStrategy=inaccessible directive=inaccessible parameterTypes=inaccessible maximumNumberOfParameters=inaccessible bcw=inaccessible thisType=inaccessible>, expectedMessage: error arg1, #0]
graphql.AssertTest ‑ assertFalse with different number of error args throws assertions [toRun: <graphql.AssertTest$__spock_feature_0_20prov0_closure21@54e02f6a delegate=inaccessible owner=inaccessible thisObject=inaccessible resolveStrategy=inaccessible directive=inaccessible parameterTypes=inaccessible maximumNumberOfParameters=inaccessible bcw=inaccessible thisType=inaccessible>, expectedMessage: error arg1 arg2, #1]
graphql.AssertTest ‑ assertFalse with different number of error args throws assertions [toRun: <graphql.AssertTest$__spock_feature_0_20prov0_closure22@17f3eefb delegate=inaccessible owner=inaccessible thisObject=inaccessible resolveStrategy=inaccessible directive=inaccessible parameterTypes=inaccessible maximumNumberOfParameters=inaccessible bcw=inaccessible thisType=inaccessible>, expectedMessage: error arg1 arg2 arg3, #2]
graphql.AssertTest ‑ assertNotNull with different number of  error args throws assertions [toRun: <graphql.AssertTest$__spock_feature_0_5prov0_closure3@fc807c1 delegate=inaccessible owner=inaccessible thisObject=inaccessible resolveStrategy=inaccessible directive=inaccessible parameterTypes=inaccessible maximumNumberOfParameters=inaccessible bcw=inaccessible thisType=inaccessible>, expectedMessage: error arg1, #0]
graphql.AssertTest ‑ assertNotNull with different number of  error args throws assertions [toRun: <graphql.AssertTest$__spock_feature_0_5prov0_closure4@434514d8 delegate=inaccessible owner=inaccessible thisObject=inaccessible resolveStrategy=inaccessible directive=inaccessible parameterTypes=inaccessible maximumNumberOfParameters=inaccessible bcw=inaccessible thisType=inaccessible>, expectedMessage: error arg1 arg2, #1]
graphql.AssertTest ‑ assertNotNull with different number of  error args throws assertions [toRun: <graphql.AssertTest$__spock_feature_0_5prov0_closure5@bc042d5 delegate=inaccessible owner=inaccessible thisObject=inaccessible resolveStrategy=inaccessible directive=inaccessible parameterTypes=inaccessible maximumNumberOfParameters=inaccessible bcw=inaccessible thisType=inaccessible>, expectedMessage: error arg1 arg2 arg3, #2]
graphql.AssertTest ‑ assertNotNull with different number of error args with non null does not throw assertions [toRun: <graphql.AssertTest$__spock_feature_0_6prov0_closure6@1305c126 delegate=inaccessible owner=inaccessible thisObject=inaccessible resolveStrategy=inaccessible directive=inaccessible parameterTypes=inaccessible maximumNumberOfParameters=inaccessible bcw=inaccessible thisType=inaccessible>, expectedMessage: error arg1, #0]
…
This pull request skips 1 test.
graphql.schema.fetching.LambdaFetchingSupportTest ‑ different class loaders induce certain behaviours

♻️ This comment has been updated with latest results.

@dondonz dondonz marked this pull request as ready for review February 28, 2026 06:22
dondonz and others added 2 commits February 28, 2026 17:30
…arameter

chainedCtx can return null in the single-instrumentation case since it
passes the mapper result through directly, and the underlying
Instrumentation begin* methods are @nullable (null is the opt-out signal).

The BiFunction return type also needs @nullable so that mapper.apply()
is correctly typed as nullable, allowing the nullability to flow from
the underlying instrumentation through the lambda to chainedCtx's return.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@dondonz dondonz marked this pull request as draft February 28, 2026 06:36
chainedCtx can return null in the single-instrumentation case since it
passes the mapper result through directly, and the underlying
Instrumentation begin* methods are @nullable (null is the opt-out signal).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
}

private <T> InstrumentationContext<T> chainedCtx(InstrumentationState state, BiFunction<Instrumentation, InstrumentationState, InstrumentationContext<T>> mapper) {
private <T> @Nullable InstrumentationContext<T> chainedCtx(InstrumentationState state, BiFunction<Instrumentation, InstrumentationState, InstrumentationContext<T>> mapper) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This project is a good exercise in catching a bunch of extra nullable annotations

@dondonz dondonz marked this pull request as ready for review February 28, 2026 06:46
@dondonz dondonz changed the title Add JSpecify annotations to execution instrumentation classes Add JSpecify annotations to execution instrumentation classes (10 more) Feb 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant