SONARJAVA-6826: Implemented rule S9359 (Octal escape sequences should not be followed by digits) - #6008
Conversation
… not be followed by digits) This rule detects octal escape sequences in string literals that are followed by additional digits, which can create ambiguity about the intended character sequence. The rule identifies patterns like '\128' where it's unclear whether this represents octal escape '\12' followed by literal '8', or a malformed escape sequence. Files added: - OctalEscapeSequenceFollowedByDigitCheck.java: Rule implementation - OctalEscapeSequenceFollowedByDigitCheckTest.java: Unit tests - OctalEscapeSequenceFollowedByDigitCheckSample.java: Test samples - S9359.html, S9359.json: Rule metadata
This comment has been minimized.
This comment has been minimized.
- Remove backslash from isAmbiguousFollowUp to avoid false positive on consecutive octal escapes like "\1\2" - Replace newlines with space instead of empty string in text block handling to avoid false positives when octal escapes span lines - Remove misaligned column markers from test sample to match full-node issue reporting - Add compliant test case for consecutive octal escapes - Set quickfix metadata to "infeasible" instead of "unknown" Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Reduce cognitive complexity of visitNode by extracting containsOctalFollowedByDigit and processBackslash helper methods - Eliminate multiple continue statements by using if/else-if/else - Add test cases for text blocks, edge cases, and improved coverage Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ith digits 4-7 Java only allows 2-digit octal escapes when the first digit is 4-7 (e.g., \45), but the rule was treating them as 3-digit escapes. This caused false negatives like "\456" not being flagged (Java parses it as \45 followed by '6'). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| </pre> | ||
| <h4>Compliant solution</h4> | ||
| <pre data-diff-id="1" data-diff-type="compliant"> | ||
| String message = "Error code: \u000A" + "8"; |
Prefer named escape sequences over Unicode escapes in fix guidance, and update quickfix status to unknown. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Code Review ✅ Approved 4 resolved / 4 findingsImplements static analysis rule S9359 to detect octal escape sequences followed by digits, resolving issues with ambiguous parsing, text block newlines, and precise test markers. No issues found. ✅ 4 resolved✅ Bug: Backslash treated as ambiguous flags valid consecutive octal escapes
✅ Bug: reportIssue highlights whole literal but test uses precise markers
✅ Edge Case: Text block newline stripping can merge digits across lines
✅ Edge Case: 3-digit octal parsing ignores \4-\7 two-digit limit
Implementation Status ◻️ 0 of 1 objectives covered◻️ SONARJAVA-6826 - 0 of 1 objectives coveredThis PR does not implement rule S9359 as the diff is unrelated and focuses on removing Bean Validation annotations. Other objectives on this issue, possibly covered elsewhere:
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 |
|
| </pre> | ||
| <h4>Compliant solution</h4> | ||
| <pre data-diff-id="1" data-diff-type="compliant"> | ||
| String message = "Error code: \n" + "8"; |
There was a problem hiding this comment.
Nit: I find that the concatenation adds noise without improving clarity, but if you prefer the current version, feel free to merge of course.
| String message = "Error code: \n" + "8"; | |
| String message = "Error code: \n8"; |





This PR implements rule S9359 which detects octal escape sequences in string literals that are followed by additional digits, creating ambiguity about the intended character sequence.
The rule identifies patterns like '\128' where it's unclear whether this represents octal escape '\12' followed by literal '8', or a malformed escape sequence. This can lead to confusion and potential bugs in string handling code.
Changes: