Skip to content

fix: remove unreachable null checks flagged by Sonar (S2583) - #1755

Merged
igordayen merged 2 commits into
embabel:mainfrom
azanux:fix/sonar-s2583-dead-null-checks
Jul 2, 2026
Merged

fix: remove unreachable null checks flagged by Sonar (S2583)#1755
igordayen merged 2 commits into
embabel:mainfrom
azanux:fix/sonar-s2583-dead-null-checks

Conversation

@azanux

@azanux azanux commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Remove unreachable null checks flagged by Sonar (S2583)

Summary

  • SonarCloud flagged 3 dead-code null checks under rule java:S2583 ("condition always evaluates to false") on the new-code leak period.
  • ChatModelObservationFilter.buildInputMessages / extractPrompt: chatContext.getRequest() is guaranteed non-null by Spring AI's ChatModelObservationContext contract, so the if (request == null) guards were unreachable.
  • ObservationUtils.formatMessages: Message.role is a non-nullable Kotlin val, so the m.getRole() == null check was unreachable.
  • No behavior change — these were defensive checks against conditions that can't occur given the current contracts.

Test plan

  • mvn -pl embabel-agent-observability -am compile -DskipTests
  • mvn -pl embabel-agent-observability test -Dtest=ChatModelObservationFilterTest,ObservationUtilsTest
Request and Message.role are guaranteed non-null by their respective contracts (Spring AI's ChatModelObservationContext and Kotlin's Message.role), making these defensive checks dead code.

Signed-off-by: Charles <azanux@gmail.com>

@igordayen igordayen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all good, except UnfoldingToolInjectionStrategy, just extra line?

@azanux

azanux commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

For the space, I don’t think it was done on purpose. Maybe I was trying to remove something in another file, and the cursor happened to be focused on this file.
Will see if I can revert

Signed-off-by: Charles <azanux@gmail.com>
@azanux

azanux commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

@igordayen revert done

@igordayen
igordayen merged commit 695e727 into embabel:main Jul 2, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants