Menu

#782 violation reported without source file name

closed
pmd (543)
5
2015-01-04
2008-06-09
ldantas
No

PMD 4.2.2 detects violations without source file name

Below a simple example to reproduce :

PMD 4.2.2

"java -version
java version "1.5.0_14"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_14-b03)
Java HotSpot(TM) Server VM (build 1.5.0_14-b03, mixed mode)

SunOS bt1sssr7 5.8 Generic_117350-46 sun4u sparc SUNW,Sun-Fire-V440

HOW to reproduce:
pmd.sh F.java xml rulesets.xml >F.xml

cut here<<<<

public class F
{
String J;
public void f()
{
StringBuffer s = new StringBuffer ("C"+J+"D"+"H");
};
}

cut here<<<<<<<<<

We obtain the following xml report:

cut here<<<<<
<?xml version="1.0" encoding="UTF-8"?>
<pmd version="4.2.2" timestamp="2008-06-09T10:07:01.404">
<file name="">
<violation beginline="0" endline="0" begincolumn="0" endcolumn="0" rule="ConsecutiveLiteralAppends" ruleset="String and StringBuffer Rules" externalInfoUrl="http://pmd.sourceforge.net/rules/strings.html#ConsecutiveLiteralAppends" priority="3">
StringBuffer.append is called 2 consecutive times with literal Strings. Use a single append with a single String.
</violation>
</file>
<file name="/usr/users/ldantas/F.java">
<violation beginline="1" endline="8" begincolumn="8" endcolumn="1" rule="NoPackage" ruleset="Naming Rules" externalInfoUrl="http://pmd.sourceforge.net/rules/naming.html#NoPackage" priority="3">
All classes and interfaces must belong to a named package
</violation>
<violation beginline="3" endline="3" begincolumn="16" endcolumn="16" rule="ShortVariable" ruleset="Naming Rules" class="F" variable="J" externalInfoUrl="http://pmd.sourceforge.net/rules/naming.html#ShortVariable" priority="3">
Avoid variables with short names like J
</violation>
<violation beginline="3" endline="3" begincolumn="16" endcolumn="16" rule="BeanMembersShouldSerialize" ruleset="JavaBean Rules" class="F" variable="J" externalInfoUrl="http://pmd.sourceforge.net/rules/javabeans.html#BeanMembersShouldSerialize" priority="3">
Found non-transient, non-static member. Please mark as transient or provide accessors.
</violation>
<violation beginline="3" endline="3" begincolumn="9" endcolumn="17" rule="SuspiciousConstantFieldName" ruleset="Naming Rules" class="F" variable="J" externalInfoUrl="http://pmd.sourceforge.net/rules/naming.html#SuspiciousConstantFieldName" priority="3">
The field name indicates a constant but its modifiers do not
</violation>
<violation beginline="3" endline="3" begincolumn="9" endcolumn="17" rule="DefaultPackage" ruleset="Controversial Rules" class="F" externalInfoUrl="http://pmd.sourceforge.net/rules/controversial.html#DefaultPackage" priority="3">
Use explicit scoping instead of the default package private level
</violation>
<violation beginline="4" endline="4" begincolumn="21" endcolumn="23" rule="ShortMethodName" ruleset="Naming Rules" class="F" method="f" externalInfoUrl="http://pmd.sourceforge.net/rules/naming.html#ShortMethodName" priority="3">
Avoid using short method names
</violation>
<violation beginline="6" endline="6" begincolumn="30" endcolumn="30" rule="UnusedLocalVariable" ruleset="Unused Code Rules" class="F" method="f" variable="s" externalInfoUrl="http://pmd.sourceforge.net/rules/unusedcode.html#UnusedLocalVariable" priority="3">
Avoid unused local variables such as 's'.
</violation>
<violation beginline="6" endline="6" begincolumn="30" endcolumn="30" rule="ShortVariable" ruleset="Naming Rules" class="F" method="f" variable="s" externalInfoUrl="http://pmd.sourceforge.net/rules/naming.html#ShortVariable" priority="3">
Avoid variables with short names like s
</violation>
<violation beginline="6" endline="7" begincolumn="30" endcolumn="65" rule="DataflowAnomalyAnalysis" ruleset="Controversial Rules" class="F" method="f" variable="s" externalInfoUrl="http://pmd.sourceforge.net/rules/controversial.html#DataflowAnomalyAnalysis" priority="5">
Found 'DU'-anomaly for variable 's' (lines '6'-'7').
</violation>
<violation beginline="6" endline="7" begincolumn="30" endcolumn="65" rule="DataflowAnomalyAnalysis" ruleset="scratchpad" class="F" method="f" variable="s" priority="5">
Found 'DU'-anomaly for variable 's' (lines '6'-'7').
</violation>
<violation beginline="6" endline="6" begincolumn="17" endcolumn="65" rule="LocalVariableCouldBeFinal" ruleset="Optimization Rules" class="F" method="f" variable="s" externalInfoUrl="http://pmd.sourceforge.net/rules/optimizations.html#LocalVariableCouldBeFinal" priority="3">
Local variable 's' could be declared final
</violation>
</file>
</pmd>

cut here <<<<<<<<<<<<

Discussion

  • ldantas

    ldantas - 2008-06-09

    output xml file

     
  • ldantas

    ldantas - 2008-06-09

    java file

     
  • ldantas

    ldantas - 2008-06-09

    Logged In: YES
    user_id=2108734
    Originator: YES

    File Added: F.java

     
  • Ryan Gustafson

    Ryan Gustafson - 2008-06-10

    Logged In: YES
    user_id=342470
    Originator: NO

    There's two issues here:

    1) ConsecutiveStringLiteral is trying to report a violation on a null Node. In prior versions of PMD, this would have causes a NullPointerException (I think anyway). This is a bug in the ConsecutiveStringLiteralRule.

    2) RuleViolation now supports reporting on a null Node, but it is intended for cases in which the violation is not file specific (e.g. aggregate result from processing many files). Unfortunately, to maintain backward compatibility in 4.2, there is no way to know when a violation is Node specific, or non-Node specific, so failures like (1) above, are being treated as non-Node specific.

    I'll correct ConsecutiveStringLiteral to report on a Node.

    PMD 4.2.3 will include this fix when it is released. The release date is indeterminate at this time.

     

Log in to post a comment.