Skip to content

Commit 8cc0aef

Browse files
committed
Add nullability annotations to smoke-test/spring-boot-smoke-test-test
See gh-46587
1 parent 12463f9 commit 8cc0aef

File tree

10 files changed

+99
-7
lines changed

10 files changed

+99
-7
lines changed

smoke-test/spring-boot-smoke-test-test/src/main/java/smoketest/test/domain/User.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import jakarta.persistence.GeneratedValue;
2222
import jakarta.persistence.Id;
2323
import jakarta.persistence.Table;
24+
import org.jspecify.annotations.Nullable;
2425

2526
import org.springframework.util.Assert;
2627

@@ -35,11 +36,13 @@ public class User {
3536

3637
@Id
3738
@GeneratedValue
38-
private Long id;
39+
private @Nullable Long id;
3940

4041
@Column(unique = true)
42+
@SuppressWarnings("NullAway.Init")
4143
private String username;
4244

45+
@SuppressWarnings("NullAway.Init")
4346
private VehicleIdentificationNumber vin;
4447

4548
protected User() {
@@ -52,7 +55,7 @@ public User(String username, VehicleIdentificationNumber vin) {
5255
this.vin = vin;
5356
}
5457

55-
public Long getId() {
58+
public @Nullable Long getId() {
5659
return this.id;
5760
}
5861

smoke-test/spring-boot-smoke-test-test/src/main/java/smoketest/test/domain/UserRepository.java

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

1717
package smoketest.test.domain;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
import org.springframework.data.repository.Repository;
2022

2123
/**
@@ -25,6 +27,6 @@
2527
*/
2628
public interface UserRepository extends Repository<User, Long> {
2729

28-
User findByUsername(String username);
30+
@Nullable User findByUsername(String username);
2931

3032
}

smoke-test/spring-boot-smoke-test-test/src/main/java/smoketest/test/domain/VehicleIdentificationNumber.java

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

1717
package smoketest.test.domain;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
import org.springframework.util.Assert;
2022

2123
/**
@@ -34,7 +36,7 @@ public VehicleIdentificationNumber(String vin) {
3436
}
3537

3638
@Override
37-
public boolean equals(Object obj) {
39+
public boolean equals(@Nullable Object obj) {
3840
if (obj == this) {
3941
return true;
4042
}
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.test.domain;
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.test;
19+
20+
import org.jspecify.annotations.NullMarked;

smoke-test/spring-boot-smoke-test-test/src/main/java/smoketest/test/service/RemoteVehicleDetailsService.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ public VehicleDetails getVehicleDetails(VehicleIdentificationNumber vin)
4949
Assert.notNull(vin, "'vin' must not be null");
5050
logger.debug("Retrieving vehicle data for: " + vin);
5151
try {
52-
return this.restTemplate.getForObject("/vehicle/{vin}/details", VehicleDetails.class, vin);
52+
VehicleDetails response = this.restTemplate.getForObject("/vehicle/{vin}/details", VehicleDetails.class,
53+
vin);
54+
Assert.state(response != null, "'response' must not be null");
55+
return response;
5356
}
5457
catch (HttpStatusCodeException ex) {
5558
if (HttpStatus.NOT_FOUND.equals(ex.getStatusCode())) {

smoke-test/spring-boot-smoke-test-test/src/main/java/smoketest/test/service/VehicleDetails.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.fasterxml.jackson.annotation.JsonCreator;
2020
import com.fasterxml.jackson.annotation.JsonProperty;
21+
import org.jspecify.annotations.Nullable;
2122

2223
import org.springframework.util.Assert;
2324

@@ -49,7 +50,7 @@ public String getModel() {
4950
}
5051

5152
@Override
52-
public boolean equals(Object obj) {
53+
public boolean equals(@Nullable Object obj) {
5354
if (obj == this) {
5455
return true;
5556
}

smoke-test/spring-boot-smoke-test-test/src/main/java/smoketest/test/service/VehicleIdentificationNumberNotFoundException.java

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

1717
package smoketest.test.service;
1818

19+
import org.jspecify.annotations.Nullable;
1920
import smoketest.test.domain.VehicleIdentificationNumber;
2021

2122
/**
@@ -31,7 +32,7 @@ public VehicleIdentificationNumberNotFoundException(VehicleIdentificationNumber
3132
this(vin, null);
3233
}
3334

34-
public VehicleIdentificationNumberNotFoundException(VehicleIdentificationNumber vin, Throwable cause) {
35+
public VehicleIdentificationNumberNotFoundException(VehicleIdentificationNumber vin, @Nullable Throwable cause) {
3536
super("Unable to find VehicleIdentificationNumber " + vin, cause);
3637
this.vehicleIdentificationNumber = vin;
3738
}
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.test.service;
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.test.web;
19+
20+
import org.jspecify.annotations.NullMarked;

0 commit comments

Comments
 (0)