Repository navigation
Reduce cognitive complexity and remove commented code in ClassTypeMroUtils - #2318
sonarqube-agent[bot] wants to merge 1 commit into
Conversation
Fixed issues: - AaF8h6-Afx2H9N8dJgnQ for java:S125 rule - AaF-F8chCdVe95fkeBSC for java:S3776 rule Generated by SonarQube Agent (task: c65e0bc5-fea5-40c1-8ba2-a4c56259dfd0)
Code Review 👍 Approved with suggestions 0 closed / 1 findings🟢 Low risk · The union-selection loops move unchanged into a private helper, and removing commented code leaves runtime behavior and public interfaces unaffected. Extracts the nested selection-expansion loops in 💡 Quality: Removed comment was explanatory prose, not commented-out code📄 python-frontend/src/main/java/org/sonar/plugins/python/api/types/v2/ClassTypeMroUtils.java:182-183 The deleted line With that line gone, two problems remain. First, the comment now says only that Fix: put the line back. The Restore the explanatory comment line🤖 Prompt for agentsVerification Rules 1/2 metRules 1 failed 1 passed 1 not applicable
Functional validation No results Auto-approval Not enabledFor more verification details, comment OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar |
| // ClassType.mro() rejects unresolved ancestry before calling this helper. | ||
| // SuperProxyType also uses the known edges alone to reject invalid ancestry; | ||
| // the resulting partial order must not be used as a complete MRO. |
There was a problem hiding this comment.
💡 Quality: Removed comment was explanatory prose, not commented-out code
The deleted line // SuperProxyType also uses the known edges alone to reject invalid ancestry; was not commented-out code. It was the middle of a three-line explanation. It records a real caller contract: SuperProxyType.directBaseInIncompleteHierarchy() calls ClassTypeMroUtils.compute(ownerClassType) when hasUnresolvedHierarchy() is true, so here compute can see unresolved ancestry and return a partial order.
With that line gone, two problems remain. First, the comment now says only that ClassType.mro() rejects unresolved ancestry before calling this helper, which suggests the helper never gets an incomplete hierarchy. That is wrong for the SuperProxyType path. Second, the next line, "the resulting partial order must not be used as a complete MRO", no longer refers to anything. Future maintainers lose the reason why partial results are acceptable here.
Fix: put the line back. The expandSelections extraction is fine.
Restore the explanatory comment line:
// ClassType.mro() rejects unresolved ancestry before calling this helper.
// SuperProxyType also uses the known edges alone to reject invalid ancestry;
// the resulting partial order must not be used as a complete MRO.
- Apply fix
Check the box to apply the fix or reply for a change | Was this helpful? React with 👍 / 👎
This PR fixes two SonarQube issues in ClassTypeMroUtils.java: refactors the computeAlternatives method to reduce cognitive complexity from 16 to below the allowed threshold by extracting nested loops into a helper method, and removes a commented-out line flagged as dead code. These changes improve code maintainability and reduce technical debt while maintaining the same functionality.
View Project in SonarCloud
Fixed Issues
java:S3776 - Refactor this method to reduce its Cognitive Complexity from 16 to the 15 allowed. • CRITICAL • View issue
Location:
python-frontend/src/main/java/org/sonar/plugins/python/api/types/v2/ClassTypeMroUtils.java:61Why is this an issue?
Cognitive Complexity is a measure of how hard it is to understand the control flow of a unit of code. Code with high cognitive complexity is hard to read, understand, test, and modify.
What changed
Replaces the doubly nested loops in computeAlternatives with a call to the new expandSelections helper. Those nested loops sat inside the outer union loop and added +2 and +3 nesting-weighted points. Moving them out cuts the method's cognitive complexity from 16 to below the allowed 15.
java:S125 - This block of commented-out lines of code should be removed. • MAJOR • View issue
Location:
python-frontend/src/main/java/org/sonar/plugins/python/api/types/v2/ClassTypeMroUtils.java:179Why is this an issue?
Commented-out code distracts the focus from the actual executed code. It creates a noise that increases maintenance code. And because it is never executed, it quickly becomes out of date and invalid.
What changed
Deletes the comment line 'SuperProxyType also uses the known edges alone to reject invalid ancestry;'. The scanner flagged it as commented-out code, and removing it clears that warning.
SonarQube Remediation Agent uses AI. Check for mistakes.
Views of this pull request are counted to improve the agent.