Skip to content

Commit 2e8428b

Browse files
committed
Remove NullAway suppressions where possible
See gh-46926
1 parent 634933b commit 2e8428b

File tree

10 files changed

+39
-46
lines changed

10 files changed

+39
-46
lines changed

build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/buildinfo/BuildInfoProperties.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ Map<String, String> getAdditionalIfNotExcluded() {
142142
return coerceToStringValues(applyExclusions(getAdditional().getOrElse(Collections.emptyMap())));
143143
}
144144

145-
@SuppressWarnings("NullAway") // Doesn't detect lambda with correct nullability
146145
private <T> @Nullable T getIfNotExcluded(Property<T> property, String name) {
147-
return getIfNotExcluded(property, name, () -> null);
146+
Supplier<@Nullable T> supplier = () -> null;
147+
return getIfNotExcluded(property, name, supplier);
148148
}
149149

150150
private <T> @Nullable T getIfNotExcluded(Property<T> property, String name, Supplier<@Nullable T> defaultValue) {

build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/StartMojo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,12 @@ private void waitForSpringApplication() throws MojoFailureException, MojoExecuti
156156
}
157157
}
158158

159-
@SuppressWarnings("NullAway") // Lambda isn't detected with the correct nullability
160159
private void doWaitForSpringApplication(MBeanServerConnection connection)
161160
throws MojoExecutionException, MojoFailureException {
162161
final SpringApplicationAdminClient client = new SpringApplicationAdminClient(connection, this.jmxName);
163162
try {
164-
execute(this.wait, this.maxAttempts, () -> (client.isReady() ? true : null));
163+
Callable<@Nullable Boolean> isReady = () -> (client.isReady() ? true : null);
164+
execute(this.wait, this.maxAttempts, isReady);
165165
}
166166
catch (ReflectionException ex) {
167167
throw new MojoExecutionException("Unable to retrieve 'ready' attribute", ex.getCause());

core/spring-boot/src/main/java/org/springframework/boot/DefaultBootstrapContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ public void addCloseListener(ApplicationListener<BootstrapContextClosedEvent> li
9191
}
9292

9393
@Override
94-
@SuppressWarnings("NullAway") // Doesn't detect lambda with correct nullability
9594
public <T> @Nullable T getOrElse(Class<T> type, @Nullable T other) {
96-
return getOrElseSupply(type, () -> other);
95+
Supplier<@Nullable T> supplier = () -> other;
96+
return getOrElseSupply(type, supplier);
9797
}
9898

9999
@Override

core/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/Binder.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -459,15 +459,15 @@ public <T> T bindOrCreate(ConfigurationPropertyName name, Bindable<T> target, @N
459459
return null;
460460
}
461461

462-
@SuppressWarnings("NullAway") // Doesn't detect lambda with correct nullability
463462
private <T> @Nullable Object bindAggregate(ConfigurationPropertyName name, Bindable<T> target, BindHandler handler,
464463
Context context, AggregateBinder<?> aggregateBinder) {
465464
AggregateElementBinder elementBinder = (itemName, itemTarget, source) -> {
466465
boolean allowRecursiveBinding = aggregateBinder.isAllowRecursiveBinding(source);
467466
Supplier<?> supplier = () -> bind(itemName, itemTarget, handler, context, allowRecursiveBinding, false);
468467
return context.withSource(source, supplier);
469468
};
470-
return context.withIncreasedDepth(() -> aggregateBinder.bind(name, target, elementBinder));
469+
Supplier<@Nullable Object> supplier = () -> aggregateBinder.bind(name, target, elementBinder);
470+
return context.withIncreasedDepth(supplier);
471471
}
472472

473473
private <T> @Nullable ConfigurationProperty findProperty(ConfigurationPropertyName name, Bindable<T> target,
@@ -492,7 +492,6 @@ public <T> T bindOrCreate(ConfigurationPropertyName name, Bindable<T> target, @N
492492
return result;
493493
}
494494

495-
@SuppressWarnings("NullAway") // Doesn't detect lambda with correct nullability
496495
private @Nullable Object bindDataObject(ConfigurationPropertyName name, Bindable<?> target, BindHandler handler,
497496
Context context, boolean allowRecursiveBinding) {
498497
if (isUnbindableBean(name, target, context)) {
@@ -505,8 +504,9 @@ public <T> T bindOrCreate(ConfigurationPropertyName name, Bindable<T> target, @N
505504
}
506505
DataObjectPropertyBinder propertyBinder = (propertyName, propertyTarget) -> bind(name.append(propertyName),
507506
propertyTarget, handler, context, false, false);
508-
return context.withDataObject(type, () -> fromDataObjectBinders(bindMethod,
509-
(dataObjectBinder) -> dataObjectBinder.bind(name, target, context, propertyBinder)));
507+
Supplier<@Nullable Object> supplier = () -> fromDataObjectBinders(bindMethod,
508+
(dataObjectBinder) -> dataObjectBinder.bind(name, target, context, propertyBinder));
509+
return context.withDataObject(type, supplier);
510510
}
511511

512512
private @Nullable Object fromDataObjectBinders(@Nullable BindMethod bindMethod,

core/spring-boot/src/main/java/org/springframework/boot/context/properties/source/MutuallyExclusiveConfigurationPropertiesException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ private static String buildMessage(Set<String> mutuallyExclusiveNames, Set<Strin
101101
* non-null values are defined in a set of entries.
102102
* @param entries a consumer used to populate the entries to check
103103
*/
104-
@SuppressWarnings("NullAway") // Doesn't detect lambda with correct nullability
105104
public static void throwIfMultipleNonNullValuesIn(Consumer<Map<String, @Nullable Object>> entries) {
106-
throwIfMultipleMatchingValuesIn(entries, Objects::nonNull);
105+
Predicate<@Nullable Object> isNonNull = Objects::nonNull;
106+
throwIfMultipleMatchingValuesIn(entries, isNonNull);
107107
}
108108

109109
/**

core/spring-boot/src/main/java/org/springframework/boot/util/LambdaSafe.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,12 @@ private Callback(Class<C> callbackType, C callbackInstance, A argument,
252252
* Invoke the callback instance where the callback method returns void.
253253
* @param invoker the invoker used to invoke the callback
254254
*/
255-
// Lambda isn't detected with the correct nullability
256-
@SuppressWarnings("NullAway")
257255
public void invoke(Consumer<C> invoker) {
258-
invoke(this.callbackInstance, () -> {
256+
Supplier<@Nullable Void> supplier = () -> {
259257
invoker.accept(this.callbackInstance);
260258
return null;
261-
});
259+
};
260+
invoke(this.callbackInstance, supplier);
262261
}
263262

264263
/**
@@ -268,10 +267,9 @@ public void invoke(Consumer<C> invoker) {
268267
* @return the result of the invocation (may be {@link InvocationResult#noResult}
269268
* if the callback was not invoked)
270269
*/
271-
// Lambda isn't detected with the correct nullability
272-
@SuppressWarnings("NullAway")
273270
public <R> InvocationResult<R> invokeAnd(Function<C, @Nullable R> invoker) {
274-
return invoke(this.callbackInstance, () -> invoker.apply(this.callbackInstance));
271+
Supplier<@Nullable R> supplier = () -> invoker.apply(this.callbackInstance);
272+
return invoke(this.callbackInstance, supplier);
275273
}
276274

277275
}
@@ -296,13 +294,14 @@ private Callbacks(Class<C> callbackType, Collection<? extends C> callbackInstanc
296294
* Invoke the callback instances where the callback method returns void.
297295
* @param invoker the invoker used to invoke the callback
298296
*/
299-
// Lambda isn't detected with the correct nullability
300-
@SuppressWarnings("NullAway")
301297
public void invoke(Consumer<C> invoker) {
302-
this.callbackInstances.forEach((callbackInstance) -> invoke(callbackInstance, () -> {
303-
invoker.accept(callbackInstance);
304-
return null;
305-
}));
298+
this.callbackInstances.forEach((callbackInstance) -> {
299+
Supplier<@Nullable Void> supplier = () -> {
300+
invoker.accept(callbackInstance);
301+
return null;
302+
};
303+
invoke(callbackInstance, supplier);
304+
});
306305
}
307306

308307
/**
@@ -312,11 +311,11 @@ public void invoke(Consumer<C> invoker) {
312311
* @return the results of the invocation (may be an empty stream if no callbacks
313312
* could be called)
314313
*/
315-
// Lambda isn't detected with the correct nullability
316-
@SuppressWarnings("NullAway")
317314
public <R> Stream<R> invokeAnd(Function<C, @Nullable R> invoker) {
318-
Function<C, InvocationResult<R>> mapper = (callbackInstance) -> invoke(callbackInstance,
319-
() -> invoker.apply(callbackInstance));
315+
Function<C, InvocationResult<R>> mapper = (callbackInstance) -> {
316+
Supplier<@Nullable R> supplier = () -> invoker.apply(callbackInstance);
317+
return invoke(callbackInstance, supplier);
318+
};
320319
return this.callbackInstances.stream()
321320
.map(mapper)
322321
.filter(InvocationResult::hasResult)

module/spring-boot-http-client/src/main/java/org/springframework/boot/http/client/autoconfigure/ClientHttpRequestFactories.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ public ClientHttpRequestFactorySettings settings() {
100100
return getProperty(accessor, Function.identity(), predicate, fallback, fallbackAccessor);
101101
}
102102

103-
@SuppressWarnings("NullAway") // Lambda isn't detected with the correct nullability
104103
private <P, T, F> @Nullable T getProperty(Function<AbstractHttpRequestFactoryProperties, @Nullable P> accessor,
105104
Function<P, @Nullable T> extractor, Predicate<@Nullable T> predicate, @Nullable F fallback,
106105
Function<F, @Nullable T> fallbackAccessor) {

module/spring-boot-jdbc/src/main/java/org/springframework/boot/jdbc/metrics/DataSourcePoolMetrics.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ public void bindTo(MeterRegistry registry) {
8181
}
8282
}
8383

84-
@SuppressWarnings("NullAway") // Lambda isn't detected with the correct nullability
8584
private <N extends Number> void bindPoolMetadata(MeterRegistry registry, String metricName, String description,
8685
Function<DataSourcePoolMetadata, @Nullable N> function) {
8786
bindDataSource(registry, metricName, description, this.metadataProvider.getValueFunction(function));

module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/PropertiesMeterFilter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,21 +117,21 @@ public DistributionStatisticConfig configure(Meter.Id id, DistributionStatisticC
117117
return (value != null) ? MeterValue.valueOf(value).getValue(meterType) : null;
118118
}
119119

120-
@SuppressWarnings("NullAway") // Lambda isn't detected with the correct nullability
121120
private <T> @Nullable T lookup(Map<String, T> values, Id id, @Nullable T defaultValue) {
122121
if (values.isEmpty()) {
123122
return defaultValue;
124123
}
125-
return doLookup(values, id, () -> defaultValue);
124+
Supplier<@Nullable T> getDefaultValue = () -> defaultValue;
125+
return doLookup(values, id, getDefaultValue);
126126
}
127127

128128
@Contract("_, _, !null -> !null")
129-
@SuppressWarnings("NullAway") // Lambda isn't detected with the correct nullability
130129
private <T> @Nullable T lookupWithFallbackToAll(Map<String, T> values, Id id, @Nullable T defaultValue) {
131130
if (values.isEmpty()) {
132131
return defaultValue;
133132
}
134-
return doLookup(values, id, () -> values.getOrDefault("all", defaultValue));
133+
Supplier<@Nullable T> getAllOrDefaultValue = () -> values.getOrDefault("all", defaultValue);
134+
return doLookup(values, id, getAllOrDefaultValue);
135135
}
136136

137137
private <T> @Nullable T doLookup(Map<String, T> values, Id id, Supplier<@Nullable T> defaultValue) {

module/spring-boot-r2dbc/src/main/java/org/springframework/boot/r2dbc/autoconfigure/R2dbcAutoConfiguration.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,19 @@ public ConnectionFactoryOptions getConnectionFactoryOptions() {
8383
return optionsBuilder.build();
8484
}
8585

86-
// Lambda isn't detected with the correct nullability
87-
@SuppressWarnings("NullAway")
8886
private void configureDatabase(Builder optionsBuilder, ConnectionFactoryOptions urlOptions) {
89-
configureIf(optionsBuilder, urlOptions, ConnectionFactoryOptions.DATABASE,
90-
() -> determineDatabaseName(this.properties));
87+
Supplier<@Nullable String> getDatabaseName = () -> determineDatabaseName(this.properties);
88+
configureIf(optionsBuilder, urlOptions, ConnectionFactoryOptions.DATABASE, getDatabaseName);
9189
}
9290

93-
// Lambda isn't detected with the correct nullability
94-
@SuppressWarnings("NullAway")
9591
private void configurePassword(Builder optionsBuilder, ConnectionFactoryOptions urlOptions) {
96-
configureIf(optionsBuilder, urlOptions, ConnectionFactoryOptions.PASSWORD, this.properties::getPassword);
92+
Supplier<@Nullable CharSequence> getPassword = this.properties::getPassword;
93+
configureIf(optionsBuilder, urlOptions, ConnectionFactoryOptions.PASSWORD, getPassword);
9794
}
9895

99-
// Lambda isn't detected with the correct nullability
100-
@SuppressWarnings("NullAway")
10196
private void configureUser(Builder optionsBuilder, ConnectionFactoryOptions urlOptions) {
102-
configureIf(optionsBuilder, urlOptions, ConnectionFactoryOptions.USER, this.properties::getUsername);
97+
Supplier<@Nullable String> getUsername = this.properties::getUsername;
98+
configureIf(optionsBuilder, urlOptions, ConnectionFactoryOptions.USER, getUsername);
10399
}
104100

105101
private <T extends CharSequence> void configureIf(Builder optionsBuilder,

0 commit comments

Comments
 (0)