Skip to content

Commit 31d8faa

Browse files
committed
Add nullability annotations to smoke-test/spring-boot-smoke-test-web-thymeleaf
See gh-46587
1 parent e94cee4 commit 31d8faa

File tree

7 files changed

+63
-13
lines changed

7 files changed

+63
-13
lines changed

smoke-test/spring-boot-smoke-test-web-thymeleaf/src/main/java/smoketest/web/thymeleaf/InMemoryMessageRepository.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.util.concurrent.ConcurrentMap;
2121
import java.util.concurrent.atomic.AtomicLong;
2222

23+
import org.jspecify.annotations.Nullable;
24+
2325
public class InMemoryMessageRepository implements MessageRepository {
2426

2527
private static final AtomicLong counter = new AtomicLong();
@@ -43,7 +45,7 @@ public Message save(Message message) {
4345
}
4446

4547
@Override
46-
public Message findMessage(Long id) {
48+
public @Nullable Message findMessage(Long id) {
4749
return this.messages.get(id);
4850
}
4951

smoke-test/spring-boot-smoke-test-web-thymeleaf/src/main/java/smoketest/web/thymeleaf/Message.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,26 @@
1818

1919
import java.util.Calendar;
2020

21+
import jakarta.annotation.Nullable;
2122
import jakarta.validation.constraints.NotEmpty;
2223

2324
public class Message {
2425

25-
private Long id;
26+
private @Nullable Long id;
2627

2728
@NotEmpty(message = "Text is required.")
28-
private String text;
29+
private @Nullable String text;
2930

3031
@NotEmpty(message = "Summary is required.")
31-
private String summary;
32+
private @Nullable String summary;
3233

3334
private Calendar created = Calendar.getInstance();
3435

35-
public Long getId() {
36+
public @Nullable Long getId() {
3637
return this.id;
3738
}
3839

39-
public void setId(Long id) {
40+
public void setId(@Nullable Long id) {
4041
this.id = id;
4142
}
4243

@@ -48,19 +49,19 @@ public void setCreated(Calendar created) {
4849
this.created = created;
4950
}
5051

51-
public String getText() {
52+
public @Nullable String getText() {
5253
return this.text;
5354
}
5455

55-
public void setText(String text) {
56+
public void setText(@Nullable String text) {
5657
this.text = text;
5758
}
5859

59-
public String getSummary() {
60+
public @Nullable String getSummary() {
6061
return this.summary;
6162
}
6263

63-
public void setSummary(String summary) {
64+
public void setSummary(@Nullable String summary) {
6465
this.summary = summary;
6566
}
6667

smoke-test/spring-boot-smoke-test-web-thymeleaf/src/main/java/smoketest/web/thymeleaf/MessageRepository.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616

1717
package smoketest.web.thymeleaf;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
public interface MessageRepository {
2022

2123
Iterable<Message> findAll();
2224

2325
Message save(Message message);
2426

25-
Message findMessage(Long id);
27+
@Nullable Message findMessage(Long id);
2628

2729
void deleteMessage(Long id);
2830

smoke-test/spring-boot-smoke-test-web-thymeleaf/src/main/java/smoketest/web/thymeleaf/SampleWebUiApplication.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package smoketest.web.thymeleaf;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
import org.springframework.boot.SpringApplication;
2022
import org.springframework.boot.autoconfigure.SpringBootApplication;
2123
import org.springframework.context.annotation.Bean;
@@ -33,7 +35,7 @@ public MessageRepository messageRepository() {
3335
public Converter<String, Message> messageConverter() {
3436
return new Converter<>() {
3537
@Override
36-
public Message convert(String id) {
38+
public @Nullable Message convert(String id) {
3739
return messageRepository().findMessage(Long.valueOf(id));
3840
}
3941
};

smoke-test/spring-boot-smoke-test-web-thymeleaf/src/main/java/smoketest/web/thymeleaf/mvc/MessageController.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import smoketest.web.thymeleaf.MessageRepository;
2222

2323
import org.springframework.stereotype.Controller;
24+
import org.springframework.util.Assert;
2425
import org.springframework.validation.BindingResult;
2526
import org.springframework.web.bind.annotation.GetMapping;
2627
import org.springframework.web.bind.annotation.ModelAttribute;
@@ -63,7 +64,9 @@ public ModelAndView create(@Valid Message message, BindingResult result, Redirec
6364
}
6465
message = this.messageRepository.save(message);
6566
redirect.addFlashAttribute("globalMessage", "view.success");
66-
return new ModelAndView("redirect:/{message.id}", "message.id", message.getId());
67+
Long id = message.getId();
68+
Assert.state(id != null, "'id' must not be null");
69+
return new ModelAndView("redirect:/{message.id}", "message.id", id);
6770
}
6871

6972
@RequestMapping("foo")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
@NullMarked
18+
package smoketest.web.thymeleaf.mvc;
19+
20+
import org.jspecify.annotations.NullMarked;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
@NullMarked
18+
package smoketest.web.thymeleaf;
19+
20+
import org.jspecify.annotations.NullMarked;

0 commit comments

Comments
 (0)