Skip to content

Commit 118cf3a

Browse files
committed
Add nullability annotations to smoke-test/spring-boot-smoke-test-web-groovy-templates
See gh-46587
1 parent 7810de8 commit 118cf3a

File tree

7 files changed

+63
-13
lines changed

7 files changed

+63
-13
lines changed

smoke-test/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/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-groovy-templates/src/main/java/smoketest/groovytemplates/Message.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,25 @@
1919
import java.util.Date;
2020

2121
import jakarta.validation.constraints.NotEmpty;
22+
import org.jspecify.annotations.Nullable;
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 Date created = new Date();
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(Date 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-groovy-templates/src/main/java/smoketest/groovytemplates/MessageRepository.java

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

1717
package smoketest.groovytemplates;
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
}

smoke-test/spring-boot-smoke-test-web-groovy-templates/src/main/java/smoketest/groovytemplates/SampleGroovyTemplateApplication.java

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

1717
package smoketest.groovytemplates;
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-groovy-templates/src/main/java/smoketest/groovytemplates/mvc/MessageController.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import smoketest.groovytemplates.MessageRepository;
2525

2626
import org.springframework.stereotype.Controller;
27+
import org.springframework.util.Assert;
2728
import org.springframework.validation.BindingResult;
2829
import org.springframework.validation.FieldError;
2930
import org.springframework.validation.ObjectError;
@@ -71,7 +72,9 @@ public ModelAndView create(@Valid Message message, BindingResult result, Redirec
7172
}
7273
message = this.messageRepository.save(message);
7374
redirect.addFlashAttribute("globalMessage", "Successfully created a new message");
74-
return new ModelAndView("redirect:/{message.id}", "message.id", message.getId());
75+
Long id = message.getId();
76+
Assert.state(id != null, "'id' must not be null");
77+
return new ModelAndView("redirect:/{message.id}", "message.id", id);
7578
}
7679

7780
private Map<String, ObjectError> getFieldErrors(BindingResult result) {
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.groovytemplates.mvc;
19+
20+
import org.jspecify.annotations.NullMarked;
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.groovytemplates;
19+
20+
import org.jspecify.annotations.NullMarked;

0 commit comments

Comments
 (0)