/pmd-4.2.5/docs/suppressing.html
HTML | 124 lines | 93 code | 31 blank | 0 comment | 0 complexity | dd61389de636a50cd9737fb49abf67c8 MD5 | raw file
Possible License(s): BSD-3-Clause
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head><title>PMD - Suppressing warnings</title><style type="text/css" media="all">
- @import url("./style/maven-base.css");
-
- @import url("./style/maven-theme.css");</style><link rel="stylesheet" href="./style/print.css" type="text/css" media="print"></link><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"></meta><meta name="author" content="Tom Copeland"></meta><meta name="email" content="tom@infoether.com"></meta></head><body class="composite"><div id="banner"><a href="http://pmd.sourceforge.net/" id="organizationLogo"><img alt="InfoEther" src="http://sourceforge.net/sflogo.php?group_id=56262&type=5"></img></a><a href="http://pmd.sourceforge.net/" id="projectLogo"><img alt="PMD" src="./images/pmd_logo_small.jpg"></img></a><div class="clear"><hr></hr></div></div><div id="breadcrumbs"><div class="xleft"></div><div class="xright">
-
- <a href="http://pmdapplied.com/" class="externalLink" title="External Link">**** Get the book! ****</a>
-
-
-
- <span class="separator">|</span>
-
-
- <a href="http://sourceforge.net/projects/pmd" class="externalLink" title="External Link">SourceForge.net Project Page</a>
-
-
-
- <span class="separator">|</span>
-
-
- <a href="http://sourceforge.net" class="externalLink" title="External Link">Hosted by SourceForge</a>
- </div><div class="clear"><hr></hr></div></div><div id="leftColumn"><div id="navcolumn"><div id="menuOverview"><h5>Overview</h5><ul><li class="none"><a href="http://sourceforge.net/project/showfiles.php?group_id=56262&package_id=51441&release_id=632850" class="externalLink" title="External Link">Download PMD 4.2.5</a></li><li class="none"><a href="http://sourceforge.net/project/shownotes.php?release_id=632850&group_id=56262" class="externalLink" title="External Link">What's new in PMD 4.2.5</a></li><li class="none"><a href="news.html">PMD in the news</a></li><li class="none"><a href="products.html">PMD-related products and books</a></li><li class="none"><a href="bestpractices.html">Best practices</a></li><li class="none"><a href="future.html">Future directions</a></li><li class="none"><a href="similar-projects.html">Similar projects</a></li><li class="none"><a href="credits.html">Credits</a></li><li class="none"><a href="license.html">License</a></li><li class="none"><a href="meaning.html">What does 'PMD' mean?</a></li></ul></div><div id="menuUsage"><h5>Usage</h5><ul><li class="none"><a href="installing.html">Installation</a></li><li class="none"><a href="running.html">Command line usage</a></li><li class="none"><a href="ant-task.html">Ant task usage</a></li><li class="none"><a href="maven-plugin.html">Maven plugin usage</a></li><li class="none"><a href="mvn-plugin.html">Mvn plugin usage</a></li><li class="none"><a href="integrations.html">IDE plugin usage</a></li><li class="none"><strong><a href="suppressing.html">Suppressing warnings</a></strong></li><li class="none"><a href="cpd.html">Finding duplicated code</a></li><li class="none"><a href="jspsupport.html">JSP support</a></li></ul></div><div id="menuCustomizing_PMD"><h5>Customizing PMD</h5><ul><li class="none"><a href="compiling.html">Compiling PMD</a></li><li class="none"><a href="howtowritearule.html">How to write a rule</a></li><li class="none"><a href="xpathruletutorial.html">Writing XPath rules</a></li><li class="none"><a href="howtomakearuleset.html">How to make a rule set</a></li><li class="none"><a href="howitworks.html">How it works</a></li><li class="none"><a href="rule-guidelines.html">Rule guidelines</a></li></ul></div><div id="menuFor_example"><h5>For example</h5><ul><li class="none"><a href="scoreboard.html">Run PMD on a Sourceforge project</a></li></ul></div><div id="menuRule_Sets"><h5>Rule Sets</h5><ul><li class="none"><a href="rules/index.html">Index</a></li><li class="none"><a href="rules/android.html">Android</a></li><li class="none"><a href="rules/basic.html">Basic</a></li><li class="none"><a href="rules/braces.html">Braces</a></li><li class="none"><a href="rules/codesize.html">Code Size</a></li><li class="none"><a href="rules/clone.html">Clone</a></li><li class="none"><a href="rules/controversial.html">Controversial</a></li><li class="none"><a href="rules/coupling.html">Coupling</a></li><li class="none"><a href="rules/design.html">Design</a></li><li class="none"><a href="rules/finalizers.html">Finalizers</a></li><li class="none"><a href="rules/imports.html">Import Statements</a></li><li class="none"><a href="rules/j2ee.html">J2EE</a></li><li class="none"><a href="rules/javabeans.html">Javabeans</a></li><li class="none"><a href="rules/junit.html">JUnit Tests</a></li><li class="none"><a href="rules/logging-java.html">Logging (Java)</a></li><li class="none"><a href="rules/logging-jakarta-commons.html">Logging (Jakarta)</a></li><li class="none"><a href="rules/migrating.html">Migrating</a></li><li class="none"><a href="rules/naming.html">Naming</a></li><li class="none"><a href="rules/optimizations.html">Optimizations</a></li><li class="none"><a href="rules/strictexception.html">Strict Exceptions</a></li><li class="none"><a href="rules/strings.html">Strings</a></li><li class="none"><a href="rules/sunsecure.html">Sun Security</a></li><li class="none"><a href="rules/unusedcode.html">Unused Code</a></li><li class="none"><a href="rules/basic-jsp.html">Java Server Pages</a></li><li class="none"><a href="rules/basic-jsf.html">Java Server Faces</a></li></ul></div><div id="menuProject_Documentation"><h5>Project Documentation</h5><ul><li class="none"><a href="index.html">About</a></li><li class="collapsed"><a href="project-info.html">Project Info</a></li><li class="collapsed"><a href="maven-reports.html">Project Reports</a></li><li class="none"><a href="development-process.html">Development Process</a></li></ul></div><div id="legend"><h5>Legend</h5><ul><li class="externalLink">External Link</li><li class="newWindow">Opens in a new window</li></ul></div><a href="http://maven.apache.org/" title="Built by Maven" id="poweredBy"><img alt="Built by Maven" src="./images/logos/mavenlogo_builtby_w.png"></img></a></div></div><div id="bodyColumn"><div class="contentBox"><div class="section"><a name="Suppressing_warnings"></a><h2>Suppressing warnings</h2>
- <div class="subsection"><a name="Annotations"></a><h3>Annotations</h3>
- <p>You can use a JDK 1.5 annotation to suppress PMD warnings, like this:</p>
- <div class="source"><pre>
- // This will suppress all the PMD warnings in this class
- @SuppressWarnings("PMD")
- public class Bar {
- void bar() {
- int foo;
- }
- }
- </pre></div>
-
- <p>Or you can suppress one rule with an annotation like this:</p>
- <div class="source"><pre>
- // This will suppress UnusedLocalVariable warnings in this class
- @SuppressWarnings("PMD.UnusedLocalVariable")
- public class Bar {
- void bar() {
- int foo;
- }
- }
- </pre></div>
-
- <p>PMD also obeys the JDK annotation @SuppressWarnings("unused"), which will apply to all rules in the unused ruleset</p>
- <div class="source"><pre>
- // This will suppress UnusedLocalVariable and UnusedPrivateMethod warnings in this class
- @SuppressWarnings("unused")
- public class Bar {
- void bar() {
- int foo;
- }
- private void foobar(){}
- }
- </pre></div>
-
- </div>
- <div class="subsection"><a name="NOPMD"></a><h3>NOPMD</h3>
- <p>Alternatively, you can tell PMD to ignore a specific line by using the "NOPMD" marker, like this:</p>
- <div class="source"><pre>
- public class Bar {
- // 'bar' is accessed by a native method, so we want to suppress warnings for it
- private int bar; //NOPMD
- }
- </pre></div>
-
- <p>You can use whatever text string you want to suppress warnings, for example, here's
- how to use TURN_OFF_WARNINGS as the suppressor:</p>
- <div class="source"><pre>
- $ cat Foo.java
- public class Foo {
- void bar() {
- int x = 2; // TURN_OFF_WARNINGS
- }
- }
- $ ./pmd.sh Foo.java text unusedcode -excludemarker TURN_OFF_WARNINGS
- No problems found!
- UnusedLocalVariable rule violation suppressed by //NOPMD in /home/tom/pmd/pmd/bin/Foo.java
- </pre></div>
-
-
- <p>Note that PMD expects the //NOPMD marker to be on the same line as the violation. So, for
- example, if you want to suppress an "empty if statement" warning, you'll need to place it on
- the line containing the "if" keyword, e.g.:</p>
- <div class="source"><pre>
- $ cat ~/tmp/Foo.java
- public class Foo {
- void bar() {
- int x = 42;
- if (x > 5) { // NOPMD
- }
- }
- }
- $ java net.sourceforge.pmd.PMD ~/tmp/Foo.java text basic
- No problems found!
- $
- </pre></div>
-
- <p>A message placed after the NOPMD marker will get placed in the report, e.g.:</p>
- <div class="source"><pre>
- public class Foo {
- void bar() {
- try {
- bar();
- } catch (FileNotFoundException e) {} // NOPMD - this surely will never happen
- }
- }
- }
- </pre></div>
-
- </div>
- <p>Suggestions? Comments? Post them <a href="http://sourceforge.net/forum/forum.php?forum_id=188192" class="externalLink" title="External Link">here</a>. Thanks!</p>
- </div></div></div><div class="clear"><hr></hr></div><div id="footer"><div class="xright"> 2002-2009, InfoEther</div><div class="clear"><hr></hr></div></div></body></html>