@@ -76,7 +76,7 @@ private static ChainedInstrumentationState asChainedState(@Nullable Instrumentat
7676 return (ChainedInstrumentationState ) assertNotNull (state );
7777 }
7878
79- private <T > @ Nullable InstrumentationContext <T > chainedCtx (@ Nullable InstrumentationState state , BiFunction <Instrumentation , InstrumentationState , InstrumentationContext <T >> mapper ) {
79+ private <T > @ Nullable InstrumentationContext <T > chainedCtx (@ Nullable InstrumentationState state , BiFunction <Instrumentation , @ Nullable InstrumentationState , InstrumentationContext <T >> mapper ) {
8080 // if we have zero or 1 instrumentations (and 1 is the most common), then we can avoid an object allocation
8181 // of the ChainedInstrumentationContext since it won't be needed
8282 if (instrumentations .isEmpty ()) {
@@ -89,35 +89,35 @@ private static ChainedInstrumentationState asChainedState(@Nullable Instrumentat
8989 return new ChainedInstrumentationContext <>(chainedMapAndDropNulls (chainedInstrumentationState , mapper ));
9090 }
9191
92- private <T > T chainedInstrument (@ Nullable InstrumentationState state , T input , ChainedInstrumentationFunction <Instrumentation , InstrumentationState , T , T > mapper ) {
92+ private <T > T chainedInstrument (@ Nullable InstrumentationState state , T input , ChainedInstrumentationFunction <Instrumentation , T , T > mapper ) {
9393 ChainedInstrumentationState chainedInstrumentationState = asChainedState (state );
9494 for (int i = 0 ; i < instrumentations .size (); i ++) {
9595 Instrumentation instrumentation = instrumentations .get (i );
96- InstrumentationState specificState = chainedInstrumentationState .getState (i );
96+ @ Nullable InstrumentationState specificState = chainedInstrumentationState .getState (i );
9797 input = mapper .apply (instrumentation , specificState , input );
9898 }
9999 return input ;
100100 }
101101
102- protected <T > ImmutableList <T > chainedMapAndDropNulls (@ Nullable InstrumentationState state , BiFunction <Instrumentation , InstrumentationState , T > mapper ) {
102+ protected <T > ImmutableList <T > chainedMapAndDropNulls (@ Nullable InstrumentationState state , BiFunction <Instrumentation , @ Nullable InstrumentationState , T > mapper ) {
103103 ChainedInstrumentationState chainedInstrumentationState = asChainedState (state );
104104 ImmutableList .Builder <T > result = ImmutableList .builderWithExpectedSize (instrumentations .size ());
105105 for (int i = 0 ; i < instrumentations .size (); i ++) {
106106 Instrumentation instrumentation = instrumentations .get (i );
107- InstrumentationState specificState = chainedInstrumentationState .getState (i );
108- T value = mapper .apply (instrumentation , specificState );
107+ @ Nullable InstrumentationState specificState = chainedInstrumentationState .getState (i );
108+ @ Nullable T value = mapper .apply (instrumentation , specificState );
109109 if (value != null ) {
110110 result .add (value );
111111 }
112112 }
113113 return result .build ();
114114 }
115115
116- protected void chainedConsume (@ Nullable InstrumentationState state , BiConsumer <Instrumentation , InstrumentationState > stateConsumer ) {
116+ protected void chainedConsume (@ Nullable InstrumentationState state , BiConsumer <Instrumentation , @ Nullable InstrumentationState > stateConsumer ) {
117117 ChainedInstrumentationState chainedInstrumentationState = asChainedState (state );
118118 for (int i = 0 ; i < instrumentations .size (); i ++) {
119119 Instrumentation instrumentation = instrumentations .get (i );
120- InstrumentationState specificState = chainedInstrumentationState .getState (i );
120+ @ Nullable InstrumentationState specificState = chainedInstrumentationState .getState (i );
121121 stateConsumer .accept (instrumentation , specificState );
122122 }
123123 }
@@ -159,7 +159,7 @@ public CompletableFuture<InstrumentationState> createStateAsync(InstrumentationC
159159 if (instrumentations .isEmpty ()) {
160160 return ExecutionStrategyInstrumentationContext .NOOP ;
161161 }
162- BiFunction <Instrumentation , InstrumentationState , ExecutionStrategyInstrumentationContext > mapper = (instrumentation , specificState ) -> instrumentation .beginExecutionStrategy (parameters , specificState );
162+ BiFunction <Instrumentation , @ Nullable InstrumentationState , ExecutionStrategyInstrumentationContext > mapper = (instrumentation , specificState ) -> instrumentation .beginExecutionStrategy (parameters , specificState );
163163 ChainedInstrumentationState chainedInstrumentationState = asChainedState (state );
164164 if (instrumentations .size () == 1 ) {
165165 return mapper .apply (instrumentations .get (0 ), chainedInstrumentationState .getState (0 ));
@@ -172,7 +172,7 @@ public CompletableFuture<InstrumentationState> createStateAsync(InstrumentationC
172172 if (instrumentations .isEmpty ()) {
173173 return ExecuteObjectInstrumentationContext .NOOP ;
174174 }
175- BiFunction <Instrumentation , InstrumentationState , ExecuteObjectInstrumentationContext > mapper = (instrumentation , specificState ) -> instrumentation .beginExecuteObject (parameters , specificState );
175+ BiFunction <Instrumentation , @ Nullable InstrumentationState , ExecuteObjectInstrumentationContext > mapper = (instrumentation , specificState ) -> instrumentation .beginExecuteObject (parameters , specificState );
176176 ChainedInstrumentationState chainedInstrumentationState = asChainedState (state );
177177 if (instrumentations .size () == 1 ) {
178178 return mapper .apply (instrumentations .get (0 ), chainedInstrumentationState .getState (0 ));
@@ -207,7 +207,7 @@ public CompletableFuture<InstrumentationState> createStateAsync(InstrumentationC
207207 if (instrumentations .isEmpty ()) {
208208 return FieldFetchingInstrumentationContext .NOOP ;
209209 }
210- BiFunction <Instrumentation , InstrumentationState , FieldFetchingInstrumentationContext > mapper = (instrumentation , specificState ) -> instrumentation .beginFieldFetching (parameters , specificState );
210+ BiFunction <Instrumentation , @ Nullable InstrumentationState , FieldFetchingInstrumentationContext > mapper = (instrumentation , specificState ) -> instrumentation .beginFieldFetching (parameters , specificState );
211211 ChainedInstrumentationState chainedInstrumentationState = asChainedState (state );
212212 if (instrumentations .size () == 1 ) {
213213 return mapper .apply (instrumentations .get (0 ), chainedInstrumentationState .getState (0 ));
@@ -252,38 +252,38 @@ public ExecutionContext instrumentExecutionContext(ExecutionContext executionCon
252252
253253 @ Override
254254 public DataFetcher <?> instrumentDataFetcher (DataFetcher <?> dataFetcher , InstrumentationFieldFetchParameters parameters , @ Nullable InstrumentationState state ) {
255- return chainedInstrument (state , dataFetcher , (Instrumentation instrumentation , InstrumentationState specificState , DataFetcher <?> accumulator ) ->
255+ return chainedInstrument (state , dataFetcher , (Instrumentation instrumentation , @ Nullable InstrumentationState specificState , DataFetcher <?> accumulator ) ->
256256 instrumentation .instrumentDataFetcher (accumulator , parameters , specificState ));
257257 }
258258
259259 @ Override
260260 public CompletableFuture <ExecutionResult > instrumentExecutionResult (ExecutionResult executionResult , InstrumentationExecutionParameters parameters , @ Nullable InstrumentationState state ) {
261- ImmutableList <Map .Entry <Instrumentation , InstrumentationState >> entries = chainedMapAndDropNulls (state , AbstractMap .SimpleEntry ::new );
261+ ImmutableList <Map .Entry <Instrumentation , @ Nullable InstrumentationState >> entries = chainedMapAndDropNulls (state , AbstractMap .SimpleEntry ::new );
262262 CompletableFuture <List <ExecutionResult >> resultsFuture = Async .eachSequentially (entries , (entry , prevResults ) -> {
263263 Instrumentation instrumentation = entry .getKey ();
264- InstrumentationState specificState = entry .getValue ();
264+ @ Nullable InstrumentationState specificState = entry .getValue ();
265265 ExecutionResult lastResult = !prevResults .isEmpty () ? prevResults .get (prevResults .size () - 1 ) : executionResult ;
266266 return instrumentation .instrumentExecutionResult (lastResult , parameters , specificState );
267267 });
268268 return resultsFuture .thenApply ((results ) -> results .isEmpty () ? executionResult : results .get (results .size () - 1 ));
269269 }
270270
271271 static class ChainedInstrumentationState implements InstrumentationState {
272- private final List <InstrumentationState > instrumentationStates ;
272+ private final List <@ Nullable InstrumentationState > instrumentationStates ;
273273
274- private ChainedInstrumentationState (List <InstrumentationState > instrumentationStates ) {
274+ private ChainedInstrumentationState (List <@ Nullable InstrumentationState > instrumentationStates ) {
275275 this .instrumentationStates = instrumentationStates ;
276276 }
277277
278- private InstrumentationState getState (int index ) {
278+ private @ Nullable InstrumentationState getState (int index ) {
279279 return instrumentationStates .get (index );
280280 }
281281
282282 private static CompletableFuture <InstrumentationState > combineAll (List <Instrumentation > instrumentations , InstrumentationCreateStateParameters parameters ) {
283- Async .CombinedBuilder <InstrumentationState > builder = Async .ofExpectedSize (instrumentations .size ());
283+ Async .CombinedBuilder <@ Nullable InstrumentationState > builder = Async .ofExpectedSize (instrumentations .size ());
284284 for (Instrumentation instrumentation : instrumentations ) {
285285 // state can be null including the CF so handle that
286- CompletableFuture <InstrumentationState > stateCF = Async .orNullCompletedFuture (instrumentation .createStateAsync (parameters ));
286+ CompletableFuture <@ Nullable InstrumentationState > stateCF = Async .< @ Nullable InstrumentationState > orNullCompletedFuture (instrumentation .createStateAsync (parameters ));
287287 builder .add (stateCF );
288288 }
289289 return builder .await ().thenApply (ChainedInstrumentationState ::new );
@@ -417,8 +417,8 @@ public void onCompleted(@Nullable Object result, @Nullable Throwable t) {
417417 }
418418
419419 @ FunctionalInterface
420- private interface ChainedInstrumentationFunction <I , S , V , R > {
421- R apply (I instrumentation , S state , V value );
420+ private interface ChainedInstrumentationFunction <I , V , R > {
421+ R apply (I instrumentation , @ Nullable InstrumentationState state , V value );
422422 }
423423
424424
0 commit comments