Skip to content

fix: Remove unreachable else-if branch in PromptChatMemoryAdvisor #3395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2025

Conversation

liqingdong
Copy link
Contributor

Problem

In the after method of PromptChatMemoryAdvisor, there was an issue with the conditional logic where the else-if branch was unreachable. The original code structure had redundant null checks and didn't properly prioritize the single-result case check.

Solution

Reordered the conditional statements to:

  1. First check for single-result case with complete null safety
  2. Then handle the multi-result case as the fallback

This approach is more efficient and maintains better null safety while handling both cases appropriately.

Changes

- if (chatClientResponse.chatResponse() != null) {
-     assistantMessages = chatClientResponse.chatResponse()
-         .getResults()
-         .stream()
-         .map(g -> (Message) g.getOutput())
-         .toList();
- }
- else if (chatClientResponse.chatResponse() != null && 
-          chatClientResponse.chatResponse().getResult() != null &&
-          chatClientResponse.chatResponse().getResult().getOutput() != null) {
-     assistantMessages = List.of((Message) chatClientResponse.chatResponse().getResult().getOutput());
- }

+ if (chatClientResponse.chatResponse() != null && 
+     chatClientResponse.chatResponse().getResult() != null &&
+     chatClientResponse.chatResponse().getResult().getOutput() != null) {
+     assistantMessages = List.of((Message) chatClientResponse.chatResponse().getResult().getOutput());
+ }
+ else if (chatClientResponse.chatResponse() != null) {
+     assistantMessages = chatClientResponse.chatResponse()
+         .getResults()
+         .stream()
+         .map(g -> (Message) g.getOutput())
+         .toList();
+ }

@ilayaperumalg
Copy link
Member

@liqingdong Thanks for fixing the conditional logic!

@sobychacko sobychacko merged commit 5010916 into spring-projects:main May 30, 2025
2 checks passed
sobychacko pushed a commit that referenced this pull request May 30, 2025
)

Fixes: #3395

Auto-cherry-pick to 1.0.x

Signed-off-by: aliqingdong <[email protected]>
Co-authored-by: aliqingdong <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants