From 52be1bcb4c046f60a15f95f1d0ca9399d8529823 Mon Sep 17 00:00:00 2001 From: Fu Cheng Date: Thu, 6 Jun 2024 09:02:30 +0800 Subject: [PATCH] Fix potential NPE using nullSafeList --- .../springframework/ai/azure/openai/AzureOpenAiChatModel.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/models/spring-ai-azure-openai/src/main/java/org/springframework/ai/azure/openai/AzureOpenAiChatModel.java b/models/spring-ai-azure-openai/src/main/java/org/springframework/ai/azure/openai/AzureOpenAiChatModel.java index 9ac782f6c..f1d2a06c0 100644 --- a/models/spring-ai-azure-openai/src/main/java/org/springframework/ai/azure/openai/AzureOpenAiChatModel.java +++ b/models/spring-ai-azure-openai/src/main/java/org/springframework/ai/azure/openai/AzureOpenAiChatModel.java @@ -143,8 +143,7 @@ public class AzureOpenAiChatModel ChatCompletions chatCompletions = this.callWithFunctionSupport(options); logger.trace("Azure ChatCompletions: {}", chatCompletions); - List generations = chatCompletions.getChoices() - .stream() + List generations = nullSafeList(chatCompletions.getChoices()).stream() .map(choice -> new Generation(choice.getMessage().getContent()) .withGenerationMetadata(generateChoiceMetadata(choice))) .toList();