From 7616ed52ee045d548ab0bd66589ee9ec43d5e0ee Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Tue, 12 Aug 2025 11:01:09 +0200 Subject: [PATCH] Add nullability annotations to smoke-test/spring-boot-smoke-test-parent-context See gh-46587 --- .../SampleParentContextApplication.java | 10 ++++++++-- .../smoketest/parent/ServiceProperties.java | 14 +++++++------ .../java/smoketest/parent/package-info.java | 20 +++++++++++++++++++ 3 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 smoke-test/spring-boot-smoke-test-parent-context/src/main/java/smoketest/parent/package-info.java diff --git a/smoke-test/spring-boot-smoke-test-parent-context/src/main/java/smoketest/parent/SampleParentContextApplication.java b/smoke-test/spring-boot-smoke-test-parent-context/src/main/java/smoketest/parent/SampleParentContextApplication.java index 7e69b3971c6..a9201db9b49 100644 --- a/smoke-test/spring-boot-smoke-test-parent-context/src/main/java/smoketest/parent/SampleParentContextApplication.java +++ b/smoke-test/spring-boot-smoke-test-parent-context/src/main/java/smoketest/parent/SampleParentContextApplication.java @@ -16,6 +16,7 @@ package smoketest.parent; +import java.io.File; import java.util.function.Consumer; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -29,6 +30,7 @@ import org.springframework.integration.dsl.Pollers; import org.springframework.integration.dsl.SourcePollingChannelAdapterSpec; import org.springframework.integration.file.FileReadingMessageSource; import org.springframework.integration.file.FileWritingMessageHandler; +import org.springframework.util.Assert; @SpringBootApplication public class SampleParentContextApplication { @@ -50,7 +52,9 @@ public class SampleParentContextApplication { @Bean public FileReadingMessageSource fileReader() { FileReadingMessageSource reader = new FileReadingMessageSource(); - reader.setDirectory(this.serviceProperties.getInputDir()); + File inputDir = this.serviceProperties.getInputDir(); + Assert.state(inputDir != null, "'inputDir' must not be null"); + reader.setDirectory(inputDir); return reader; } @@ -66,7 +70,9 @@ public class SampleParentContextApplication { @Bean public FileWritingMessageHandler fileWriter() { - FileWritingMessageHandler writer = new FileWritingMessageHandler(this.serviceProperties.getOutputDir()); + File outputDir = this.serviceProperties.getOutputDir(); + Assert.state(outputDir != null, "'outputDir' must not be null"); + FileWritingMessageHandler writer = new FileWritingMessageHandler(outputDir); writer.setExpectReply(false); return writer; } diff --git a/smoke-test/spring-boot-smoke-test-parent-context/src/main/java/smoketest/parent/ServiceProperties.java b/smoke-test/spring-boot-smoke-test-parent-context/src/main/java/smoketest/parent/ServiceProperties.java index 9ec8afdac22..d777084161b 100644 --- a/smoke-test/spring-boot-smoke-test-parent-context/src/main/java/smoketest/parent/ServiceProperties.java +++ b/smoke-test/spring-boot-smoke-test-parent-context/src/main/java/smoketest/parent/ServiceProperties.java @@ -18,6 +18,8 @@ package smoketest.parent; import java.io.File; +import org.jspecify.annotations.Nullable; + import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.jmx.export.annotation.ManagedAttribute; import org.springframework.jmx.export.annotation.ManagedResource; @@ -28,9 +30,9 @@ public class ServiceProperties { private String greeting = "Hello"; - private File inputDir; + private @Nullable File inputDir; - private File outputDir; + private @Nullable File outputDir; @ManagedAttribute public String getGreeting() { @@ -41,19 +43,19 @@ public class ServiceProperties { this.greeting = greeting; } - public File getInputDir() { + public @Nullable File getInputDir() { return this.inputDir; } - public void setInputDir(File inputDir) { + public void setInputDir(@Nullable File inputDir) { this.inputDir = inputDir; } - public File getOutputDir() { + public @Nullable File getOutputDir() { return this.outputDir; } - public void setOutputDir(File outputDir) { + public void setOutputDir(@Nullable File outputDir) { this.outputDir = outputDir; } diff --git a/smoke-test/spring-boot-smoke-test-parent-context/src/main/java/smoketest/parent/package-info.java b/smoke-test/spring-boot-smoke-test-parent-context/src/main/java/smoketest/parent/package-info.java new file mode 100644 index 00000000000..2b1ed750fbe --- /dev/null +++ b/smoke-test/spring-boot-smoke-test-parent-context/src/main/java/smoketest/parent/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@NullMarked +package smoketest.parent; + +import org.jspecify.annotations.NullMarked;