[java] SuspiciousOctalEscape: Improve rule message
This commit is contained in:
3 files changed
+18
-8
No files matched your search
+4
-4
@@ -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 == '\\') {
|
||||
|
||||
@@ -3001,7 +3001,7 @@ public class Foo {
|
||||
<rule name="SuspiciousOctalEscape"
|
||||
language="java"
|
||||
since="1.5"
|
||||
message="Suspicious decimal characters following octal escape in string literal"
|
||||
message="Suspicious decimal characters following octal escape in string literal: {0}"
|
||||
class="net.sourceforge.pmd.lang.java.rule.errorprone.SuspiciousOctalEscapeRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#suspiciousoctalescape">
|
||||
<description>
|
||||
|
||||
+13
-3
@@ -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">
|
||||
|
||||
<!--
|
||||
<test-code>
|
||||
<description>ok use of octal</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
void bar() {
|
||||
int x = \028;
|
||||
String x = "\027";
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
-->
|
||||
|
||||
<test-code>
|
||||
<description>should be flagged</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<expected-linenumbers>3</expected-linenumbers>
|
||||
<expected-messages>
|
||||
<message>Suspicious decimal characters following octal escape in string literal: \12 + 8</message>
|
||||
</expected-messages>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
void bar() {
|
||||
@@ -34,6 +35,9 @@ public class Foo {
|
||||
<test-code>
|
||||
<description>should be flagged - different octal</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<expected-messages>
|
||||
<message>Suspicious decimal characters following octal escape in string literal: \000 + 8</message>
|
||||
</expected-messages>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
void bar() {
|
||||
@@ -46,6 +50,9 @@ public class Foo {
|
||||
<test-code>
|
||||
<description>should be flagged - different octal</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<expected-messages>
|
||||
<message>Suspicious decimal characters following octal escape in string literal: \40 + 0</message>
|
||||
</expected-messages>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
void bar() {
|
||||
@@ -70,6 +77,9 @@ public class Foo {
|
||||
<test-code>
|
||||
<description>[ 2050064 ] False + SuspiciousOctalEscape with backslash literal, second test case</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<expected-messages>
|
||||
<message>Suspicious decimal characters following octal escape in string literal: \12 + 8</message>
|
||||
</expected-messages>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
void bar() {
|
||||
|
||||
Reference in new issue
Block a user