Add nullability annotations to smoke-test/spring-boot-smoke-test-test

See gh-46587
This commit is contained in:
Moritz Halbritter 2025-08-12 11:24:30 +02:00
parent 12463f9415
commit 8cc0aef867
10 changed files with 99 additions and 7 deletions

View File

@ -21,6 +21,7 @@ import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import org.jspecify.annotations.Nullable;
import org.springframework.util.Assert;
@ -35,11 +36,13 @@ public class User {
@Id
@GeneratedValue
private Long id;
private @Nullable Long id;
@Column(unique = true)
@SuppressWarnings("NullAway.Init")
private String username;
@SuppressWarnings("NullAway.Init")
private VehicleIdentificationNumber vin;
protected User() {
@ -52,7 +55,7 @@ public class User {
this.vin = vin;
}
public Long getId() {
public @Nullable Long getId() {
return this.id;
}

View File

@ -16,6 +16,8 @@
package smoketest.test.domain;
import org.jspecify.annotations.Nullable;
import org.springframework.data.repository.Repository;
/**
@ -25,6 +27,6 @@ import org.springframework.data.repository.Repository;
*/
public interface UserRepository extends Repository<User, Long> {
User findByUsername(String username);
@Nullable User findByUsername(String username);
}

View File

@ -16,6 +16,8 @@
package smoketest.test.domain;
import org.jspecify.annotations.Nullable;
import org.springframework.util.Assert;
/**
@ -34,7 +36,7 @@ public final class VehicleIdentificationNumber {
}
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (obj == this) {
return true;
}

View File

@ -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.test.domain;
import org.jspecify.annotations.NullMarked;

View File

@ -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.test;
import org.jspecify.annotations.NullMarked;

View File

@ -49,7 +49,10 @@ public class RemoteVehicleDetailsService implements VehicleDetailsService {
Assert.notNull(vin, "'vin' must not be null");
logger.debug("Retrieving vehicle data for: " + vin);
try {
return this.restTemplate.getForObject("/vehicle/{vin}/details", VehicleDetails.class, vin);
VehicleDetails response = this.restTemplate.getForObject("/vehicle/{vin}/details", VehicleDetails.class,
vin);
Assert.state(response != null, "'response' must not be null");
return response;
}
catch (HttpStatusCodeException ex) {
if (HttpStatus.NOT_FOUND.equals(ex.getStatusCode())) {

View File

@ -18,6 +18,7 @@ package smoketest.test.service;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.jspecify.annotations.Nullable;
import org.springframework.util.Assert;
@ -49,7 +50,7 @@ public class VehicleDetails {
}
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (obj == this) {
return true;
}

View File

@ -16,6 +16,7 @@
package smoketest.test.service;
import org.jspecify.annotations.Nullable;
import smoketest.test.domain.VehicleIdentificationNumber;
/**
@ -31,7 +32,7 @@ public class VehicleIdentificationNumberNotFoundException extends RuntimeExcepti
this(vin, null);
}
public VehicleIdentificationNumberNotFoundException(VehicleIdentificationNumber vin, Throwable cause) {
public VehicleIdentificationNumberNotFoundException(VehicleIdentificationNumber vin, @Nullable Throwable cause) {
super("Unable to find VehicleIdentificationNumber " + vin, cause);
this.vehicleIdentificationNumber = vin;
}

View File

@ -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.test.service;
import org.jspecify.annotations.NullMarked;

View File

@ -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.test.web;
import org.jspecify.annotations.NullMarked;