Skip to content

Commit c42a2fc

Browse files
committed
fix(ChatMessage): restore IllegalArgumentException on null parts list
Commit f97c85d (spotbugs RCN cleanup) removed the null branch inside requireNonEmpty under the assumption that the JSpecify @nonnull default made parts==null unreachable. The deliberately type-cast call site in MultimodalMessagesTest.nullPartsListIsRejected bypasses that static check at compile time, so the runtime path now NPEs inside requireNonEmpty(parts).isEmpty() instead of throwing the documented IllegalArgumentException. Restore the contract by validating null at the public-constructor boundary (the right place for external-input validation) and keep the private requireNonEmpty focused on the empty case.
1 parent 647f517 commit c42a2fc

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/main/java/net/ladenthin/llama/ChatMessage.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,19 @@ public ChatMessage(String role, String content, @Nullable String toolCallId, Lis
7777
public ChatMessage(String role, List<ContentPart> parts) {
7878
this(
7979
role,
80-
concatText(parts),
80+
concatText(requireNonNull(parts)),
8181
null,
8282
Collections.<ToolCall>emptyList(),
8383
Collections.unmodifiableList(new java.util.ArrayList<ContentPart>(requireNonEmpty(parts))));
8484
}
8585

86+
private static List<ContentPart> requireNonNull(List<ContentPart> parts) {
87+
if (parts == null) {
88+
throw new IllegalArgumentException("parts must not be null");
89+
}
90+
return parts;
91+
}
92+
8693
private ChatMessage(
8794
String role,
8895
String content,

0 commit comments

Comments
 (0)