Skip to content

Commit cbba9f1

Browse files
committed
Fix(advisor) : Prevent NPE when conversation ID value is null
- Replace containsKey(..) + toString() with direct get(..) and null check - Change Assert.noNullElements(keySet().toArray()) to Assert.state(!containsKey(null)) to avoid unnecessary array allocation Signed-off-by: KoreaNirsa <[email protected]>
1 parent d662e57 commit cbba9f1

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

spring-ai-client-chat/src/main/java/org/springframework/ai/chat/client/advisor/api/BaseChatMemoryAdvisor.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ public interface BaseChatMemoryAdvisor extends BaseAdvisor {
3636
*/
3737
default String getConversationId(Map<String, Object> context, String defaultConversationId) {
3838
Assert.notNull(context, "context cannot be null");
39-
Assert.noNullElements(context.keySet().toArray(), "context cannot contain null keys");
39+
Assert.state(!context.containsKey(null), "context cannot contain null keys");
4040
Assert.hasText(defaultConversationId, "defaultConversationId cannot be null or empty");
41-
return context.containsKey(ChatMemory.CONVERSATION_ID) ? context.get(ChatMemory.CONVERSATION_ID).toString()
42-
: defaultConversationId;
41+
42+
Object value = context.get(ChatMemory.CONVERSATION_ID);
43+
return (value != null) ? value.toString() : defaultConversationId;
4344
}
4445

4546
}

0 commit comments

Comments
 (0)