Repository navigation
SONARJAVA-7223 Invert negated ternary conditions in OctalValuesCheck permission bits - #6387
Conversation
Code Review ✅ Approved🟢 Low risk · The three permission-bit ternaries only invert equivalent comparisons and swap branches, leaving generated permission strings unchanged. Inverts the negated Verification Rules 2/2 met PRs 1 inspectedFunctional validation No results Rules 2 passed 1 not applicable
Broader impact PRs 1 inspectedCross-PR 1 PR inspected 0 open impacts
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 |
rombirli
left a comment
There was a problem hiding this comment.
This rule already excludes ... != null conditions, it might make sense to also exclude ... != 0 conditions as well, as fixing it here doesn't improve much the code WDYT?
|




The read, write and execute permission-bit ternaries in OctalValuesCheck used negated
!=conditions, forcing readers to mentally invert each test. They now use positive==comparisons with the branches swapped, producing identical output while improving readability and clearing three SonarQube S9435 warnings.View Project in SonarQube
Fixed Issues
java:S9435 - Invert this negated condition and swap the two branches of the ternary. • MINOR • View issue 1
java:S9435 - Invert this negated condition and swap the two branches of the ternary. • MINOR • View issue 2
java:S9435 - Invert this negated condition and swap the two branches of the ternary. • MINOR • View issue 3
Location:
java:java-checks/src/main/java/org/sonar/java/checks/OctalValuesCheck.java:72Why is this an issue?
A ternary expression packs both outcomes of a choice into a single line, so the reader takes in the condition and the two results at once. When the condition is negated, that reading no longer works in one pass: the reader has to invert the condition mentally before pairing each result with the case it belongs to. In
order.status() != Status.SHIPPED ? "Pending" : "Shipped", the value that goes with "shipped" is the second one, even though shipping is what the condition talks about.What changed
All three permission-bit ternaries used a negated
!=comparison, which forces the reader to mentally invert the condition before matching each branch to its case. The hunk rewrites each one with the equivalent positive==comparison and swaps the two result expressions ((bits & 4) != 0 ? 'r' : '-'becomes(bits & 4) == 0 ? '-' : 'r', and likewise for the write and execute bits). The produced string is identical because both the condition and the branches were flipped together, and the operands are side-effect-free, so only readability changes and the negated-condition warnings on the read, write and execute ternaries are resolved.SonarQube Remediation Agent uses AI. Check for mistakes.