Repository navigation
SONARJAVA-7151: S1314: Ignore short octal literals and common permission patterns - #6327
Conversation
…on patterns Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
… in the issue message Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Suggested RSPEC change for S1314 (not applied to the generated HTML in this PR)The implementation now:
Proposed update to the rule description in RSPEC: <h2>Why is this an issue?</h2>
<p>Integer literals starting with a zero are octal rather than decimal values. While using octal values is fully supported, most developers do not
have experience with them. They may not recognize octal values as such, mistaking them instead for decimal values.</p>
<p>This rule does not raise issues on:</p>
<ul>
<li>single-digit octal literals such as <code>00</code> or <code>07</code>, whose value is the same in decimal,</li>
<li>common Unix file permission modes such as <code>0644</code>, <code>0755</code> or <code>04755</code>,</li>
<li>octal literals written with the <code>0_</code> prefix, such as <code>0_13</code>, which makes the intent explicit.</li>
</ul>
<h2>How to fix it</h2>
<p>Use the decimal value instead. If an octal value is really intended, use the <code>0_</code> prefix, which makes it clear to readers
that the literal is octal.</p>
<h3>Noncompliant code example</h3>
<pre>
int myNumber = 010; // Noncompliant. myNumber will hold 8, not 10 - was this really expected?
</pre>
<h3>Compliant solution</h3>
<pre>
int myNumber = 8;
</pre>
<p>or, if octal is intended:</p>
<pre>
int myNumber = 0_10;
</pre>
<h2>Resources</h2>
<!-- unchanged -->The issue message in RSPEC metadata (if documented) should become: |
…olic permission string Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…on-mode message Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
/pvf |
There was a problem hiding this comment.
NIT: I know this file existed before you touched to this rule, but in general we prefer to suffix reproducer files with "Sample", this PR could be a good opportunity to rename it
|
|
|
/pvf |
|
|
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Code Review ✅ Approved 2 closed / 2 findings🟡 Medium risk · Adding S1314 to Sonar way and changing its octal detection and messages could alter issue reports and suggested fixes across Java projects. Refines S1314 ( ✅ 2 closed✅ Edge Case: Underscore-separated octal literals bypass the new exemptions
✅ Quality: PR description still says permission modes are no longer reported
Verification Rules 1/1 met Repos 3 inspectedFunctional validation No results Rules 1 passed 2 not applicable
Broader impact Repos 3 inspectedCross-repo 3 repositories 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 |
|
/pvf S1314 |
|
|
|




Summary
OctalValuesCheck) no longer reports octal int literals of length <= 2 (e.g.00,02,07), whose value is identical in decimal.0644,0755,0777,04755,01777): an optional special-bits digit followed by owner/group/others digits, where owner has at least read permission and each digit is one of 0, 4, 5, 6, 7.0_prefix (e.g.0_7,0_13,0_755), and the issue message now suggests this prefix when an octal value is intended.🤖 Generated with Claude Code
Agent workflow
Tool link: https://github.com/SonarSource/languages-experimental-tooling/tree/romain/my-tickets/personal/romain-brenguier
PR created using
uv run create_with_claude.py Rule S1314, should not throw for int literals that have length <= 2 (e.g. 02), it should also not throw for common permission patterns like 0755 etc... Add samples to the tests for these casesPR updated using
uv run update_with_claude.py --prompt "Implement the action plan described in the document We should allow pattern like 0_7 0_13 0_755 (using prefix 0_) to write octal values as this is more explicit than without the _. Make that explicit in the issue message, that a possible fix if octal is really intended 0_ can be used as it is more explicit. We should still allow common permission patterns like 0755 and 0_755. Don't make change to the html directly but comment on the PR what should be the change to the rspec.." -a "We should allow pattern like 0_7 0_13 0_755 (using prefix 0_) to write octal values as this is more explicit than without the _. Make that explicit in the issue message, that a possible fix if octal is really intended 0_ can be used as it is more explicit. We should still allow common permission patterns like 0755 and 0_755. Don't make change to the html directly but comment on the PR what should be the change to the rspec." -g "claude"PR updated using
uv run update_with_claude.py --prompt "Implement the action plan described in the document Change the implementation to no longer exclude permission patterns from raising. Instead for these cases suggest to use a String equivalent to represent permissions where possible for instance "rwxrwxrwx" instead of 0777.." -a "Change the implementation to no longer exclude permission patterns from raising. Instead for these cases suggest to use a String equivalent to represent permissions where possible for instance "rwxrwxrwx" instead of 0777." -g "claude"PR updated using
uv run update_with_claude.py --prompt "Implement the action plan described in the document Code Review: Updates S1314 for Java by adding it to the Sonar way profile, rewriting the description, and documenting exceptions for short literals, Unix permission modes, and0_-prefixed octal literals. Changes are requested before merge. Open issues: the0755` example is still listed as confusing in the Why section, the permission-mode exception lacks a defined criterion, the worked octal alternative keeps the bug the noncompliant comments describe, the intro and list use parentheses the style guide avoids, the PR title does not follow the rule-change convention, and the PR description no longer matches the How to fix guidance. The sonar-java OctalValuesCheck does not yet implement these exceptions, so the spec must ship with the check change and the PR should stay in draft until then.💡 Quality: New Java description uses parentheses the style guide says to avoid
Files: rules/S1314/java/rule.adoc:1, rules/S1314/java/rule.adoc:9-11
The style guide says parentheses should be avoided and the information should be worked into the sentence instead. The new intro sentence uses three parentheticals: "(e.g.,
010,0755)", "(base-8)" and "(base-10)". Each item in the worked-example list also puts its calculation in parentheses, for example "(1×8 + 0 = 8)". Please rephrase, for example: "...starts with a zero followed by other digits, such as010or0755. Java interprets these as base-8 octal values rather than base-10 decimal values."Fix (Rewrite the intro sentence without parentheses.):
This rule raises an issue when an integer literal starts with a zero followed by other digits, such as
010or0755. Java interprets such a literal as a base-8 octal value rather than a base-10 decimal value.💡 Quality: Why-section still uses exempted 0755 as an example of confusing octal
Files: rules/S1314/java/rule.adoc:11, rules/S1314/java/rule.adoc:22, rules/S1314/java/rule.adoc:29
This commit makes
0755compliant: line 22 calls it the conventional Unix permission notation and line 29 marks it// Compliant. Line 11, in "Why is this an issue?", still lists0755next to010and060as an example of a confusing octal literal. The rule now presents the same literal as both a problem and an accepted exception. Replace it with a literal the rule still flags, such as01000, which matches the updated noncompliant example on line 52.Fix (Use a literal that is still noncompliant as the worked example.):
01000represents 512 in decimal (1×512 + 0 + 0 + 0 = 512)💡 Quality: PR title doesn't follow the rule-change title convention
Files: rules/S1314/java/rule.adoc:1
The repo requires rule change PR titles in the form
<JIRA-TICKET-ID> Modify rule Sxxxx. This PR is titledSONARJAVA-7151: Update S1314: add to Sonar way, ..., which has an extra colon and usesUpdateinstead ofModify rule. Rename it to something likeSONARJAVA-7151 Modify rule S1314: Add to Sonar way and document exceptions.Files: rules/S1314/java/rule.adoc:22, rules/S1314/java/rule.adoc:29-33, rules/S1314/java/rule.adoc:10, rules/S1314/java/rule.adoc:54
The new exception replaces a checkable criterion with "Common Unix file permission modes", but it never says which literals count. That leaves readers unable to decide whether an issue applies. The page's own examples show the gap.
060(group read/write) and010(group execute) are valid permission modes, yet lines 10, 39 and 54 treat them as noncompliant. Meanwhile0700and04755are exempt. A developer looking at0640,0060or02775cannot tell whether the rule should flag it. State the actual criterion the analyzer uses, such as an explicit list of modes or a shape like a 4-5 character literal whose digits form a valid mode, and explain why060stays noncompliant.Fix (Spell out the exact set or shape of exempt permission literals.):
0644,0755or04755, where the octal interpretation is intended. Shorter literals such as060are still reported.💡 Quality: Octal alternative keeps the bug the noncompliant comments describe
Files: rules/S1314/java/rule.adoc:53-55, rules/S1314/java/rule.adoc:67-74
The noncompliant comments say these variables were meant to hold 10, 60 and 1000, for example "timeout holds 48, not 60". The new "Or, if octal is intended" block then rewrites the same variables as
0_10,0_60and0_1000. Those still evaluate to 8, 48 and 512. Readers may take this as permission to add0_just to silence the rule, which leaves the timeout bug from the impact section in place. Use a separate example where octal is clearly intended, such as a permission mode likeint mode = 0_640;.Fix (Show the
0_form on a value whose octal meaning is intended.):Or, if an octal value is intended, such as a file permission mode:
[source,java]
int mode = 0_640;
💡 Quality: PR description no longer matches the How to fix guidance
Files: rules/S1314/java/rule.adoc:45, rules/S1314/java/message.adoc:3
The PR description says the "How to fix it" section mentions the
0x/0bprefixes. It also says nothing about the new0_-prefix exception or the Java-specific message. This commit replaced the fix sentence with decimal and0_guidance, so the0x/0bmention now only appears in the Why section. It also addedjava/message.adoc. Update the PR description so reviewers judge the rule against what it now says.." -a "Code Review: Updates S1314 for Java by adding it to the Sonar way profile, rewriting the description, and documenting exceptions for short literals, Unix permission modes, and0_-prefixed octal literals. Changes are requested before merge. Open issues: the0755example is still listed as confusing in the Why section, the permission-mode exception lacks a defined criterion, the worked octal alternative keeps the bug the noncompliant comments describe, the intro and list use parentheses the style guide avoids, the PR title does not follow the rule-change convention, and the PR description no longer matches the How to fix guidance. The sonar-java OctalValuesCheck does not yet implement these exceptions, so the spec must ship with the check change and the PR should stay in draft until then.💡 Quality: New Java description uses parentheses the style guide says to avoid
Files: rules/S1314/java/rule.adoc:1, rules/S1314/java/rule.adoc:9-11
The style guide says parentheses should be avoided and the information should be worked into the sentence instead. The new intro sentence uses three parentheticals: "(e.g.,
010,0755)", "(base-8)" and "(base-10)". Each item in the worked-example list also puts its calculation in parentheses, for example "(1×8 + 0 = 8)". Please rephrase, for example: "...starts with a zero followed by other digits, such as010or0755. Java interprets these as base-8 octal values rather than base-10 decimal values."Fix (Rewrite the intro sentence without parentheses.):
This rule raises an issue when an integer literal starts with a zero followed by other digits, such as
010or0755. Java interprets such a literal as a base-8 octal value rather than a base-10 decimal value.💡 Quality: Why-section still uses exempted 0755 as an example of confusing octal
Files: rules/S1314/java/rule.adoc:11, rules/S1314/java/rule.adoc:22, rules/S1314/java/rule.adoc:29
This commit makes
0755compliant: line 22 calls it the conventional Unix permission notation and line 29 marks it// Compliant. Line 11, in "Why is this an issue?", still lists0755next to010and060as an example of a confusing octal literal. The rule now presents the same literal as both a problem and an accepted exception. Replace it with a literal the rule still flags, such as01000, which matches the updated noncompliant example on line 52.Fix (Use a literal that is still noncompliant as the worked example.):
01000represents 512 in decimal (1×512 + 0 + 0 + 0 = 512)💡 Quality: PR title doesn't follow the rule-change title convention
Files: rules/S1314/java/rule.adoc:1
The repo requires rule change PR titles in the form
<JIRA-TICKET-ID> Modify rule Sxxxx. This PR is titledSONARJAVA-7151: Update S1314: add to Sonar way, ..., which has an extra colon and usesUpdateinstead ofModify rule. Rename it to something likeSONARJAVA-7151 Modify rule S1314: Add to Sonar way and document exceptions.Files: rules/S1314/java/rule.adoc:22, rules/S1314/java/rule.adoc:29-33, rules/S1314/java/rule.adoc:10, rules/S1314/java/rule.adoc:54
The new exception replaces a checkable criterion with "Common Unix file permission modes", but it never says which literals count. That leaves readers unable to decide whether an issue applies. The page's own examples show the gap.
060(group read/write) and010(group execute) are valid permission modes, yet lines 10, 39 and 54 treat them as noncompliant. Meanwhile0700and04755are exempt. A developer looking at0640,0060or02775cannot tell whether the rule should flag it. State the actual criterion the analyzer uses, such as an explicit list of modes or a shape like a 4-5 character literal whose digits form a valid mode, and explain why060stays noncompliant.Fix (Spell out the exact set or shape of exempt permission literals.):
0644,0755or04755, where the octal interpretation is intended. Shorter literals such as060are still reported.💡 Quality: Octal alternative keeps the bug the noncompliant comments describe
Files: rules/S1314/java/rule.adoc:53-55, rules/S1314/java/rule.adoc:67-74
The noncompliant comments say these variables were meant to hold 10, 60 and 1000, for example "timeout holds 48, not 60". The new "Or, if octal is intended" block then rewrites the same variables as
0_10,0_60and0_1000. Those still evaluate to 8, 48 and 512. Readers may take this as permission to add0_just to silence the rule, which leaves the timeout bug from the impact section in place. Use a separate example where octal is clearly intended, such as a permission mode likeint mode = 0_640;.Fix (Show the
0_form on a value whose octal meaning is intended.):Or, if an octal value is intended, such as a file permission mode:
[source,java]
int mode = 0_640;
💡 Quality: PR description no longer matches the How to fix guidance
Files: rules/S1314/java/rule.adoc:45, rules/S1314/java/message.adoc:3
The PR description says the "How to fix it" section mentions the
0x/0bprefixes. It also says nothing about the new0_-prefix exception or the Java-specific message. This commit replaced the fix sentence with decimal and0_guidance, so the0x/0bmention now only appears in the Why section. It also addedjava/message.adoc. Update the PR description so reviewers judge the rule against what it now says." -g "claude"`PR updated using
uv run update_with_claude.py --prompt "Implement the action plan described in the document [MINOR] Split this 185 characters long line (which is greater than 180 authorized). (component: java-checks/src/main/java/org/sonar/java/checks/OctalValuesCheck.java, line: 54)." -a "[MINOR] Split this 185 characters long line (which is greater than 180 authorized). (component: java-checks/src/main/java/org/sonar/java/checks/OctalValuesCheck.java, line: 54)" -g "claude"PR updated using
uv run update_with_claude.py --prompt "Implement the action plan described in the document Code Review: Rewrites the Java S1314 spec to add the rule to Sonar way, with new exceptions for literals of at most two characters,0_-prefixed literals, and Unix permission modes, plus a dedicated permission-mode message. Changes are requested before merge: the PR title doesn't follow the rule-change convention, the description is out of sync with the How to fix guidance, and the permission-mode message omits the decimal fix for zero-padded decimals like0700. The spec also must not ship until sonar-java'sOctalValuesCheckimplements the same exceptions and message, sinceisOctalstill flags00,07, and0_13` and the check's tests contradict the new spec.💡 Quality: PR title doesn't follow the rule-change title convention
Files: rules/S1314/java/rule.adoc:1
The repo requires rule change PR titles in the form
<JIRA-TICKET-ID> Modify rule Sxxxx. This PR is titledSONARJAVA-7151: Update S1314: add to Sonar way, ..., which has an extra colon and usesUpdateinstead ofModify rule. Rename it to something likeSONARJAVA-7151 Modify rule S1314: Add to Sonar way and document exceptions.💡 Quality: PR description no longer matches the How to fix guidance
Files: rules/S1314/java/rule.adoc:45, rules/S1314/java/message.adoc:3
The PR description says the "How to fix it" section mentions the
0x/0bprefixes. It also says nothing about the new0_-prefix exception or the Java-specific message. This commit replaced the fix sentence with decimal and0_guidance, so the0x/0bmention now only appears in the Why section. It also addedjava/message.adoc. Update the PR description so reviewers judge the rule against what it now says.💡 Edge Case: Permission-mode message drops the decimal fix for padded decimals
Files: rules/S1314/java/message.adoc:4, rules/S1314/java/rule.adoc:17
Line 17 says the dedicated message fires for any four-character literal whose three digits are each 0, 4, 5, 6 or 7, with an owner digit of at least 4. That pattern also covers zero-padded decimals, which are the main bug this rule targets. Examples are times of day like
int start = 0700;or0645, and counts like0500. For those, the message in message.adoc:4 only offers a symbolic permission string such as "rwx------" or the0_prefix. It never mentions the decimal value the developer probably meant, so they get pointed at a fix that makes no sense. Add the decimal alternative to the permission-mode message, for example: "If this is a file permission mode, use the symbolic permission string "{symbolic}"; otherwise use the decimal value. If an octal value is intended, use the more explicit "0_" prefix."The Validate Rules job failed because the S1314 Java AsciiDoc description uses inline code ending in an underscore (
0_), which the asciidoc validator rejects; this is directly caused by the PR's documentation change.." -a "Code Review: Rewrites the Java S1314 spec to add the rule to Sonar way, with new exceptions for literals of at most two characters,0_-prefixed literals, and Unix permission modes, plus a dedicated permission-mode message. Changes are requested before merge: the PR title doesn't follow the rule-change convention, the description is out of sync with the How to fix guidance, and the permission-mode message omits the decimal fix for zero-padded decimals like0700. The spec also must not ship until sonar-java'sOctalValuesCheckimplements the same exceptions and message, sinceisOctalstill flags00,07, and0_13and the check's tests contradict the new spec.💡 Quality: PR title doesn't follow the rule-change title convention
Files: rules/S1314/java/rule.adoc:1
The repo requires rule change PR titles in the form
<JIRA-TICKET-ID> Modify rule Sxxxx. This PR is titledSONARJAVA-7151: Update S1314: add to Sonar way, ..., which has an extra colon and usesUpdateinstead ofModify rule. Rename it to something likeSONARJAVA-7151 Modify rule S1314: Add to Sonar way and document exceptions.💡 Quality: PR description no longer matches the How to fix guidance
Files: rules/S1314/java/rule.adoc:45, rules/S1314/java/message.adoc:3
The PR description says the "How to fix it" section mentions the
0x/0bprefixes. It also says nothing about the new0_-prefix exception or the Java-specific message. This commit replaced the fix sentence with decimal and0_guidance, so the0x/0bmention now only appears in the Why section. It also addedjava/message.adoc. Update the PR description so reviewers judge the rule against what it now says.💡 Edge Case: Permission-mode message drops the decimal fix for padded decimals
Files: rules/S1314/java/message.adoc:4, rules/S1314/java/rule.adoc:17
Line 17 says the dedicated message fires for any four-character literal whose three digits are each 0, 4, 5, 6 or 7, with an owner digit of at least 4. That pattern also covers zero-padded decimals, which are the main bug this rule targets. Examples are times of day like
int start = 0700;or0645, and counts like0500. For those, the message in message.adoc:4 only offers a symbolic permission string such as "rwx------" or the0_prefix. It never mentions the decimal value the developer probably meant, so they get pointed at a fix that makes no sense. Add the decimal alternative to the permission-mode message, for example: "If this is a file permission mode, use the symbolic permission string "{symbolic}"; otherwise use the decimal value. If an octal value is intended, use the more explicit "0_" prefix."The Validate Rules job failed because the S1314 Java AsciiDoc description uses inline code ending in an underscore (
0_), which the asciidoc validator rejects; this is directly caused by the PR's documentation change." -g "claude"`PR updated using
uv run update_with_claude.py --prompt "Implement the action plan described in the document Can you pull using rule-api the changes to the rspec for S1314 from the pull request https://github.com/SonarSource/rspec/pull/8334? And Rename OctalValuesCheck sample file to something ending in Sample." -a "Can you pull using rule-api the changes to the rspec for S1314 from the pull request https://github.com/SonarSource/rspec/pull/8334? And Rename OctalValuesCheck sample file to something ending in Sample" -g "claude"Summary by Gitar
rwxr-xr-xfor four-character permission literals like0755This will update automatically on new commits.