Handle null expectedMessage in InternalCheckVerifier - #6098
Open
sonarqube-agent[bot] wants to merge 1 commit into
Open
Handle null expectedMessage in InternalCheckVerifier#6098sonarqube-agent[bot] wants to merge 1 commit into
sonarqube-agent[bot] wants to merge 1 commit into
Conversation
Fixed issues: - AaCEbOLk_eQqzseR3v2f for javabugs:S2259 rule Generated by SonarQube Agent (task: 16a84c0a-d30c-41f7-8c1e-ddab96b40a84)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixed a potential NullPointerException in InternalCheckVerifier that occurred when expectedMessage was null and .equals() was called directly on it. By using Objects.equals() instead, the code now safely handles null values without throwing an exception.
View Project in SonarCloud
Fixed Issues
javabugs:S2259 - Fix this access that will throw a NullPointerException when executed. • MAJOR • View issue
Location:
java:java-checks-testkit/src/main/java/org/sonar/java/checks/verifier/internal/InternalCheckVerifier.java:407Why is this an issue?
A reference to
nullshould never be dereferenced/accessed. Doing so will cause aNullPointerExceptionto be thrown. At best, such an exception will cause abrupt program termination. At worst, it could expose debugging information that would be useful to an attacker, or it could allow an attacker to bypass security measures.What changed
This hunk fixes a potential NullPointerException that occurs when
expectedMessageis null and.equals()is called on it. The variableexpectedMessageis assigned fromexpectations.expectedFileIssue(), which can return null. The original codeexpectedMessage.equals(issue.getMessage())would throw a NullPointerException whenexpectedMessageis null. By replacing it withObjects.equals(expectedMessage, issue.getMessage()), the code safely handles null values for either argument without throwing an exception.SonarQube Remediation Agent uses AI. Check for mistakes.