Remove jspecify annotations

This commit is contained in:
Dave Syer 2025-11-26 14:22:44 +00:00
parent a9b7c6b4cd
commit 44d5f2100b
16 changed files with 102 additions and 69 deletions

View file

@ -16,8 +16,6 @@
package org.springframework.samples.petclinic; package org.springframework.samples.petclinic;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.samples.petclinic.model.BaseEntity; import org.springframework.samples.petclinic.model.BaseEntity;
@ -27,7 +25,7 @@ import org.springframework.samples.petclinic.vet.Vet;
public class PetClinicRuntimeHints implements RuntimeHintsRegistrar { public class PetClinicRuntimeHints implements RuntimeHintsRegistrar {
@Override @Override
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) { public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
hints.resources().registerPattern("db/*"); // https://github.com/spring-projects/spring-boot/issues/32654 hints.resources().registerPattern("db/*"); // https://github.com/spring-projects/spring-boot/issues/32654
hints.resources().registerPattern("messages/*"); hints.resources().registerPattern("messages/*");
hints.resources().registerPattern("mysql-default-conf"); hints.resources().registerPattern("mysql-default-conf");

View file

@ -21,7 +21,6 @@ import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType; import jakarta.persistence.GenerationType;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass; import jakarta.persistence.MappedSuperclass;
import org.jspecify.annotations.Nullable;
/** /**
* Simple JavaBean domain object with an id property. Used as a base class for objects * Simple JavaBean domain object with an id property. Used as a base class for objects
@ -35,13 +34,13 @@ public class BaseEntity implements Serializable {
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private @Nullable Integer id; private Integer id;
public @Nullable Integer getId() { public Integer getId() {
return id; return id;
} }
public void setId(@Nullable Integer id) { public void setId(Integer id) {
this.id = id; this.id = id;
} }

View file

@ -18,7 +18,6 @@ package org.springframework.samples.petclinic.model;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.MappedSuperclass; import jakarta.persistence.MappedSuperclass;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
import org.jspecify.annotations.Nullable;
/** /**
* Simple JavaBean domain object adds a name property to <code>BaseEntity</code>. Used as * Simple JavaBean domain object adds a name property to <code>BaseEntity</code>. Used as
@ -33,13 +32,13 @@ public class NamedEntity extends BaseEntity {
@Column(name = "name") @Column(name = "name")
@NotBlank @NotBlank
private @Nullable String name; private String name;
public @Nullable String getName() { public String getName() {
return this.name; return this.name;
} }
public void setName(@Nullable String name) { public void setName(String name) {
this.name = name; this.name = name;
} }

View file

@ -18,7 +18,6 @@ package org.springframework.samples.petclinic.model;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.MappedSuperclass; import jakarta.persistence.MappedSuperclass;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
import org.jspecify.annotations.Nullable;
/** /**
* Simple JavaBean domain object representing an person. * Simple JavaBean domain object representing an person.
@ -30,25 +29,25 @@ public class Person extends BaseEntity {
@Column(name = "first_name") @Column(name = "first_name")
@NotBlank @NotBlank
private @Nullable String firstName; private String firstName;
@Column(name = "last_name") @Column(name = "last_name")
@NotBlank @NotBlank
private @Nullable String lastName; private String lastName;
public @Nullable String getFirstName() { public String getFirstName() {
return this.firstName; return this.firstName;
} }
public void setFirstName(@Nullable String firstName) { public void setFirstName(String firstName) {
this.firstName = firstName; this.firstName = firstName;
} }
public @Nullable String getLastName() { public String getLastName() {
return this.lastName; return this.lastName;
} }
public void setLastName(@Nullable String lastName) { public void setLastName(String lastName) {
this.lastName = lastName; this.lastName = lastName;
} }

View file

@ -17,7 +17,4 @@
/** /**
* The classes in this package represent utilities used by the domain. * The classes in this package represent utilities used by the domain.
*/ */
@NullMarked
package org.springframework.samples.petclinic.model; package org.springframework.samples.petclinic.model;
import org.jspecify.annotations.NullMarked;

View file

@ -33,7 +33,6 @@ import jakarta.persistence.OrderBy;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import jakarta.validation.constraints.Pattern; import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
import org.jspecify.annotations.Nullable;
/** /**
* Simple JavaBean domain object representing an owner. * Simple JavaBean domain object representing an owner.
@ -51,43 +50,43 @@ public class Owner extends Person {
@Column(name = "address") @Column(name = "address")
@NotBlank @NotBlank
private @Nullable String address; private String address;
@Column(name = "city") @Column(name = "city")
@NotBlank @NotBlank
private @Nullable String city; private String city;
@Column(name = "telephone") @Column(name = "telephone")
@NotBlank @NotBlank
@Pattern(regexp = "\\d{10}", message = "{telephone.invalid}") @Pattern(regexp = "\\d{10}", message = "{telephone.invalid}")
private @Nullable String telephone; private String telephone;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "owner_id") @JoinColumn(name = "owner_id")
@OrderBy("name") @OrderBy("name")
private final List<Pet> pets = new ArrayList<>(); private final List<Pet> pets = new ArrayList<>();
public @Nullable String getAddress() { public String getAddress() {
return this.address; return this.address;
} }
public void setAddress(@Nullable String address) { public void setAddress(String address) {
this.address = address; this.address = address;
} }
public @Nullable String getCity() { public String getCity() {
return this.city; return this.city;
} }
public void setCity(@Nullable String city) { public void setCity(String city) {
this.city = city; this.city = city;
} }
public @Nullable String getTelephone() { public String getTelephone() {
return this.telephone; return this.telephone;
} }
public void setTelephone(@Nullable String telephone) { public void setTelephone(String telephone) {
this.telephone = telephone; this.telephone = telephone;
} }
@ -106,7 +105,7 @@ public class Owner extends Person {
* @param name to test * @param name to test
* @return the Pet with the given name, or null if no such Pet exists for this Owner * @return the Pet with the given name, or null if no such Pet exists for this Owner
*/ */
public @Nullable Pet getPet(String name) { public Pet getPet(String name) {
return getPet(name, false); return getPet(name, false);
} }
@ -115,7 +114,7 @@ public class Owner extends Person {
* @param id to test * @param id to test
* @return the Pet with the given id, or null if no such Pet exists for this Owner * @return the Pet with the given id, or null if no such Pet exists for this Owner
*/ */
public @Nullable Pet getPet(Integer id) { public Pet getPet(Integer id) {
for (Pet pet : getPets()) { for (Pet pet : getPets()) {
if (!pet.isNew()) { if (!pet.isNew()) {
Integer compId = pet.getId(); Integer compId = pet.getId();
@ -133,7 +132,7 @@ public class Owner extends Person {
* @param ignoreNew whether to ignore new pets (pets that are not saved yet) * @param ignoreNew whether to ignore new pets (pets that are not saved yet)
* @return the Pet with the given name, or null if no such Pet exists for this Owner * @return the Pet with the given name, or null if no such Pet exists for this Owner
*/ */
public @Nullable Pet getPet(String name, boolean ignoreNew) { public Pet getPet(String name, boolean ignoreNew) {
for (Pet pet : getPets()) { for (Pet pet : getPets()) {
String compName = pet.getName(); String compName = pet.getName();
if (compName != null && compName.equalsIgnoreCase(name)) { if (compName != null && compName.equalsIgnoreCase(name)) {

View file

@ -35,7 +35,6 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import org.jspecify.annotations.Nullable;
import org.springframework.web.servlet.mvc.support.RedirectAttributes; import org.springframework.web.servlet.mvc.support.RedirectAttributes;
@ -63,7 +62,7 @@ class OwnerController {
} }
@ModelAttribute("owner") @ModelAttribute("owner")
public Owner findOwner(@PathVariable(name = "ownerId", required = false) @Nullable Integer ownerId) { public Owner findOwner(@PathVariable(name = "ownerId", required = false) Integer ownerId) {
return ownerId == null ? new Owner() return ownerId == null ? new Owner()
: this.owners.findById(ownerId) : this.owners.findById(ownerId)
.orElseThrow(() -> new IllegalArgumentException("Owner not found with id: " + ownerId .orElseThrow(() -> new IllegalArgumentException("Owner not found with id: " + ownerId

View file

@ -32,7 +32,6 @@ import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany; import jakarta.persistence.OneToMany;
import jakarta.persistence.OrderBy; import jakarta.persistence.OrderBy;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import org.jspecify.annotations.Nullable;
/** /**
* Simple business object representing a pet. * Simple business object representing a pet.
@ -48,30 +47,30 @@ public class Pet extends NamedEntity {
@Column(name = "birth_date") @Column(name = "birth_date")
@DateTimeFormat(pattern = "yyyy-MM-dd") @DateTimeFormat(pattern = "yyyy-MM-dd")
private @Nullable LocalDate birthDate; private LocalDate birthDate;
@ManyToOne @ManyToOne
@JoinColumn(name = "type_id") @JoinColumn(name = "type_id")
private @Nullable PetType type; private PetType type;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "pet_id") @JoinColumn(name = "pet_id")
@OrderBy("date ASC") @OrderBy("date ASC")
private final Set<Visit> visits = new LinkedHashSet<>(); private final Set<Visit> visits = new LinkedHashSet<>();
public void setBirthDate(@Nullable LocalDate birthDate) { public void setBirthDate(LocalDate birthDate) {
this.birthDate = birthDate; this.birthDate = birthDate;
} }
public @Nullable LocalDate getBirthDate() { public LocalDate getBirthDate() {
return this.birthDate; return this.birthDate;
} }
public @Nullable PetType getType() { public PetType getType() {
return this.type; return this.type;
} }
public void setType(@Nullable PetType type) { public void setType(PetType type) {
this.type = type; this.type = type;
} }

View file

@ -34,7 +34,6 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import org.jspecify.annotations.Nullable;
import org.springframework.web.servlet.mvc.support.RedirectAttributes; import org.springframework.web.servlet.mvc.support.RedirectAttributes;
@ -73,8 +72,8 @@ class PetController {
} }
@ModelAttribute("pet") @ModelAttribute("pet")
public @Nullable Pet findPet(@PathVariable("ownerId") int ownerId, public Pet findPet(@PathVariable("ownerId") int ownerId,
@PathVariable(name = "petId", required = false) @Nullable Integer petId) { @PathVariable(name = "petId", required = false) Integer petId) {
if (petId == null) { if (petId == null) {
return new Pet(); return new Pet();

View file

@ -24,7 +24,6 @@ import jakarta.persistence.Column;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
import org.jspecify.annotations.Nullable;
/** /**
* Simple JavaBean domain object representing a visit. * Simple JavaBean domain object representing a visit.
@ -38,10 +37,10 @@ public class Visit extends BaseEntity {
@Column(name = "visit_date") @Column(name = "visit_date")
@DateTimeFormat(pattern = "yyyy-MM-dd") @DateTimeFormat(pattern = "yyyy-MM-dd")
private @Nullable LocalDate date; private LocalDate date;
@NotBlank @NotBlank
private @Nullable String description; private String description;
/** /**
* Creates a new instance of Visit for the current date * Creates a new instance of Visit for the current date
@ -50,19 +49,19 @@ public class Visit extends BaseEntity {
this.date = LocalDate.now(); this.date = LocalDate.now();
} }
public @Nullable LocalDate getDate() { public LocalDate getDate() {
return this.date; return this.date;
} }
public void setDate(@Nullable LocalDate date) { public void setDate(LocalDate date) {
this.date = date; this.date = date;
} }
public @Nullable String getDescription() { public String getDescription() {
return this.description; return this.description;
} }
public void setDescription(@Nullable String description) { public void setDescription(String description) {
this.description = description; this.description = description;
} }

View file

@ -1,4 +1,16 @@
@NullMarked /*
* Copyright 2012-2025 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.
*/
package org.springframework.samples.petclinic.owner; package org.springframework.samples.petclinic.owner;
import org.jspecify.annotations.NullMarked;

View file

@ -1,4 +1,16 @@
@NullMarked /*
* Copyright 2012-2025 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.
*/
package org.springframework.samples.petclinic; package org.springframework.samples.petclinic;
import org.jspecify.annotations.NullMarked;

View file

@ -1,4 +1,16 @@
@NullMarked /*
* Copyright 2012-2025 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.
*/
package org.springframework.samples.petclinic.system; package org.springframework.samples.petclinic.system;
import org.jspecify.annotations.NullMarked;

View file

@ -31,7 +31,6 @@ import jakarta.persistence.JoinTable;
import jakarta.persistence.ManyToMany; import jakarta.persistence.ManyToMany;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlElement;
import org.jspecify.annotations.Nullable;
/** /**
* Simple JavaBean domain object representing a veterinarian. * Simple JavaBean domain object representing a veterinarian.
@ -48,7 +47,7 @@ public class Vet extends Person {
@ManyToMany(fetch = FetchType.EAGER) @ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "vet_specialties", joinColumns = @JoinColumn(name = "vet_id"), @JoinTable(name = "vet_specialties", joinColumns = @JoinColumn(name = "vet_id"),
inverseJoinColumns = @JoinColumn(name = "specialty_id")) inverseJoinColumns = @JoinColumn(name = "specialty_id"))
private @Nullable Set<Specialty> specialties; private Set<Specialty> specialties;
protected Set<Specialty> getSpecialtiesInternal() { protected Set<Specialty> getSpecialtiesInternal() {
if (this.specialties == null) { if (this.specialties == null) {

View file

@ -20,7 +20,6 @@ import java.util.List;
import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlRootElement; import jakarta.xml.bind.annotation.XmlRootElement;
import org.jspecify.annotations.Nullable;
/** /**
* Simple domain object representing a list of veterinarians. Mostly here to be used for * Simple domain object representing a list of veterinarians. Mostly here to be used for
@ -31,7 +30,7 @@ import org.jspecify.annotations.Nullable;
@XmlRootElement @XmlRootElement
public class Vets { public class Vets {
private @Nullable List<Vet> vets; private List<Vet> vets;
@XmlElement @XmlElement
public List<Vet> getVetList() { public List<Vet> getVetList() {

View file

@ -1,4 +1,16 @@
@NullMarked /*
* Copyright 2012-2025 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.
*/
package org.springframework.samples.petclinic.vet; package org.springframework.samples.petclinic.vet;
import org.jspecify.annotations.NullMarked;