Bugs item #1964927, was opened at 2008-05-15 15:53
Message generated for change (Comment added) made by tiupayzai
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=479921&aid=1964927&group_id=56262
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Closed
Resolution: Invalid
Priority: 5
Private: No
Submitted By: Rick Rupp (tiupayzai)
Assigned to: Nobody/Anonymous (nobody)
Summary: AvoidDuplicateLiterals falsely identifies annotations
Initial Comment:
I am getting false hits because of literals used in annotations.
AvoidDuplicateLiterals rule identifies literals used in annotations.
I've tested by running PMD from an ant task using the following two versions. The result is the same for both of them.
pmd-3.9.jar
pmd-4.2.1.jar
Example:
--------
There are 4 methods in a java class that use the annotation
@SuppressWarnings("unchecked")
I get the following PMD warning...
The String literal "unchecked" appears 4 times in this file; the first occurrence is on line 385
I don't want to turn off this rule, because it is valuable. But it's really annoying to mark up my code with the NOPMD just to make this go away.
@SuppressWarnings("unchecked") // NOPMD string literal
Am I missing a setting, or is this a bug?
----------------------------------------------------------------------
>Comment By: Rick Rupp (tiupayzai)
Date: 2008-05-15 17:51
Message:
Logged In: YES
user_id=2088498
Originator: YES
Thanks for the help. This worked for me perfectly.
Unfortunately my ruleset definition is a bit inelegant.
I wanted to have one command that included the entire strings ruleset, and
set the property for the AvoidDuplicateLiterals.
<rule ref="rulesets/strings.xml">
<!-- I want to set property for "AvoidDuplicateLiterals" here -->
</rule>
Instead I had to do it in two statements....
1) Include all the strings rules, but exclude the AvoidDuplicateLiterals
rule.
2) Include the AvoidDuplicateLiterals and set it's property.
<rule ref="rulesets/strings.xml">
<exclude name="AvoidDuplicateLiterals"/>
</rule>
<rule ref="rulesets/strings.xml/AvoidDuplicateLiterals">
<properties>
<property name="skipAnnotations" value="true"/>
</properties>
</rule>
*shrug* close enough. It's readable and it works.
Feel free to poke fun at me if there's a better way to do this. :-)
I'm just posting the exact XML to fix the problem so the next person who
searches for this can find the answer quickly.
----------------------------------------------------------------------
Comment By: Xavier Le Vourch (xlv)
Date: 2008-05-15 16:42
Message:
Logged In: YES
user_id=1373398
Originator: NO
Since 4.2.1, there's a property called "skipAnnotations". Setting it to
true in your ruleset will achieve what you want.
Xavier
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=479921&aid=1964927&group_id=56262
|