Refactor expressions method and return empty map instead of null#370
Open
sonarqube-agent[bot] wants to merge 1 commit into
Open
Refactor expressions method and return empty map instead of null#370sonarqube-agent[bot] wants to merge 1 commit into
sonarqube-agent[bot] wants to merge 1 commit into
Conversation
Fixed issues: - AZggACbWxdvKFWvLKU5_ for java:S5738 rule - AZggACuKxdvKFWvLKU88 for java:S1168 rule - AZggADCMxdvKFWvLKVBS for java:S138 rule - AZggADD2xdvKFWvLKVBj for java:S5778 rule - AZggADD2xdvKFWvLKVBk for java:S5778 rule Generated by SonarQube Agent (task: 305f378f-5846-4114-9ae3-c3eddb2e49b5)
zglicz
approved these changes
Jun 5, 2026
zglicz
left a comment
Contributor
There was a problem hiding this comment.
Auto-approved: SonarQube automated remediation.
vdiez
approved these changes
Jun 8, 2026
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.
This PR fixes 5 SonarQube issues, including splitting an oversized 161-line method into smaller focused methods and replacing null returns with an empty map to prevent potential null pointer exceptions. These changes improve code maintainability and robustness while ensuring compliance with SonarQube code quality standards.
View Project in SonarCloud
Fixed Issues
java:S5778 - Refactor the code of the lambda to have only one invocation possibly throwing a runtime exception. • MAJOR • View issue
Location:
sonar-flex-plugin/src/test/java/org/sonar/plugins/flex/cobertura/CoberturaReportParserTest.java:31Why is this an issue?
When verifying that code raises a runtime exception, a good practice is to avoid having multiple method calls inside the tested code, to be explicit about which method call is expected to raise the exception.
What changed
Extracts the
new File("fakeFile.xml")andSensorContextTester.create(new File("."))calls out of the lambda passed toassertThrowsinto local variables. This ensures only theparseReportcall remains inside the lambda, addressing the code smell where multiple method calls inside the assertThrows lambda could each throw a runtime exception at line 42.java:S5778 - Refactor the code of the lambda to have only one invocation possibly throwing a runtime exception. • MAJOR • View issue
Location:
sonar-flex-plugin/src/test/java/org/sonar/plugins/flex/cobertura/CoberturaReportParserTest.java:42Why is this an issue?
When verifying that code raises a runtime exception, a good practice is to avoid having multiple method calls inside the tested code, to be explicit about which method call is expected to raise the exception.
What changed
Replaces the inline
new File(...)andSensorContextTester.create(new File(...))arguments with the pre-computed local variablesreportFileandcontext, so the lambda body now contains only a single invocation (CoberturaReportParser.parseReport(reportFile, context)) that could throw a runtime exception. This directly resolves the warning about having multiple potentially-throwing calls inside the assertThrows lambda at line 31, and also addresses the related code smell about refactoring the lambda to have only one invocation possibly throwing a runtime exception.java:S5738 - Remove this call to a deprecated method, it has been marked for removal. • MAJOR • View issue
Location:
flex-checks/src/test/java/org/sonar/flex/checks/CheckListTest.java:74Why is this an issue?
With the introduction of Java 9, the standard annotation class
java.lang.Deprecatedhas been updated with new parameters. Notably, a boolean parameterforRemovalhas been added to clearly signify whether the deprecated code is intended to be removed in the future. This is indicated withforRemoval=true. The javadoc of the annotation explicitly mentions the following:What changed
This hunk removes the call to
rule.setMarkdownDescription("-42"), which is a deprecated method marked for removal. The original code used this deprecated method inside a try-catch block to test whether an HTML description was already set. The fix replaces this pattern with an AssertJ assertion (assertThat(rule.markdownDescription()).isNull()) that checks the same condition without calling the deprecated-for-removal method, thus eliminating the static analysis warning about using deprecated code marked for removal.java:S1168 - Return an empty map instead of null. • MAJOR • View issue
Location:
flex-checks/src/main/java/org/sonar/flex/checks/utils/MetadataTag.java:91Why is this an issue?
Returning
nullinstead of an actual array, collection or map forces callers of the method to explicitly test for nullity, making them more complex and less readable.What changed
This hunk is a necessary companion change to the fix in MetadataTag.java where
nullis replaced with an empty map. Previously, the caller checkedproperties != nullto guard against a null return value from the method. Since the method now returns an empty map instead of null (fixing the code smell about returning null instead of an empty collection), the null check is replaced with!properties.isEmpty(), which is the appropriate way to check for an empty map. This ensures the calling code remains correct after the return-type change from null to an empty map.java:S138 - This method has 161 lines, which is greater than the 100 lines authorized. Split it into smaller methods. • MAJOR • View issue
Location:
flex-squid/src/main/java/org/sonar/flex/FlexGrammar.java:453Why is this an issue?
A method that grows too large tends to aggregate too many responsibilities. Such method inevitably become harder to understand and therefore harder to maintain.
What changed
This hunk splits the oversized
expressionsmethod (161 lines, exceeding the 100-line limit) by replacing the inline code with three delegate method calls:identifierAndPrimaryExpressions(b),assignmentAndPostfixExpressions(b), andoperatorExpressions(b). It also closes the originalexpressionsmethod and begins the definition of the first extracted helper methodidentifierAndPrimaryExpressions. This directly addresses the code smell about the method being too long by distributing its responsibilities across smaller, focused methods.SonarQube Remediation Agent uses AI. Check for mistakes.