Skip to content

Commit 8d2389a

Browse files
committed
Add nullability annotations to module/spring-boot-graphql
See gh-46587
1 parent efe2d57 commit 8d2389a

File tree

13 files changed

+66
-24
lines changed

13 files changed

+66
-24
lines changed

module/spring-boot-graphql/src/main/java/org/springframework/boot/graphql/autoconfigure/DefaultGraphQlSchemaCondition.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.springframework.core.io.support.ResourcePatternUtils;
3636
import org.springframework.core.type.AnnotatedTypeMetadata;
3737
import org.springframework.graphql.execution.GraphQlSource;
38+
import org.springframework.util.Assert;
3839

3940
/**
4041
* {@link Condition} that checks whether a GraphQL schema has been defined in the
@@ -76,6 +77,7 @@ public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeM
7677
.items(ConditionMessage.Style.QUOTE, Arrays.asList(schema.getLocations())));
7778
}
7879
ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
80+
Assert.state(beanFactory != null, "'beanFactory' must not be null");
7981
String[] customizerBeans = beanFactory.getBeanNamesForType(GraphQlSourceBuilderCustomizer.class, false, false);
8082
if (customizerBeans.length != 0) {
8183
match = true;

module/spring-boot-graphql/src/main/java/org/springframework/boot/graphql/autoconfigure/GraphQlAutoConfiguration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import graphql.introspection.Introspection;
2929
import org.apache.commons.logging.Log;
3030
import org.apache.commons.logging.LogFactory;
31+
import org.jspecify.annotations.Nullable;
3132

3233
import org.springframework.aot.hint.RuntimeHints;
3334
import org.springframework.aot.hint.RuntimeHintsRegistrar;
@@ -204,7 +205,7 @@ GraphQlSourceBuilderCustomizer cursorStrategyCustomizer(CursorStrategy<?> cursor
204205
static class GraphQlResourcesRuntimeHints implements RuntimeHintsRegistrar {
205206

206207
@Override
207-
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
208+
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
208209
hints.resources().registerPattern("graphql/**/*.graphqls").registerPattern("graphql/**/*.gqls");
209210
}
210211

module/spring-boot-graphql/src/main/java/org/springframework/boot/graphql/autoconfigure/GraphQlCorsProperties.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import java.util.ArrayList;
2222
import java.util.List;
2323

24+
import org.jspecify.annotations.Nullable;
25+
2426
import org.springframework.boot.context.properties.ConfigurationProperties;
2527
import org.springframework.boot.context.properties.PropertyMapper;
2628
import org.springframework.boot.convert.DurationUnit;
@@ -72,7 +74,7 @@ public class GraphQlCorsProperties {
7274
/**
7375
* Whether credentials are supported. When not set, credentials are not supported.
7476
*/
75-
private Boolean allowCredentials;
77+
private @Nullable Boolean allowCredentials;
7678

7779
/**
7880
* How long the response from a pre-flight request can be cached by clients. If a
@@ -121,11 +123,11 @@ public void setExposedHeaders(List<String> exposedHeaders) {
121123
this.exposedHeaders = exposedHeaders;
122124
}
123125

124-
public Boolean getAllowCredentials() {
126+
public @Nullable Boolean getAllowCredentials() {
125127
return this.allowCredentials;
126128
}
127129

128-
public void setAllowCredentials(Boolean allowCredentials) {
130+
public void setAllowCredentials(@Nullable Boolean allowCredentials) {
129131
this.allowCredentials = allowCredentials;
130132
}
131133

@@ -137,7 +139,7 @@ public void setMaxAge(Duration maxAge) {
137139
this.maxAge = maxAge;
138140
}
139141

140-
public CorsConfiguration toCorsConfiguration() {
142+
public @Nullable CorsConfiguration toCorsConfiguration() {
141143
if (CollectionUtils.isEmpty(this.allowedOrigins) && CollectionUtils.isEmpty(this.allowedOriginPatterns)) {
142144
return null;
143145
}

module/spring-boot-graphql/src/main/java/org/springframework/boot/graphql/autoconfigure/GraphQlProperties.java

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.time.Duration;
2020
import java.util.Arrays;
2121

22+
import org.jspecify.annotations.Nullable;
23+
2224
import org.springframework.boot.context.properties.ConfigurationProperties;
2325
import org.springframework.core.io.Resource;
2426

@@ -239,7 +241,7 @@ public static class Websocket {
239241
/**
240242
* Path of the GraphQL WebSocket subscription endpoint.
241243
*/
242-
private String path;
244+
private @Nullable String path;
243245

244246
/**
245247
* Time within which the initial {@code CONNECTION_INIT} type message must be
@@ -250,13 +252,13 @@ public static class Websocket {
250252
/**
251253
* Maximum idle period before a server keep-alive ping is sent to client.
252254
*/
253-
private Duration keepAlive;
255+
private @Nullable Duration keepAlive;
254256

255-
public String getPath() {
257+
public @Nullable String getPath() {
256258
return this.path;
257259
}
258260

259-
public void setPath(String path) {
261+
public void setPath(@Nullable String path) {
260262
this.path = path;
261263
}
262264

@@ -268,11 +270,11 @@ public void setConnectionInitTimeout(Duration connectionInitTimeout) {
268270
this.connectionInitTimeout = connectionInitTimeout;
269271
}
270272

271-
public Duration getKeepAlive() {
273+
public @Nullable Duration getKeepAlive() {
272274
return this.keepAlive;
273275
}
274276

275-
public void setKeepAlive(Duration keepAlive) {
277+
public void setKeepAlive(@Nullable Duration keepAlive) {
276278
this.keepAlive = keepAlive;
277279
}
278280

@@ -283,13 +285,13 @@ public static class Rsocket {
283285
/**
284286
* Mapping of the RSocket message handler.
285287
*/
286-
private String mapping;
288+
private @Nullable String mapping;
287289

288-
public String getMapping() {
290+
public @Nullable String getMapping() {
289291
return this.mapping;
290292
}
291293

292-
public void setMapping(String mapping) {
294+
public void setMapping(@Nullable String mapping) {
293295
this.mapping = mapping;
294296
}
295297

@@ -300,26 +302,26 @@ public static class Sse {
300302
/**
301303
* How frequently keep-alive messages should be sent.
302304
*/
303-
private Duration keepAlive;
305+
private @Nullable Duration keepAlive;
304306

305307
/**
306308
* Time required for concurrent handling to complete.
307309
*/
308-
private Duration timeout;
310+
private @Nullable Duration timeout;
309311

310-
public Duration getKeepAlive() {
312+
public @Nullable Duration getKeepAlive() {
311313
return this.keepAlive;
312314
}
313315

314-
public void setKeepAlive(Duration keepAlive) {
316+
public void setKeepAlive(@Nullable Duration keepAlive) {
315317
this.keepAlive = keepAlive;
316318
}
317319

318-
public Duration getTimeout() {
320+
public @Nullable Duration getTimeout() {
319321
return this.timeout;
320322
}
321323

322-
public void setTimeout(Duration timeout) {
324+
public void setTimeout(@Nullable Duration timeout) {
323325
this.timeout = timeout;
324326
}
325327

module/spring-boot-graphql/src/main/java/org/springframework/boot/graphql/autoconfigure/data/package-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
/**
1818
* Auto-configuration classes for data integrations with GraphQL.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.graphql.autoconfigure.data;
22+
23+
import org.jspecify.annotations.NullMarked;

module/spring-boot-graphql/src/main/java/org/springframework/boot/graphql/autoconfigure/observation/package-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
/**
1818
* Auto-configuration for Spring GraphQL observations.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.graphql.autoconfigure.observation;
22+
23+
import org.jspecify.annotations.NullMarked;

module/spring-boot-graphql/src/main/java/org/springframework/boot/graphql/autoconfigure/package-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
/**
1818
* Auto-configuration for Spring GraphQL.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.graphql.autoconfigure;
22+
23+
import org.jspecify.annotations.NullMarked;

module/spring-boot-graphql/src/main/java/org/springframework/boot/graphql/autoconfigure/reactive/GraphQlWebFluxAutoConfiguration.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import graphql.GraphQL;
2222
import org.apache.commons.logging.Log;
2323
import org.apache.commons.logging.LogFactory;
24+
import org.jspecify.annotations.Nullable;
2425
import reactor.core.publisher.Mono;
2526

2627
import org.springframework.aot.hint.RuntimeHints;
@@ -118,7 +119,7 @@ RouterFunction<ServerResponse> graphQlRouterFunction(GraphQlHttpHandler httpHand
118119
builder.POST(path, this::unsupportedMediaType);
119120
builder.GET(path, this::onlyAllowPost);
120121
if (properties.getGraphiql().isEnabled()) {
121-
GraphiQlHandler graphQlHandler = new GraphiQlHandler(path, properties.getWebsocket().getPath());
122+
GraphiQlHandler graphQlHandler = createGraphQlHandler(properties, path);
122123
builder.GET(properties.getGraphiql().getPath(), graphQlHandler::handleRequest);
123124
}
124125
GraphQlSource graphQlSource = graphQlSourceProvider.getIfAvailable();
@@ -129,6 +130,12 @@ RouterFunction<ServerResponse> graphQlRouterFunction(GraphQlHttpHandler httpHand
129130
return builder.build();
130131
}
131132

133+
// https://github.com/spring-projects/spring-graphql/issues/1276
134+
@SuppressWarnings("NullAway")
135+
private GraphiQlHandler createGraphQlHandler(GraphQlProperties properties, String path) {
136+
return new GraphiQlHandler(path, properties.getWebsocket().getPath());
137+
}
138+
132139
private Mono<ServerResponse> unsupportedMediaType(ServerRequest request) {
133140
return ServerResponse.status(HttpStatus.UNSUPPORTED_MEDIA_TYPE).headers(this::acceptJson).build();
134141
}
@@ -196,7 +203,7 @@ HandlerMapping graphQlWebSocketEndpoint(GraphQlWebSocketHandler graphQlWebSocket
196203
static class GraphiQlResourceHints implements RuntimeHintsRegistrar {
197204

198205
@Override
199-
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
206+
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
200207
hints.resources().registerPattern("graphiql/index.html");
201208
}
202209

module/spring-boot-graphql/src/main/java/org/springframework/boot/graphql/autoconfigure/reactive/package-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
/**
1818
* Auto-configuration classes for WebFlux support in Spring GraphQL.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.graphql.autoconfigure.reactive;
22+
23+
import org.jspecify.annotations.NullMarked;

module/spring-boot-graphql/src/main/java/org/springframework/boot/graphql/autoconfigure/rsocket/package-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
/**
1818
* Auto-configuration classes for RSocket integration with GraphQL.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.graphql.autoconfigure.rsocket;
22+
23+
import org.jspecify.annotations.NullMarked;

0 commit comments

Comments
 (0)