diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/SuspiciousOctalEscapeRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/SuspiciousOctalEscapeRule.java index 389add0c9b..17edef59b1 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/SuspiciousOctalEscapeRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/SuspiciousOctalEscapeRule.java @@ -46,7 +46,7 @@ public class SuspiciousOctalEscapeRule extends AbstractJavaRulechainRule { // escape followed by // an octal digit -- legal but very // confusing! - addViolation(data, node); + addViolation(data, node, "\\" + first + second + " + " + third); } else { // if there is a 4th decimal digit, it // could never be part of @@ -55,7 +55,7 @@ public class SuspiciousOctalEscapeRule extends AbstractJavaRulechainRule { if (escapeSequence.length() > 3) { char fourth = escapeSequence.charAt(3); if (isDecimal(fourth)) { - addViolation(data, node); + addViolation(data, node, "\\" + first + second + third + " + " + fourth); } } } @@ -64,14 +64,14 @@ public class SuspiciousOctalEscapeRule extends AbstractJavaRulechainRule { // this is a two-digit octal escape followed // by a decimal digit // legal but very confusing - addViolation(data, node); + addViolation(data, node, "\\" + first + second + " + " + third); } } } else if (isDecimal(second)) { // this is a one-digit octal escape followed by a // decimal digit // legal but very confusing - addViolation(data, node); + addViolation(data, node, "\\" + first + " + " + second); } } } else if (first == '\\') { diff --git a/pmd-java/src/main/resources/category/java/errorprone.xml b/pmd-java/src/main/resources/category/java/errorprone.xml index 1849bd2e26..418463ce45 100644 --- a/pmd-java/src/main/resources/category/java/errorprone.xml +++ b/pmd-java/src/main/resources/category/java/errorprone.xml @@ -3001,7 +3001,7 @@ public class Foo { diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/SuspiciousOctalEscape.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/SuspiciousOctalEscape.xml index 0b2cdf6f2a..29413a50ef 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/SuspiciousOctalEscape.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/SuspiciousOctalEscape.xml @@ -4,24 +4,25 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pmd.sourceforge.net/rule-tests http://pmd.sourceforge.net/rule-tests_1_0_0.xsd"> - should be flagged 1 3 + + Suspicious decimal characters following octal escape in string literal: \12 + 8 + should be flagged - different octal 1 + + Suspicious decimal characters following octal escape in string literal: \000 + 8 + should be flagged - different octal 1 + + Suspicious decimal characters following octal escape in string literal: \40 + 0 + [ 2050064 ] False + SuspiciousOctalEscape with backslash literal, second test case 1 + + Suspicious decimal characters following octal escape in string literal: \12 + 8 +