Skip to content

Commit 5ffc0e2

Browse files
committed
Start introducing JSpecify
Signed-off-by: Eric Bottard <[email protected]>
1 parent c430a00 commit 5ffc0e2

File tree

1 file changed

+12
-9
lines changed
  • spring-ai-commons/src/main/java/org/springframework/ai/content

1 file changed

+12
-9
lines changed

spring-ai-commons/src/main/java/org/springframework/ai/content/Media.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
import java.io.IOException;
2020
import java.net.URI;
2121

22+
import org.jspecify.annotations.NullMarked;
23+
import org.jspecify.annotations.Nullable;
24+
2225
import org.springframework.core.io.Resource;
23-
import org.springframework.lang.Nullable;
2426
import org.springframework.util.Assert;
2527
import org.springframework.util.MimeType;
2628

@@ -67,6 +69,7 @@
6769
* @author Thomas Vitale
6870
* @since 1.0.0
6971
*/
72+
@NullMarked
7073
public 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

Comments
 (0)