diff --git a/smoke-test/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/InMemoryMessageRepository.java b/smoke-test/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/InMemoryMessageRepository.java index b3f94e53ce7..bd5368c4856 100644 --- a/smoke-test/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/InMemoryMessageRepository.java +++ b/smoke-test/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/InMemoryMessageRepository.java @@ -20,6 +20,8 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.atomic.AtomicLong; +import org.jspecify.annotations.Nullable; + public class InMemoryMessageRepository implements MessageRepository { private static final AtomicLong counter = new AtomicLong(); @@ -43,7 +45,7 @@ public class InMemoryMessageRepository implements MessageRepository { } @Override - public Message findMessage(Long id) { + public @Nullable Message findMessage(Long id) { return this.messages.get(id); } diff --git a/smoke-test/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/Message.java b/smoke-test/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/Message.java index fd8a796c120..e38727dfc67 100644 --- a/smoke-test/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/Message.java +++ b/smoke-test/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/Message.java @@ -19,24 +19,25 @@ package smoketest.groovytemplates; import java.util.Date; import jakarta.validation.constraints.NotEmpty; +import org.jspecify.annotations.Nullable; public class Message { - private Long id; + private @Nullable Long id; @NotEmpty(message = "Text is required.") - private String text; + private @Nullable String text; @NotEmpty(message = "Summary is required.") - private String summary; + private @Nullable String summary; private Date created = new Date(); - public Long getId() { + public @Nullable Long getId() { return this.id; } - public void setId(Long id) { + public void setId(@Nullable Long id) { this.id = id; } @@ -48,19 +49,19 @@ public class Message { this.created = created; } - public String getText() { + public @Nullable String getText() { return this.text; } - public void setText(String text) { + public void setText(@Nullable String text) { this.text = text; } - public String getSummary() { + public @Nullable String getSummary() { return this.summary; } - public void setSummary(String summary) { + public void setSummary(@Nullable String summary) { this.summary = summary; } diff --git a/smoke-test/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/MessageRepository.java b/smoke-test/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/MessageRepository.java index b602690c035..511b441a076 100644 --- a/smoke-test/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/MessageRepository.java +++ b/smoke-test/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/MessageRepository.java @@ -16,12 +16,14 @@ package smoketest.groovytemplates; +import org.jspecify.annotations.Nullable; + public interface MessageRepository { Iterable findAll(); Message save(Message message); - Message findMessage(Long id); + @Nullable Message findMessage(Long id); } diff --git a/smoke-test/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/SampleGroovyTemplateApplication.java b/smoke-test/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/SampleGroovyTemplateApplication.java index ae3613e4d6a..ca7a9aaef97 100644 --- a/smoke-test/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/SampleGroovyTemplateApplication.java +++ b/smoke-test/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/SampleGroovyTemplateApplication.java @@ -16,6 +16,8 @@ package smoketest.groovytemplates; +import org.jspecify.annotations.Nullable; + import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; @@ -33,7 +35,7 @@ public class SampleGroovyTemplateApplication { public Converter messageConverter() { return new Converter<>() { @Override - public Message convert(String id) { + public @Nullable Message convert(String id) { return messageRepository().findMessage(Long.valueOf(id)); } }; diff --git a/smoke-test/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/mvc/MessageController.java b/smoke-test/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/mvc/MessageController.java index 8741092b064..c53820b83e8 100644 --- a/smoke-test/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/mvc/MessageController.java +++ b/smoke-test/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/mvc/MessageController.java @@ -24,6 +24,7 @@ import smoketest.groovytemplates.Message; import smoketest.groovytemplates.MessageRepository; import org.springframework.stereotype.Controller; +import org.springframework.util.Assert; import org.springframework.validation.BindingResult; import org.springframework.validation.FieldError; import org.springframework.validation.ObjectError; @@ -71,7 +72,9 @@ public class MessageController { } message = this.messageRepository.save(message); redirect.addFlashAttribute("globalMessage", "Successfully created a new message"); - return new ModelAndView("redirect:/{message.id}", "message.id", message.getId()); + Long id = message.getId(); + Assert.state(id != null, "'id' must not be null"); + return new ModelAndView("redirect:/{message.id}", "message.id", id); } private Map getFieldErrors(BindingResult result) { diff --git a/smoke-test/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/mvc/package-info.java b/smoke-test/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/mvc/package-info.java new file mode 100644 index 00000000000..22624e56d3f --- /dev/null +++ b/smoke-test/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/mvc/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.groovytemplates.mvc; + +import org.jspecify.annotations.NullMarked; diff --git a/smoke-test/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/package-info.java b/smoke-test/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/package-info.java new file mode 100644 index 00000000000..2783db04484 --- /dev/null +++ b/smoke-test/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/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.groovytemplates; + +import org.jspecify.annotations.NullMarked;