1919import java .io .IOException ;
2020import java .net .URI ;
2121
22+ import org .jspecify .annotations .NullMarked ;
23+ import org .jspecify .annotations .Nullable ;
24+
2225import org .springframework .core .io .Resource ;
23- import org .springframework .lang .Nullable ;
2426import org .springframework .util .Assert ;
2527import org .springframework .util .MimeType ;
2628
6769 * @author Thomas Vitale
6870 * @since 1.0.0
6971 */
72+ @ NullMarked
7073public class Media {
7174
7275 private static final String NAME_PREFIX = "media-" ;
@@ -75,8 +78,7 @@ public class Media {
7578 * An Id of the media object, usually defined when the model returns a reference to
7679 * media it has been passed.
7780 */
78- @ Nullable
79- private final String id ;
81+ private final @ Nullable String id ;
8082
8183 private final MimeType mimeType ;
8284
@@ -195,8 +197,7 @@ public byte[] getDataAsByteArray() {
195197 * Get the media id
196198 * @return the media id
197199 */
198- @ Nullable
199- public String getId () {
200+ public @ Nullable String getId () {
200201 return this .id ;
201202 }
202203
@@ -209,13 +210,13 @@ public String getName() {
209210 */
210211 public static final class Builder {
211212
212- private String id ;
213+ private @ Nullable String id ;
213214
214- private MimeType mimeType ;
215+ private @ Nullable MimeType mimeType ;
215216
216- private Object data ;
217+ private @ Nullable Object data ;
217218
218- private String name ;
219+ private @ Nullable String name ;
219220
220221 private Builder () {
221222 }
@@ -315,6 +316,8 @@ public Builder name(String name) {
315316 * @throws IllegalArgumentException if mimeType or data are null
316317 */
317318 public Media build () {
319+ Assert .state (this .mimeType != null , "MimeType must not be null" );
320+ Assert .state (this .data != null , "Data must not be null" );
318321 return new Media (this .mimeType , this .data , this .id , this .name );
319322 }
320323
0 commit comments