Skip to content

Commit b84f34c

Browse files
committed
Remove @Nullable on local variables
>> `@Nullable` and `@NonNull` aren't applied to local variables—at least not their root types. (They should be applied to type arguments and array components.) The reason is that it is possible to infer whether a variable can be null based on the values that are assigned to the variable. Signed-off-by: Yanming Zhou <zhouyanming@gmail.com>
1 parent fd2e1d2 commit b84f34c

6 files changed

Lines changed: 7 additions & 10 deletions

File tree

module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/autoconfigure/jsontest/app/ExampleJacksonComponent.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.util.Date;
2020
import java.util.UUID;
2121

22-
import org.jspecify.annotations.Nullable;
2322
import tools.jackson.core.JsonGenerator;
2423
import tools.jackson.core.JsonParser;
2524
import tools.jackson.databind.DeserializationContext;
@@ -45,11 +44,11 @@ static class Serializer extends ObjectValueSerializer<ExampleCustomObject> {
4544
@Override
4645
protected void serializeObject(ExampleCustomObject value, JsonGenerator jgen, SerializationContext context) {
4746
jgen.writeStringProperty("value", value.value());
48-
@Nullable Date date = value.date();
47+
Date date = value.date();
4948
if (date != null) {
5049
jgen.writeNumberProperty("date", date.getTime());
5150
}
52-
@Nullable UUID uuid = value.uuid();
51+
UUID uuid = value.uuid();
5352
if (uuid != null) {
5453
jgen.writeStringProperty("uuid", uuid.toString());
5554
}

module/spring-boot-jpa/src/main/java/org/springframework/boot/jpa/autoconfigure/JpaBaseConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public EntityManagerFactoryBuilder entityManagerFactoryBuilder(JpaVendorAdapter
125125
ObjectProvider<PersistenceUnitManager> persistenceUnitManager,
126126
ObjectProvider<EntityManagerFactoryBuilderCustomizer> customizers,
127127
Map<String, AsyncTaskExecutor> taskExecutors) {
128-
@Nullable AsyncTaskExecutor bootstrapExecutor = determineBootstrapExecutor(taskExecutors);
128+
AsyncTaskExecutor bootstrapExecutor = determineBootstrapExecutor(taskExecutors);
129129
EntityManagerFactoryBuilder builder = new EntityManagerFactoryBuilder(jpaVendorAdapter,
130130
this::buildJpaProperties, persistenceUnitManager.getIfAvailable(), null, bootstrapExecutor);
131131
if (this.properties.getBootstrap() == Bootstrap.ASYNC) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public DistributionStatisticConfig configure(Meter.Id id, DistributionStatisticC
125125
if (values.isEmpty()) {
126126
return defaultValue;
127127
}
128-
@Nullable T result = doLookup(values, id);
128+
T result = doLookup(values, id);
129129
return (result != null) ? result : values.getOrDefault("all", defaultValue);
130130
}
131131

module/spring-boot-security-saml2/src/main/java/org/springframework/boot/security/saml2/autoconfigure/Saml2RelyingPartyRegistrationConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private RelyingPartyRegistration asRegistration(String id, Registration properti
107107
.forEach(credentials::add)));
108108
builder.singleLogoutServiceLocation(properties.getSinglelogout().getUrl());
109109
builder.singleLogoutServiceResponseLocation(properties.getSinglelogout().getResponseUrl());
110-
@Nullable Saml2MessageBinding binding = properties.getSinglelogout().getBinding();
110+
Saml2MessageBinding binding = properties.getSinglelogout().getBinding();
111111
if (binding != null) {
112112
builder.singleLogoutServiceBinding(binding);
113113
}

smoke-test/spring-boot-smoke-test-integration/src/test/java/smoketest/integration/producer/ProducerApplication.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.io.File;
2020
import java.io.FileOutputStream;
2121

22-
import org.jspecify.annotations.Nullable;
2322
import smoketest.integration.ServiceProperties;
2423

2524
import org.springframework.boot.ApplicationArguments;
@@ -41,7 +40,7 @@ public ProducerApplication(ServiceProperties serviceProperties) {
4140

4241
@Override
4342
public void run(ApplicationArguments args) throws Exception {
44-
@Nullable File inputDir = this.serviceProperties.getInputDir();
43+
File inputDir = this.serviceProperties.getInputDir();
4544
Assert.notNull(inputDir, "No inputDir configured");
4645
inputDir.mkdirs();
4746
if (!args.getNonOptionArgs().isEmpty()) {

smoke-test/spring-boot-smoke-test-parent-context/src/test/java/smoketest/parent/producer/ProducerApplication.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.io.File;
2020
import java.io.FileOutputStream;
2121

22-
import org.jspecify.annotations.Nullable;
2322
import smoketest.parent.ServiceProperties;
2423

2524
import org.springframework.boot.ApplicationArguments;
@@ -41,7 +40,7 @@ public ProducerApplication(ServiceProperties serviceProperties) {
4140

4241
@Override
4342
public void run(ApplicationArguments args) throws Exception {
44-
@Nullable File inputDir = this.serviceProperties.getInputDir();
43+
File inputDir = this.serviceProperties.getInputDir();
4544
Assert.notNull(inputDir, "No inputDir configured");
4645
inputDir.mkdirs();
4746
if (!args.getNonOptionArgs().isEmpty()) {

0 commit comments

Comments
 (0)