pmd/pmd_rules_java.html

2323 lines
116 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Index of all built-in rules available for Java">
<meta name="keywords" content="rule_referencesjava, ">
<title>Java Rules | PMD Source Code Analyzer</title>
<link rel="stylesheet" type="text/css" href="assets/fontawesome-free-5.15.4-web/css/all.min.css">
<link rel="stylesheet" type="text/css" href="assets/bootstrap-4.5.2-dist/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/syntax.css">
<link rel="stylesheet" type="text/css" href="css/modern-business.css">
<link rel="stylesheet" type="text/css" href="css/customstyles.css">
<link rel="stylesheet" type="text/css" href="css/theme-green.css">
<link rel="stylesheet" type="text/css" href="css/pmd-customstyles.css">
<link rel="shortcut icon" href="images/logo/favicon.ico" type="image/x-icon">
<link rel="icon" href="images/logo/favicon.ico" type="image/x-icon">
<link rel="alternate" type="application/rss+xml" title="" href="feed.xml">
</head>
<body>
<!-- Content is offset by the height of the topnav bar. -->
<!-- There's already a padding-top rule in modern-business.css, but it apparently doesn't work on Firefox 60 and Chrome 67 -->
<div id="topbar-content-offset">
<!-- Navigation -->
<nav class="navbar navbar-expand-lg fixed-top navbar-dark">
<div class="container topnavlinks">
<a class="navbar-brand fas fa-home fa-lg" href="index.html">&nbsp;<span class="projectTitle"> PMD Source Code Analyzer Project</span></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto mt-2 mt-lg-0"></ul>
<ul class="navbar-nav">
<!-- toggle sidebar button -->
<li class="nav-item"><a id="tg-sb-link" class="nav-link" href="#"><i id="tg-sb-icon" class="fas fa-toggle-on"></i> Nav</a></li>
<!-- entries without drop-downs appear here -->
<li class="nav-item"><a class="nav-link" href="https://github.com/pmd/pmd/releases/latest" target="_blank">Download</a></li>
<li class="nav-item"><a class="nav-link" href="https://github.com/pmd/pmd" target="_blank">Fork us on github</a></li>
<!-- entries with drop-downs appear here -->
<!-- conditional logic to control which topnav appears for the audience defined in the configuration file.-->
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="search..." id="search-input">
<ul id="results-container"></ul>
</form>
</div>
</div>
</nav>
<!-- Page Content -->
<div class="container-toc-wrapper">
<div class="container">
<div class="col-lg-12">&nbsp;</div>
<!-- Content Row -->
<div class="row">
<!-- Sidebar Column -->
<div class="col-md-3" id="tg-sb-sidebar">
<ul id="mysidebar" class="nav">
<li class="sidebarTitle">PMD 7.8.0-SNAPSHOT</li>
<div class="sidebarTitleDate">Release date: 29-November-2024</div>
<li>
<a href="#">About</a>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="pmd_release_notes.html">Release notes</a></li>
<li><a href="pmd_release_notes_pmd7.html">Release notes (PMD 7)</a></li>
<li><a href="pmd_about_help.html">Getting help</a></li>
<li><a href="pmd_about_release_policies.html">Release policies</a></li>
<li><a href="pmd_about_support_lifecycle.html">Support lifecycle</a></li>
</ul>
</li>
<li>
<a href="#">User Documentation</a>
<ul>
<li><a href="pmd_userdocs_migrating_to_pmd7.html">Migration Guide for PMD 7</a></li>
<li><a href="pmd_userdocs_installation.html">Installation and basic CLI usage</a></li>
<li><a href="pmd_userdocs_making_rulesets.html">Making rulesets</a></li>
<li><a href="pmd_userdocs_configuring_rules.html">Configuring rules</a></li>
<li><a href="pmd_userdocs_best_practices.html">Best practices</a></li>
<li><a href="pmd_userdocs_suppressing_warnings.html">Suppressing warnings</a></li>
<li><a href="pmd_userdocs_incremental_analysis.html">Incremental analysis</a></li>
<li><a href="pmd_userdocs_cli_reference.html">PMD CLI reference</a></li>
<li><a href="pmd_userdocs_report_formats.html">PMD Report formats</a></li>
<li><a href="pmd_userdocs_3rdpartyrulesets.html">3rd party rulesets</a></li>
<li class="subfolders">
<a href="#">CPD reference</a>
<ul>
<li><a href="pmd_userdocs_cpd.html">Copy-paste detection</a></li>
<li><a href="pmd_userdocs_cpd_report_formats.html">CPD Report formats</a></li>
</ul>
</li>
<li class="subfolders">
<a href="#">Extending PMD</a>
<ul>
<li><a href="pmd_userdocs_extending_writing_rules_intro.html">Introduction to writing rules</a></li>
<li><a href="pmd_userdocs_extending_your_first_rule.html">Your first rule</a></li>
<li><a href="pmd_userdocs_extending_writing_xpath_rules.html">XPath rules</a></li>
<li><a href="pmd_userdocs_extending_writing_java_rules.html">Java rules</a></li>
<li><a href="pmd_userdocs_extending_designer_reference.html">Rule designer reference</a></li>
<li><a href="pmd_userdocs_extending_defining_properties.html">Defining rule properties</a></li>
<li><a href="pmd_userdocs_extending_rule_guidelines.html">Rule guidelines</a></li>
<li><a href="pmd_userdocs_extending_testing.html">Testing your rules</a></li>
<li><a href="pmd_userdocs_extending_ast_dump.html">Creating (XML) dump of the AST</a></li>
</ul>
</li>
<li class="subfolders">
<a href="#">Tools / Integrations</a>
<ul>
<li><a href="pmd_userdocs_tools_maven.html">Maven PMD Plugin</a></li>
<li><a href="pmd_userdocs_tools_gradle.html">Gradle</a></li>
<li><a href="pmd_userdocs_tools_ant.html">Ant</a></li>
<li><a href="pmd_userdocs_tools_java_api.html">PMD Java API</a></li>
<li><a href="pmd_userdocs_tools_bld.html">bld PMD Extension</a></li>
<li><a href="pmd_userdocs_tools_ci.html">CI integrations</a></li>
<li><a href="pmd_userdocs_tools.html">Other Tools / Integrations</a></li>
</ul>
</li>
</ul>
</li>
<li>
<a href="#">Rule Reference</a>
<ul>
<li class="subfolders">
<a href="#">Apex Rules</a>
<ul>
<li><a href="pmd_rules_apex.html">Index</a></li>
<li><a href="pmd_rules_apex_bestpractices.html">Best Practices</a></li>
<li><a href="pmd_rules_apex_codestyle.html">Code Style</a></li>
<li><a href="pmd_rules_apex_design.html">Design</a></li>
<li><a href="pmd_rules_apex_documentation.html">Documentation</a></li>
<li><a href="pmd_rules_apex_errorprone.html">Error Prone</a></li>
<li><a href="pmd_rules_apex_performance.html">Performance</a></li>
<li><a href="pmd_rules_apex_security.html">Security</a></li>
</ul>
</li>
<li class="subfolders">
<a href="#">HTML Rules</a>
<ul>
<li><a href="pmd_rules_html.html">Index</a></li>
<li><a href="pmd_rules_html_bestpractices.html">Best Practices</a></li>
</ul>
</li>
<li class="subfolders">
<a href="#">Java Rules</a>
<ul>
<li class="active"><a href="pmd_rules_java.html">Index</a></li>
<li><a href="pmd_rules_java_bestpractices.html">Best Practices</a></li>
<li><a href="pmd_rules_java_codestyle.html">Code Style</a></li>
<li><a href="pmd_rules_java_design.html">Design</a></li>
<li><a href="pmd_rules_java_documentation.html">Documentation</a></li>
<li><a href="pmd_rules_java_errorprone.html">Error Prone</a></li>
<li><a href="pmd_rules_java_multithreading.html">Multithreading</a></li>
<li><a href="pmd_rules_java_performance.html">Performance</a></li>
<li><a href="pmd_rules_java_security.html">Security</a></li>
</ul>
</li>
<li class="subfolders">
<a href="#">Java Server Pages Rules</a>
<ul>
<li><a href="pmd_rules_jsp.html">Index</a></li>
<li><a href="pmd_rules_jsp_bestpractices.html">Best Practices</a></li>
<li><a href="pmd_rules_jsp_codestyle.html">Code Style</a></li>
<li><a href="pmd_rules_jsp_design.html">Design</a></li>
<li><a href="pmd_rules_jsp_errorprone.html">Error Prone</a></li>
<li><a href="pmd_rules_jsp_security.html">Security</a></li>
</ul>
</li>
<li class="subfolders">
<a href="#">JavaScript Rules</a>
<ul>
<li><a href="pmd_rules_ecmascript.html">Index</a></li>
<li><a href="pmd_rules_ecmascript_bestpractices.html">Best Practices</a></li>
<li><a href="pmd_rules_ecmascript_codestyle.html">Code Style</a></li>
<li><a href="pmd_rules_ecmascript_errorprone.html">Error Prone</a></li>
<li><a href="pmd_rules_ecmascript_performance.html">Performance</a></li>
</ul>
</li>
<li class="subfolders">
<a href="#">Kotlin Rules</a>
<ul>
<li><a href="pmd_rules_kotlin.html">Index</a></li>
<li><a href="pmd_rules_kotlin_bestpractices.html">Best Practices</a></li>
<li><a href="pmd_rules_kotlin_errorprone.html">Error Prone</a></li>
</ul>
</li>
<li class="subfolders">
<a href="#">Maven POM Rules</a>
<ul>
<li><a href="pmd_rules_pom.html">Index</a></li>
<li><a href="pmd_rules_pom_errorprone.html">Error Prone</a></li>
</ul>
</li>
<li class="subfolders">
<a href="#">Modelica Rules</a>
<ul>
<li><a href="pmd_rules_modelica.html">Index</a></li>
<li><a href="pmd_rules_modelica_bestpractices.html">Best Practices</a></li>
</ul>
</li>
<li class="subfolders">
<a href="#">PLSQL Rules</a>
<ul>
<li><a href="pmd_rules_plsql.html">Index</a></li>
<li><a href="pmd_rules_plsql_bestpractices.html">Best Practices</a></li>
<li><a href="pmd_rules_plsql_codestyle.html">Code Style</a></li>
<li><a href="pmd_rules_plsql_design.html">Design</a></li>
<li><a href="pmd_rules_plsql_errorprone.html">Error Prone</a></li>
</ul>
</li>
<li class="subfolders">
<a href="#">Salesforce Visualforce Rules</a>
<ul>
<li><a href="pmd_rules_visualforce.html">Index</a></li>
<li><a href="pmd_rules_visualforce_security.html">Security</a></li>
</ul>
</li>
<li class="subfolders">
<a href="#">Scala Rules</a>
<ul>
<li><a href="pmd_rules_scala.html">Index</a></li>
</ul>
</li>
<li class="subfolders">
<a href="#">Swift Rules</a>
<ul>
<li><a href="pmd_rules_swift.html">Index</a></li>
<li><a href="pmd_rules_swift_bestpractices.html">Best Practices</a></li>
<li><a href="pmd_rules_swift_errorprone.html">Error Prone</a></li>
</ul>
</li>
<li class="subfolders">
<a href="#">Velocity Template Language (VTL) Rules</a>
<ul>
<li><a href="pmd_rules_velocity.html">Index</a></li>
<li><a href="pmd_rules_velocity_bestpractices.html">Best Practices</a></li>
<li><a href="pmd_rules_velocity_design.html">Design</a></li>
<li><a href="pmd_rules_velocity_errorprone.html">Error Prone</a></li>
</ul>
</li>
<li class="subfolders">
<a href="#">WSDL Rules</a>
<ul>
<li><a href="pmd_rules_wsdl.html">Index</a></li>
</ul>
</li>
<li class="subfolders">
<a href="#">XML Rules</a>
<ul>
<li><a href="pmd_rules_xml.html">Index</a></li>
<li><a href="pmd_rules_xml_bestpractices.html">Best Practices</a></li>
<li><a href="pmd_rules_xml_errorprone.html">Error Prone</a></li>
</ul>
</li>
<li class="subfolders">
<a href="#">XSL Rules</a>
<ul>
<li><a href="pmd_rules_xsl.html">Index</a></li>
<li><a href="pmd_rules_xsl_codestyle.html">Code Style</a></li>
<li><a href="pmd_rules_xsl_performance.html">Performance</a></li>
</ul>
</li>
</ul>
</li>
<li>
<a href="#">Language-Specific Documentation</a>
<ul>
<li><a href="pmd_languages_index.html">Overview</a></li>
<li><a href="pmd_languages_configuration.html">Language configuration</a></li>
<li><a href="pmd_languages_apex.html">Apex</a></li>
<li><a href="pmd_languages_cpp.html">C/C++</a></li>
<li><a href="pmd_languages_cs.html">C#</a></li>
<li><a href="pmd_languages_coco.html">Coco</a></li>
<li><a href="pmd_languages_dart.html">Dart</a></li>
<li><a href="pmd_languages_fortran.html">Fortran</a></li>
<li><a href="pmd_languages_gherkin.html">Gherkin</a></li>
<li><a href="pmd_languages_go.html">Go</a></li>
<li><a href="pmd_languages_html.html">HTML</a></li>
<li><a href="pmd_languages_java.html">Java</a></li>
<li><a href="pmd_languages_js_ts.html">JavaScript / TypeScript</a></li>
<li><a href="pmd_languages_jsp.html">JSP</a></li>
<li><a href="pmd_languages_julia.html">Julia</a></li>
<li><a href="pmd_languages_kotlin.html">Kotlin</a></li>
<li><a href="pmd_languages_lua.html">Lua</a></li>
<li><a href="pmd_languages_matlab.html">Matlab</a></li>
<li><a href="pmd_languages_modelica.html">Modelica</a></li>
<li><a href="pmd_languages_objectivec.html">Objective-C</a></li>
<li><a href="pmd_languages_perl.html">Perl</a></li>
<li><a href="pmd_languages_php.html">PHP</a></li>
<li><a href="pmd_languages_plsql.html">PLSQL</a></li>
<li><a href="pmd_languages_python.html">Python</a></li>
<li><a href="pmd_languages_ruby.html">Ruby</a></li>
<li><a href="pmd_languages_scala.html">Scala</a></li>
<li><a href="pmd_languages_swift.html">Swift</a></li>
<li><a href="pmd_languages_tsql.html">T-SQL</a></li>
<li><a href="pmd_languages_visualforce.html">Visualforce</a></li>
<li><a href="pmd_languages_velocity.html">Velocity Template Language (VTL)</a></li>
<li><a href="pmd_languages_xml.html">XML and XML dialects</a></li>
</ul>
</li>
<li>
<a href="#">Developer Documentation</a>
<ul>
<li><a href="pmd_devdocs_development.html">Developer resources</a></li>
<li><a href="pmd_devdocs_building.html">Building PMD from source</a></li>
<li><a href="https://github.com/pmd/pmd/blob/main/CONTRIBUTING.md" target="_blank">Contributing</a></li>
<li><a href="pmd_devdocs_writing_documentation.html">Writing documentation</a></li>
<li><a href="pmd_devdocs_roadmap.html">Roadmap</a></li>
<li><a href="pmd_devdocs_how_pmd_works.html">How PMD works</a></li>
<li><a href="pmd_devdocs_pmdtester.html">Pmdtester</a></li>
<li><a href="pmd_devdocs_rule_deprecation_policy.html">Rule Deprecation Policy</a></li>
<li class="subfolders">
<a href="#">Major contributions</a>
<ul>
<li><a href="pmd_devdocs_major_rule_guidelines.html">Rule Guidelines</a></li>
<li><a href="pmd_devdocs_major_adding_new_language_javacc.html">Adding a new language (JavaCC)</a></li>
<li><a href="pmd_devdocs_major_adding_new_language_antlr.html">Adding a new language (ANTLR)</a></li>
<li><a href="pmd_devdocs_major_adding_new_cpd_language.html">Adding a new CPD language</a></li>
</ul>
</li>
<li class="subfolders">
<a href="#">Experimental features</a>
<ul>
<li><a href="tag_experimental.html">List of experimental Features</a></li>
</ul>
</li>
</ul>
</li>
<li>
<a href="#">Project documentation</a>
<ul>
<li class="subfolders">
<a href="#">Trivia about PMD</a>
<ul>
<li><a href="pmd_projectdocs_trivia_news.html">PMD in the press</a></li>
<li><a href="pmd_projectdocs_trivia_products.html">Products & books related to PMD</a></li>
<li><a href="pmd_projectdocs_trivia_similarprojects.html">Similar projects</a></li>
<li><a href="pmd_projectdocs_trivia_meaning.html">What does 'PMD' mean?</a></li>
</ul>
</li>
<li><a href="pmd_projectdocs_logo.html">Logo</a></li>
<li><a href="pmd_projectdocs_faq.html">FAQ</a></li>
<li><a href="license.html">License</a></li>
<li><a href="pmd_projectdocs_credits.html">Credits</a></li>
<li><a href="pmd_release_notes_old.html">Old release notes</a></li>
<li><a href="pmd_projectdocs_decisions.html">Decisions</a></li>
<li class="subfolders">
<a href="#">Project management</a>
<ul>
<li><a href="pmd_projectdocs_committers_infrastructure.html">Infrastructure</a></li>
<li><a href="pmd_projectdocs_committers_releasing.html">Release process</a></li>
<li><a href="pmd_projectdocs_committers_merging_pull_requests.html">Merging pull requests</a></li>
<li><a href="pmd_projectdocs_committers_main_landing_page.html">Main Landing page</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<!-- Content Column -->
<div class="col-md-9" id="tg-sb-content">
<header>
<div class="row">
<div class="col-lg-12">
<a href="./" role="button"
><i class="fa fa-home fa-lg"></i
></a>
» Java Rules
</div>
</div>
<hr />
</header>
<div class="post-header">
<h1 class="post-title-main">Java Rules</h1>
</div>
<div class="post-content" >
<div class="summary">Index of all built-in rules available for Java</div>
<details id="inline-toc-details">
<summary>Table of Contents</summary>
<div id="inline-toc"><!-- empty, move TOC here when screen size too small --></div>
</details>
<!-- DO NOT EDIT THIS FILE. This file is generated. -->
<h2 id="best-practices">Best Practices</h2>
<div class="bs-callout bs-callout-">Rules which enforce generally accepted best practices.</div>
<ul>
<li><a href="pmd_rules_java_bestpractices.html#abstractclasswithoutabstractmethod">AbstractClassWithoutAbstractMethod</a>: The abstract class does not contain any abstract methods. An abstract class suggests an incomplet…</li>
<li><a href="pmd_rules_java_bestpractices.html#accessorclassgeneration">AccessorClassGeneration</a>: Instantiation by way of private constructors from outside the constructors class often causes th…</li>
<li><a href="pmd_rules_java_bestpractices.html#accessormethodgeneration">AccessorMethodGeneration</a>: When accessing private fields / methods from another class, the Java compiler will generate acces…</li>
<li><a href="pmd_rules_java_bestpractices.html#arrayisstoreddirectly">ArrayIsStoredDirectly</a>: Constructors and methods receiving arrays should clone objects and store the copy. This prevents …</li>
<li><a href="pmd_rules_java_bestpractices.html#avoidmessagedigestfield">AvoidMessageDigestField</a>: Declaring a MessageDigest instance as a field make this instance directly available to multiple t…</li>
<li><a href="pmd_rules_java_bestpractices.html#avoidprintstacktrace">AvoidPrintStackTrace</a>: Avoid printStackTrace(); use a logger call instead.</li>
<li><a href="pmd_rules_java_bestpractices.html#avoidreassigningcatchvariables">AvoidReassigningCatchVariables</a>: Reassigning exception variables caught in a catch statement should be avoided because of: 1) If i…</li>
<li><a href="pmd_rules_java_bestpractices.html#avoidreassigningloopvariables">AvoidReassigningLoopVariables</a>: Reassigning loop variables can lead to hard-to-find bugs. Prevent or limit how these variables ca…</li>
<li><a href="pmd_rules_java_bestpractices.html#avoidreassigningparameters">AvoidReassigningParameters</a>: Reassigning values to incoming parameters of a method or constructor is not recommended, as this …</li>
<li><a href="pmd_rules_java_bestpractices.html#avoidstringbufferfield">AvoidStringBufferField</a>: StringBuffers/StringBuilders can grow considerably, and so may become a source of memory leaks if…</li>
<li><a href="pmd_rules_java_bestpractices.html#avoidusinghardcodedip">AvoidUsingHardCodedIP</a>: Application with hard-coded IP addresses can become impossible to deploy in some cases. Externali…</li>
<li><a href="pmd_rules_java_bestpractices.html#checkresultset">CheckResultSet</a>: Always check the return values of navigation methods (next, previous, first, last) of a ResultSet…</li>
<li><a href="pmd_rules_java_bestpractices.html#constantsininterface">ConstantsInInterface</a>: Using constants in interfaces is a bad practice. Interfaces define types, constants are implement…</li>
<li><a href="pmd_rules_java_bestpractices.html#defaultlabelnotlastinswitch">DefaultLabelNotLastInSwitch</a>: By convention, the default label should be the last label in a switch statement or switch express…</li>
<li><a href="pmd_rules_java_bestpractices.html#defaultlabelnotlastinswitchstmt">DefaultLabelNotLastInSwitchStmt</a>: <span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> The rule has been renamed. Use instead <a href="pmd_rules_java_bestpractices.html#defaultlabelnotlastinswitch">DefaultLabelNotLastInSwitch</a>.</li>
<li><a href="pmd_rules_java_bestpractices.html#doublebraceinitialization">DoubleBraceInitialization</a>: Double brace initialisation is a pattern to initialise eg collections concisely. But it implicitl…</li>
<li><a href="pmd_rules_java_bestpractices.html#forloopcanbeforeach">ForLoopCanBeForeach</a>: Reports loops that can be safely replaced with the foreach syntax. The rule considers loops over …</li>
<li><a href="pmd_rules_java_bestpractices.html#forloopvariablecount">ForLoopVariableCount</a>: Having a lot of control variables in a for loop makes it harder to see what range of values the…</li>
<li><a href="pmd_rules_java_bestpractices.html#guardlogstatement">GuardLogStatement</a>: Whenever using a log level, one should check if it is actually enabled, or otherwise skip the ass…</li>
<li><a href="pmd_rules_java_bestpractices.html#junit4suitesshouldusesuiteannotation">JUnit4SuitesShouldUseSuiteAnnotation</a>: In JUnit 3, test suites are indicated by the suite() method. In JUnit 4, suites are indicated thr…</li>
<li><a href="pmd_rules_java_bestpractices.html#junit4testshoulduseafterannotation">JUnit4TestShouldUseAfterAnnotation</a>: <span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> The rule has been renamed. Use instead <a href="pmd_rules_java_bestpractices.html#unittestshoulduseafterannotation">UnitTestShouldUseAfterAnnotation</a>.</li>
<li><a href="pmd_rules_java_bestpractices.html#junit4testshouldusebeforeannotation">JUnit4TestShouldUseBeforeAnnotation</a>: <span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> The rule has been renamed. Use instead <a href="pmd_rules_java_bestpractices.html#unittestshouldusebeforeannotation">UnitTestShouldUseBeforeAnnotation</a>.</li>
<li><a href="pmd_rules_java_bestpractices.html#junit4testshouldusetestannotation">JUnit4TestShouldUseTestAnnotation</a>: <span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> The rule has been renamed. Use instead <a href="pmd_rules_java_bestpractices.html#unittestshouldusetestannotation">UnitTestShouldUseTestAnnotation</a>.</li>
<li><a href="pmd_rules_java_bestpractices.html#junit5testshouldbepackageprivate">JUnit5TestShouldBePackagePrivate</a>: Reports JUnit 5 test classes and methods that are not package-private. Contrary to JUnit 4 tests,…</li>
<li><a href="pmd_rules_java_bestpractices.html#junitassertionsshouldincludemessage">JUnitAssertionsShouldIncludeMessage</a>: <span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> The rule has been renamed. Use instead <a href="pmd_rules_java_bestpractices.html#unittestassertionsshouldincludemessage">UnitTestAssertionsShouldIncludeMessage</a>.</li>
<li><a href="pmd_rules_java_bestpractices.html#junittestcontainstoomanyasserts">JUnitTestContainsTooManyAsserts</a>: <span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> The rule has been renamed. Use instead <a href="pmd_rules_java_bestpractices.html#unittestcontainstoomanyasserts">UnitTestContainsTooManyAsserts</a>.</li>
<li><a href="pmd_rules_java_bestpractices.html#junittestsshouldincludeassert">JUnitTestsShouldIncludeAssert</a>: <span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> The rule has been renamed. Use instead <a href="pmd_rules_java_bestpractices.html#unittestshouldincludeassert">UnitTestShouldIncludeAssert</a>.</li>
<li><a href="pmd_rules_java_bestpractices.html#junituseexpected">JUnitUseExpected</a>: In JUnit4, use the @Test(expected) annotation to denote tests that should throw exceptions.</li>
<li><a href="pmd_rules_java_bestpractices.html#literalsfirstincomparisons">LiteralsFirstInComparisons</a>: Position literals first in all String comparisons, if the second argument is null then NullPointe…</li>
<li><a href="pmd_rules_java_bestpractices.html#loosecoupling">LooseCoupling</a>: Excessive coupling to implementation types (e.g., HashSet) limits your ability to use alternate…</li>
<li><a href="pmd_rules_java_bestpractices.html#methodreturnsinternalarray">MethodReturnsInternalArray</a>: Exposing internal arrays to the caller violates object encapsulation since elements can be remove…</li>
<li><a href="pmd_rules_java_bestpractices.html#missingoverride">MissingOverride</a>: Annotating overridden methods with @Override ensures at compile time that the method …</li>
<li><a href="pmd_rules_java_bestpractices.html#nonexhaustiveswitch">NonExhaustiveSwitch</a>: Switch statements should be exhaustive, to make their control flow easier to follow. …</li>
<li><a href="pmd_rules_java_bestpractices.html#onedeclarationperline">OneDeclarationPerLine</a>: Java allows the use of several variables declaration of the same type on one line. However, it ca…</li>
<li><a href="pmd_rules_java_bestpractices.html#preservestacktrace">PreserveStackTrace</a>: Reports exceptions that are thrown from within a catch block, yet dont refer to the exception pa…</li>
<li><a href="pmd_rules_java_bestpractices.html#primitivewrapperinstantiation">PrimitiveWrapperInstantiation</a>: Reports usages of primitive wrapper constructors. They are deprecated since Java 9 an…</li>
<li><a href="pmd_rules_java_bestpractices.html#replaceenumerationwithiterator">ReplaceEnumerationWithIterator</a>: Consider replacing Enumeration usages with the newer java.util.Iterator</li>
<li><a href="pmd_rules_java_bestpractices.html#replacehashtablewithmap">ReplaceHashtableWithMap</a>: Consider replacing Hashtable usage with the newer java.util.Map if thread safety is not required.</li>
<li><a href="pmd_rules_java_bestpractices.html#replacevectorwithlist">ReplaceVectorWithList</a>: Consider replacing Vector usages with the newer java.util.ArrayList if expensive thread-safe oper…</li>
<li><a href="pmd_rules_java_bestpractices.html#simplifiabletestassertion">SimplifiableTestAssertion</a>: Reports test assertions that may be simplified using a more specific assertion method…</li>
<li><a href="pmd_rules_java_bestpractices.html#switchstmtsshouldhavedefault">SwitchStmtsShouldHaveDefault</a>: <span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> The rule has been renamed. Use instead <a href="pmd_rules_java_bestpractices.html#nonexhaustiveswitch">NonExhaustiveSwitch</a>.</li>
<li><a href="pmd_rules_java_bestpractices.html#systemprintln">SystemPrintln</a>: References to System.(out|err).print are usually intended for debugging purposes and can remain …</li>
<li><a href="pmd_rules_java_bestpractices.html#unittestassertionsshouldincludemessage">UnitTestAssertionsShouldIncludeMessage</a>: Unit assertions should include an informative message - i.e., use the three-argument version of ‘…</li>
<li><a href="pmd_rules_java_bestpractices.html#unittestcontainstoomanyasserts">UnitTestContainsTooManyAsserts</a>: Unit tests should not contain too many asserts. Many asserts are indicative of a complex test, fo…</li>
<li><a href="pmd_rules_java_bestpractices.html#unittestshouldincludeassert">UnitTestShouldIncludeAssert</a>: Unit tests should include at least one assertion. This makes the tests more robust, and using ass…</li>
<li><a href="pmd_rules_java_bestpractices.html#unittestshoulduseafterannotation">UnitTestShouldUseAfterAnnotation</a>: This rule detects methods called tearDown() that are not properly annotated as a cleanup method…</li>
<li><a href="pmd_rules_java_bestpractices.html#unittestshouldusebeforeannotation">UnitTestShouldUseBeforeAnnotation</a>: This rule detects methods called setUp() that are not properly annotated as a setup method. Thi…</li>
<li><a href="pmd_rules_java_bestpractices.html#unittestshouldusetestannotation">UnitTestShouldUseTestAnnotation</a>: The rule will detect any test method starting with "test" that is not properly annotated, and wil…</li>
<li><a href="pmd_rules_java_bestpractices.html#unnecessaryvarargsarraycreation">UnnecessaryVarargsArrayCreation</a>: Reports explicit array creation when a varargs is expected. For instance: …</li>
<li><a href="pmd_rules_java_bestpractices.html#unusedassignment">UnusedAssignment</a>: Reports assignments to variables that are never used before the variable is overwritten, …</li>
<li><a href="pmd_rules_java_bestpractices.html#unusedformalparameter">UnusedFormalParameter</a>: Reports parameters of methods and constructors that are not referenced them in the method body. P…</li>
<li><a href="pmd_rules_java_bestpractices.html#unusedlocalvariable">UnusedLocalVariable</a>: Detects when a local variable is declared and/or assigned, but not used. Variables whose name sta…</li>
<li><a href="pmd_rules_java_bestpractices.html#unusedprivatefield">UnusedPrivateField</a>: Detects when a private field is declared and/or assigned a value, but not used. Since PMD 6.50.0 …</li>
<li><a href="pmd_rules_java_bestpractices.html#unusedprivatemethod">UnusedPrivateMethod</a>: Unused Private Method detects when a private method is declared but is unused.</li>
<li><a href="pmd_rules_java_bestpractices.html#usecollectionisempty">UseCollectionIsEmpty</a>: The isEmpty() method on java.util.Collection is provided to determine if a collection has any ele…</li>
<li><a href="pmd_rules_java_bestpractices.html#useenumcollections">UseEnumCollections</a>: Wherever possible, use EnumSet or EnumMap instead of HashSet and HashMap when the keys …</li>
<li><a href="pmd_rules_java_bestpractices.html#usestandardcharsets">UseStandardCharsets</a>: Starting with Java 7, StandardCharsets provides constants for common Charset objects, such as UTF…</li>
<li><a href="pmd_rules_java_bestpractices.html#usetrywithresources">UseTryWithResources</a>: Java 7 introduced the try-with-resources statement. This statement ensures that each resource is …</li>
<li><a href="pmd_rules_java_bestpractices.html#usevarargs">UseVarargs</a>: Java 5 introduced the varargs parameter declaration for methods and constructors. This syntactic …</li>
<li><a href="pmd_rules_java_bestpractices.html#whileloopwithliteralboolean">WhileLoopWithLiteralBoolean</a>: do {} while (true); requires reading the end of the statement before it is apparent that it loo…</li>
</ul>
<h2 id="code-style">Code Style</h2>
<div class="bs-callout bs-callout-">Rules which enforce a specific coding style.</div>
<ul>
<li><a href="pmd_rules_java_codestyle.html#atleastoneconstructor">AtLeastOneConstructor</a>: Each non-static class should declare at least one constructor. Classes with solely static members…</li>
<li><a href="pmd_rules_java_codestyle.html#avoiddollarsigns">AvoidDollarSigns</a>: Avoid using dollar signs in variable/method/class/interface names.</li>
<li><a href="pmd_rules_java_codestyle.html#avoidprotectedfieldinfinalclass">AvoidProtectedFieldInFinalClass</a>: Do not use protected fields in final classes since they cannot be subclassed. Clarify your intent…</li>
<li><a href="pmd_rules_java_codestyle.html#avoidprotectedmethodinfinalclassnotextending">AvoidProtectedMethodInFinalClassNotExtending</a>: Do not use protected methods in most final classes since they cannot be subclassed. This should o…</li>
<li><a href="pmd_rules_java_codestyle.html#avoidusingnativecode">AvoidUsingNativeCode</a>: Unnecessary reliance on Java Native Interface (JNI) calls directly reduces application portabilit…</li>
<li><a href="pmd_rules_java_codestyle.html#booleangetmethodname">BooleanGetMethodName</a>: Methods that return boolean or Boolean results should be named as predicate statements to denote …</li>
<li><a href="pmd_rules_java_codestyle.html#callsuperinconstructor">CallSuperInConstructor</a>: It is a good practice to call super() in a constructor. If super() is not called but another cons…</li>
<li><a href="pmd_rules_java_codestyle.html#classnamingconventions">ClassNamingConventions</a>: Configurable naming conventions for type declarations. This rule reports type declara…</li>
<li><a href="pmd_rules_java_codestyle.html#commentdefaultaccessmodifier">CommentDefaultAccessModifier</a>: To avoid mistakes if we want that an Annotation, Class, Enum, Method, Constructor or Field have a…</li>
<li><a href="pmd_rules_java_codestyle.html#confusingternary">ConfusingTernary</a>: Avoid negation within an "if" expression with an "else" clause. For example, rephrase: if (x !=…</li>
<li><a href="pmd_rules_java_codestyle.html#controlstatementbraces">ControlStatementBraces</a>: Enforce a policy for braces on control statements. It is recommended to use braces on if … els…</li>
<li><a href="pmd_rules_java_codestyle.html#emptycontrolstatement">EmptyControlStatement</a>: Reports control statements whose body is empty, as well as empty initializers. The ch…</li>
<li><a href="pmd_rules_java_codestyle.html#emptymethodinabstractclassshouldbeabstract">EmptyMethodInAbstractClassShouldBeAbstract</a>: Empty or auto-generated methods in an abstract class should be tagged as abstract. This helps to …</li>
<li><a href="pmd_rules_java_codestyle.html#extendsobject">ExtendsObject</a>: No need to explicitly extend Object.</li>
<li><a href="pmd_rules_java_codestyle.html#fielddeclarationsshouldbeatstartofclass">FieldDeclarationsShouldBeAtStartOfClass</a>: Fields should be declared at the top of the class, before any method declarations, constructors, …</li>
<li><a href="pmd_rules_java_codestyle.html#fieldnamingconventions">FieldNamingConventions</a>: Configurable naming conventions for field declarations. This rule reports variable declarations …</li>
<li><a href="pmd_rules_java_codestyle.html#finalparameterinabstractmethod">FinalParameterInAbstractMethod</a>: Declaring a method parameter as final for an interface method is useless because the implementati…</li>
<li><a href="pmd_rules_java_codestyle.html#forloopshouldbewhileloop">ForLoopShouldBeWhileLoop</a>: Some for loops can be simplified to while loops, this makes them more concise.</li>
<li><a href="pmd_rules_java_codestyle.html#formalparameternamingconventions">FormalParameterNamingConventions</a>: Configurable naming conventions for formal parameters of methods and lambdas. This ru…</li>
<li><a href="pmd_rules_java_codestyle.html#genericsnaming">GenericsNaming</a>: Names for references to generic values should be limited to a single uppercase letter.</li>
<li><a href="pmd_rules_java_codestyle.html#identicalcatchbranches">IdenticalCatchBranches</a>: Identical catch branches use up vertical space and increase the complexity of code without …</li>
<li><a href="pmd_rules_java_codestyle.html#lambdacanbemethodreference">LambdaCanBeMethodReference</a>: This rule reports lambda expressions that can be written more succinctly as a method reference. T…</li>
<li><a href="pmd_rules_java_codestyle.html#linguisticnaming">LinguisticNaming</a>: This rule finds Linguistic Naming Antipatterns. It checks for fields, that are named, as if they …</li>
<li><a href="pmd_rules_java_codestyle.html#localhomenamingconvention">LocalHomeNamingConvention</a>: The Local Home interface of a Session EJB should be suffixed by LocalHome.</li>
<li><a href="pmd_rules_java_codestyle.html#localinterfacesessionnamingconvention">LocalInterfaceSessionNamingConvention</a>: The Local Interface of a Session EJB should be suffixed by Local.</li>
<li><a href="pmd_rules_java_codestyle.html#localvariablecouldbefinal">LocalVariableCouldBeFinal</a>: A local variable assigned only once can be declared final.</li>
<li><a href="pmd_rules_java_codestyle.html#localvariablenamingconventions">LocalVariableNamingConventions</a>: Configurable naming conventions for local variable declarations and other locally-scoped …</li>
<li><a href="pmd_rules_java_codestyle.html#longvariable">LongVariable</a>: Fields, formal arguments, or local variable names that are too long can make the code difficult t…</li>
<li><a href="pmd_rules_java_codestyle.html#mdbandsessionbeannamingconvention">MDBAndSessionBeanNamingConvention</a>: The EJB Specification states that any MessageDrivenBean or SessionBean should be suffixed by Bean.</li>
<li><a href="pmd_rules_java_codestyle.html#methodargumentcouldbefinal">MethodArgumentCouldBeFinal</a>: Reports method and constructor parameters that can be made final because they are never reassigne…</li>
<li><a href="pmd_rules_java_codestyle.html#methodnamingconventions">MethodNamingConventions</a>: Configurable naming conventions for method declarations. This rule reports method dec…</li>
<li><a href="pmd_rules_java_codestyle.html#nopackage">NoPackage</a>: Detects when a class, interface, enum or annotation does not have a package definition.</li>
<li><a href="pmd_rules_java_codestyle.html#onlyonereturn">OnlyOneReturn</a>: A method should have only one exit point, and that should be the last statement in the method.</li>
<li><a href="pmd_rules_java_codestyle.html#packagecase">PackageCase</a>: Detects when a package definition contains uppercase characters.</li>
<li><a href="pmd_rules_java_codestyle.html#prematuredeclaration">PrematureDeclaration</a>: Checks for variables that are defined before they might be used. A declaration is deemed to be pr…</li>
<li><a href="pmd_rules_java_codestyle.html#remoteinterfacenamingconvention">RemoteInterfaceNamingConvention</a>: Remote Interface of a Session EJB should not have a suffix.</li>
<li><a href="pmd_rules_java_codestyle.html#remotesessioninterfacenamingconvention">RemoteSessionInterfaceNamingConvention</a>: A Remote Home interface type of a Session EJB should be suffixed by Home.</li>
<li><a href="pmd_rules_java_codestyle.html#shortclassname">ShortClassName</a>: Short Classnames with fewer than e.g. five characters are not recommended.</li>
<li><a href="pmd_rules_java_codestyle.html#shortmethodname">ShortMethodName</a>: Method names that are very short are not helpful to the reader.</li>
<li><a href="pmd_rules_java_codestyle.html#shortvariable">ShortVariable</a>: Fields, local variables, enum constant names or parameter names that are very short are not helpf…</li>
<li><a href="pmd_rules_java_codestyle.html#toomanystaticimports">TooManyStaticImports</a>: If you overuse the static import feature, it can make your program unreadable and unmaintainable,…</li>
<li><a href="pmd_rules_java_codestyle.html#unnecessaryannotationvalueelement">UnnecessaryAnnotationValueElement</a>: Avoid the use of value in annotations when its the only element.</li>
<li><a href="pmd_rules_java_codestyle.html#unnecessaryboxing">UnnecessaryBoxing</a>: Reports explicit boxing and unboxing conversions that may safely be removed, either b…</li>
<li><a href="pmd_rules_java_codestyle.html#unnecessarycast">UnnecessaryCast</a>: Detects casts which could be removed as the operand of the cast is already suitable for the conte…</li>
<li><a href="pmd_rules_java_codestyle.html#unnecessaryconstructor">UnnecessaryConstructor</a>: This rule detects when a constructor is not necessary; i.e., when there is only one constructor a…</li>
<li><a href="pmd_rules_java_codestyle.html#unnecessaryfullyqualifiedname">UnnecessaryFullyQualifiedName</a>: Import statements allow the use of non-fully qualified names. The use of a fully qualified name …</li>
<li><a href="pmd_rules_java_codestyle.html#unnecessaryimport">UnnecessaryImport</a>: Reports import statements that can be removed. They are either unused, duplicated, or…</li>
<li><a href="pmd_rules_java_codestyle.html#unnecessarylocalbeforereturn">UnnecessaryLocalBeforeReturn</a>: Avoid the creation of unnecessary local variables</li>
<li><a href="pmd_rules_java_codestyle.html#unnecessarymodifier">UnnecessaryModifier</a>: Fields in interfaces and annotations are automatically public static final, and methods are pu…</li>
<li><a href="pmd_rules_java_codestyle.html#unnecessaryreturn">UnnecessaryReturn</a>: Avoid the use of unnecessary return statements. A return is unnecessary when no instructions foll…</li>
<li><a href="pmd_rules_java_codestyle.html#unnecessarysemicolon">UnnecessarySemicolon</a>: Reports unnecessary semicolons (so called "empty statements" and "empty declarations"). …</li>
<li><a href="pmd_rules_java_codestyle.html#usediamondoperator">UseDiamondOperator</a>: In some cases, explicit type arguments in a constructor call for a generic type may be replaced b…</li>
<li><a href="pmd_rules_java_codestyle.html#useexplicittypes">UseExplicitTypes</a>: Java 10 introduced the var keyword. This reduces the amount of code written because java can in…</li>
<li><a href="pmd_rules_java_codestyle.html#uselessparentheses">UselessParentheses</a>: Parenthesized expressions are used to override the default operator precedence rules….</li>
<li><a href="pmd_rules_java_codestyle.html#uselessqualifiedthis">UselessQualifiedThis</a>: Reports qualified this usages in the same class.</li>
<li><a href="pmd_rules_java_codestyle.html#useshortarrayinitializer">UseShortArrayInitializer</a>: When declaring and initializing array fields or variables, it is not necessary to explicitly crea…</li>
<li><a href="pmd_rules_java_codestyle.html#useunderscoresinnumericliterals">UseUnderscoresInNumericLiterals</a>: Since Java 1.7, numeric literals can use underscores to separate digits. This rule enforces that …</li>
</ul>
<h2 id="design">Design</h2>
<div class="bs-callout bs-callout-">Rules that help you discover design issues.</div>
<ul>
<li><a href="pmd_rules_java_design.html#abstractclasswithoutanymethod">AbstractClassWithoutAnyMethod</a>: If an abstract class does not provide any methods, it may be acting as a simple data container th…</li>
<li><a href="pmd_rules_java_design.html#avoidcatchinggenericexception">AvoidCatchingGenericException</a>: Avoid catching generic exceptions such as NullPointerException, RuntimeException, Exception in tr…</li>
<li><a href="pmd_rules_java_design.html#avoiddeeplynestedifstmts">AvoidDeeplyNestedIfStmts</a>: Avoid creating deeply nested if-then statements since they are harder to read and error-prone to …</li>
<li><a href="pmd_rules_java_design.html#avoidrethrowingexception">AvoidRethrowingException</a>: Catch blocks that merely rethrow a caught exception only add to code size and runtime complexity.</li>
<li><a href="pmd_rules_java_design.html#avoidthrowingnewinstanceofsameexception">AvoidThrowingNewInstanceOfSameException</a>: Catch blocks that merely rethrow a caught exception wrapped inside a new instance of the same typ…</li>
<li><a href="pmd_rules_java_design.html#avoidthrowingnullpointerexception">AvoidThrowingNullPointerException</a>: Avoid throwing NullPointerExceptions manually. These are confusing because most people will assum…</li>
<li><a href="pmd_rules_java_design.html#avoidthrowingrawexceptiontypes">AvoidThrowingRawExceptionTypes</a>: Avoid throwing certain exception types. Rather than throw a raw RuntimeException, Throwable, Exce…</li>
<li><a href="pmd_rules_java_design.html#avoiduncheckedexceptionsinsignatures">AvoidUncheckedExceptionsInSignatures</a>: Reports unchecked exceptions in the throws clause of a method or constructor. Java doesnt forc…</li>
<li><a href="pmd_rules_java_design.html#classwithonlyprivateconstructorsshouldbefinal">ClassWithOnlyPrivateConstructorsShouldBeFinal</a>: Reports classes that may be made final because they cannot be extended from outside their compila…</li>
<li><a href="pmd_rules_java_design.html#cognitivecomplexity">CognitiveComplexity</a>: Methods that are highly complex are difficult to read and more costly to maintain. If you include…</li>
<li><a href="pmd_rules_java_design.html#collapsibleifstatements">CollapsibleIfStatements</a>: Reports nested if statements that can be merged together by joining their conditions with a boo…</li>
<li><a href="pmd_rules_java_design.html#couplingbetweenobjects">CouplingBetweenObjects</a>: This rule counts the number of unique attributes, local variables, and return types within an obj…</li>
<li><a href="pmd_rules_java_design.html#cyclomaticcomplexity">CyclomaticComplexity</a>: The complexity of methods directly affects maintenance costs and readability. Concentrating too m…</li>
<li><a href="pmd_rules_java_design.html#dataclass">DataClass</a>: Data Classes are simple data holders, which reveal most of their state, and without complex funct…</li>
<li><a href="pmd_rules_java_design.html#donotextendjavalangerror">DoNotExtendJavaLangError</a>: Errors are system exceptions. Do not extend them.</li>
<li><a href="pmd_rules_java_design.html#exceptionasflowcontrol">ExceptionAsFlowControl</a>: This rule reports exceptions thrown and caught in an enclosing try statement. This use of excepti…</li>
<li><a href="pmd_rules_java_design.html#excessiveimports">ExcessiveImports</a>: A high number of imports can indicate a high degree of coupling within an object. This rule count…</li>
<li><a href="pmd_rules_java_design.html#excessiveparameterlist">ExcessiveParameterList</a>: Methods with numerous parameters are a challenge to maintain, especially if most of them share th…</li>
<li><a href="pmd_rules_java_design.html#excessivepubliccount">ExcessivePublicCount</a>: Classes with large numbers of public methods and attributes require disproportionate testing effo…</li>
<li><a href="pmd_rules_java_design.html#finalfieldcouldbestatic">FinalFieldCouldBeStatic</a>: If a final field is assigned to a compile-time constant, it could be made static, thus saving ove…</li>
<li><a href="pmd_rules_java_design.html#godclass">GodClass</a>: The God Class rule detects the God Class design flaw using metrics. God classes do too many thing…</li>
<li><a href="pmd_rules_java_design.html#immutablefield">ImmutableField</a>: Reports non-final fields whose value never changes once object initialization ends, and hence may…</li>
<li><a href="pmd_rules_java_design.html#invalidjavabean">InvalidJavaBean</a>: Identifies beans, that dont follow the [JavaBeans API specification](https://download.oracle.com…</li>
<li><a href="pmd_rules_java_design.html#lawofdemeter">LawOfDemeter</a>: The law of Demeter is a simple rule that says "only talk to friends". It forbids fetching data fr…</li>
<li><a href="pmd_rules_java_design.html#logicinversion">LogicInversion</a>: Use opposite operator instead of negating the whole expression with a logic complement operator.</li>
<li><a href="pmd_rules_java_design.html#loosepackagecoupling">LoosePackageCoupling</a>: Avoid using classes from the configured package hierarchy outside of the package hierarchy, excep…</li>
<li><a href="pmd_rules_java_design.html#mutablestaticstate">MutableStaticState</a>: Non-private static fields should be made constants (or immutable references) by declaring them fi…</li>
<li><a href="pmd_rules_java_design.html#ncsscount">NcssCount</a>: This rule uses the NCSS (Non-Commenting Source Statements) metric to determine the number of line…</li>
<li><a href="pmd_rules_java_design.html#npathcomplexity">NPathComplexity</a>: The NPath complexity of a method is the number of acyclic execution paths through that method. Wh…</li>
<li><a href="pmd_rules_java_design.html#signaturedeclarethrowsexception">SignatureDeclareThrowsException</a>: A method/constructor shouldnt explicitly throw the generic java.lang.Exception, since it is uncl…</li>
<li><a href="pmd_rules_java_design.html#simplifiedternary">SimplifiedTernary</a>: Reports ternary expression with the form condition ? literalBoolean : foo or condition ? foo :…</li>
<li><a href="pmd_rules_java_design.html#simplifybooleanexpressions">SimplifyBooleanExpressions</a>: Avoid unnecessary comparisons in boolean expressions, they serve no purpose and impacts readability.</li>
<li><a href="pmd_rules_java_design.html#simplifybooleanreturns">SimplifyBooleanReturns</a>: Avoid unnecessary if-then-else statements when returning a boolean. The result of the conditional…</li>
<li><a href="pmd_rules_java_design.html#simplifyconditional">SimplifyConditional</a>: No need to check for null before an instanceof; the instanceof keyword returns false when given a…</li>
<li><a href="pmd_rules_java_design.html#singularfield">SingularField</a>: Reports fields which may be converted to a local variable. This is so because in every method whe…</li>
<li><a href="pmd_rules_java_design.html#switchdensity">SwitchDensity</a>: A high ratio of statements to labels in a switch statement implies that the switch statement is o…</li>
<li><a href="pmd_rules_java_design.html#toomanyfields">TooManyFields</a>: Classes that have too many fields can become unwieldy and could be redesigned to have fewer field…</li>
<li><a href="pmd_rules_java_design.html#toomanymethods">TooManyMethods</a>: A class with too many methods is probably a good suspect for refactoring, in order to reduce its …</li>
<li><a href="pmd_rules_java_design.html#uselessoverridingmethod">UselessOverridingMethod</a>: The overriding method merely calls the same method defined in a superclass.</li>
<li><a href="pmd_rules_java_design.html#useobjectforclearerapi">UseObjectForClearerAPI</a>: When you write a public method, you should be thinking in terms of an API. If your method is publ…</li>
<li><a href="pmd_rules_java_design.html#useutilityclass">UseUtilityClass</a>: For classes that only have static methods, consider making them utility classes. Note that this d…</li>
</ul>
<h2 id="documentation">Documentation</h2>
<div class="bs-callout bs-callout-">Rules that are related to code documentation.</div>
<ul>
<li><a href="pmd_rules_java_documentation.html#commentcontent">CommentContent</a>: A rule for the politically correct… we dont want to offend anyone.</li>
<li><a href="pmd_rules_java_documentation.html#commentrequired">CommentRequired</a>: Denotes whether javadoc (formal) comments are required (or unwanted) for specific language elements.</li>
<li><a href="pmd_rules_java_documentation.html#commentsize">CommentSize</a>: Determines whether the dimensions of non-header comments found are within the specified limits.</li>
<li><a href="pmd_rules_java_documentation.html#uncommentedemptyconstructor">UncommentedEmptyConstructor</a>: Uncommented Empty Constructor finds instances where a constructor does not contain statements, bu…</li>
<li><a href="pmd_rules_java_documentation.html#uncommentedemptymethodbody">UncommentedEmptyMethodBody</a>: Uncommented Empty Method Body finds instances where a method body does not contain statements, bu…</li>
</ul>
<h2 id="error-prone">Error Prone</h2>
<div class="bs-callout bs-callout-">Rules to detect constructs that are either broken, extremely confusing or prone to runtime errors.</div>
<ul>
<li><a href="pmd_rules_java_errorprone.html#assignmentinoperand">AssignmentInOperand</a>: Avoid assignments in operands; this can make code more complicated and harder to read.</li>
<li><a href="pmd_rules_java_errorprone.html#assignmenttononfinalstatic">AssignmentToNonFinalStatic</a>: Identifies a possible unsafe usage of a static field.</li>
<li><a href="pmd_rules_java_errorprone.html#avoidaccessibilityalteration">AvoidAccessibilityAlteration</a>: Methods such as getDeclaredConstructors(), getDeclaredMethods(), and getDeclaredFields() al…</li>
<li><a href="pmd_rules_java_errorprone.html#avoidassertasidentifier">AvoidAssertAsIdentifier</a>: Use of the term assert will conflict with newer versions of Java since it is a reserved word. S…</li>
<li><a href="pmd_rules_java_errorprone.html#avoidbranchingstatementaslastinloop">AvoidBranchingStatementAsLastInLoop</a>: Using a branching statement as the last part of a loop may be a bug, and/or is confusing. Ensure …</li>
<li><a href="pmd_rules_java_errorprone.html#avoidcallingfinalize">AvoidCallingFinalize</a>: The method Object.finalize() is called by the garbage collector on an object when garbage collect…</li>
<li><a href="pmd_rules_java_errorprone.html#avoidcatchingnpe">AvoidCatchingNPE</a>: Code should never throw NullPointerExceptions under normal circumstances. A catch block may hide…</li>
<li><a href="pmd_rules_java_errorprone.html#avoidcatchingthrowable">AvoidCatchingThrowable</a>: Catching Throwable errors is not recommended since its scope is very broad. It includes runtime i…</li>
<li><a href="pmd_rules_java_errorprone.html#avoiddecimalliteralsinbigdecimalconstructor">AvoidDecimalLiteralsInBigDecimalConstructor</a>: One might assume that the result of "new BigDecimal(0.1)" is exactly equal to 0.1, but it is actu…</li>
<li><a href="pmd_rules_java_errorprone.html#avoidduplicateliterals">AvoidDuplicateLiterals</a>: Code containing duplicate String literals can usually be improved by declaring the String as a co…</li>
<li><a href="pmd_rules_java_errorprone.html#avoidenumasidentifier">AvoidEnumAsIdentifier</a>: Use of the term enum will conflict with newer versions of Java since it is a reserved word. Sin…</li>
<li><a href="pmd_rules_java_errorprone.html#avoidfieldnamematchingmethodname">AvoidFieldNameMatchingMethodName</a>: It can be confusing to have a field name with the same name as a method. While this is permitted,…</li>
<li><a href="pmd_rules_java_errorprone.html#avoidfieldnamematchingtypename">AvoidFieldNameMatchingTypeName</a>: It is somewhat confusing to have a field name matching the declaring type name. This probably mea…</li>
<li><a href="pmd_rules_java_errorprone.html#avoidinstanceofchecksincatchclause">AvoidInstanceofChecksInCatchClause</a>: Each caught exception type should be handled in its own catch clause.</li>
<li><a href="pmd_rules_java_errorprone.html#avoidliteralsinifcondition">AvoidLiteralsInIfCondition</a>: Avoid using hard-coded literals in conditional statements. By declaring them as static variables …</li>
<li><a href="pmd_rules_java_errorprone.html#avoidlosingexceptioninformation">AvoidLosingExceptionInformation</a>: Statements in a catch block that invoke accessors on the exception without using the information …</li>
<li><a href="pmd_rules_java_errorprone.html#avoidmultipleunaryoperators">AvoidMultipleUnaryOperators</a>: The use of multiple unary operators may be problematic, and/or confusing. Ensure that the intende…</li>
<li><a href="pmd_rules_java_errorprone.html#avoidusingoctalvalues">AvoidUsingOctalValues</a>: Integer literals should not start with zero since this denotes that the rest of literal will be i…</li>
<li><a href="pmd_rules_java_errorprone.html#brokennullcheck">BrokenNullCheck</a>: The null check is broken since it will throw a NullPointerException itself. It is likely that you…</li>
<li><a href="pmd_rules_java_errorprone.html#callsuperfirst">CallSuperFirst</a>: Super should be called at the start of the method</li>
<li><a href="pmd_rules_java_errorprone.html#callsuperlast">CallSuperLast</a>: Super should be called at the end of the method</li>
<li><a href="pmd_rules_java_errorprone.html#checkskipresult">CheckSkipResult</a>: The skip() method may skip a smaller number of bytes than requested. Check the returned value to …</li>
<li><a href="pmd_rules_java_errorprone.html#classcastexceptionwithtoarray">ClassCastExceptionWithToArray</a>: When deriving an array of a specific class from your Collection, one should provide an array of t…</li>
<li><a href="pmd_rules_java_errorprone.html#clonemethodmustbepublic">CloneMethodMustBePublic</a>: The java manual says "By convention, classes that implement this interface should override Object…</li>
<li><a href="pmd_rules_java_errorprone.html#clonemethodmustimplementcloneable">CloneMethodMustImplementCloneable</a>: The method clone() should only be implemented if the class implements the Cloneable interface wit…</li>
<li><a href="pmd_rules_java_errorprone.html#clonemethodreturntypemustmatchclassname">CloneMethodReturnTypeMustMatchClassName</a>: If a class implements Cloneable the return type of the method clone() must be the class name….</li>
<li><a href="pmd_rules_java_errorprone.html#closeresource">CloseResource</a>: Ensure that resources (like java.sql.Connection, java.sql.Statement, and java.sql.ResultSet</li>
<li><a href="pmd_rules_java_errorprone.html#compareobjectswithequals">CompareObjectsWithEquals</a>: Use equals() to compare object references; avoid comparing them with ==. Since comparing obje…</li>
<li><a href="pmd_rules_java_errorprone.html#comparisonwithnan">ComparisonWithNaN</a>: Reports comparisons with double and float NaN (Not-a-Number) values. These are [spe…</li>
<li><a href="pmd_rules_java_errorprone.html#confusingargumenttovarargsmethod">ConfusingArgumentToVarargsMethod</a>: Reports a confusing argument passed to a varargs method. This can occur when an array…</li>
<li><a href="pmd_rules_java_errorprone.html#constructorcallsoverridablemethod">ConstructorCallsOverridableMethod</a>: Reports calls to overridable methods on this during object initialization. These are invoked on…</li>
<li><a href="pmd_rules_java_errorprone.html#detachedtestcase">DetachedTestCase</a>: The method appears to be a test case since it has public or default visibility, non-static access…</li>
<li><a href="pmd_rules_java_errorprone.html#donotcallgarbagecollectionexplicitly">DoNotCallGarbageCollectionExplicitly</a>: Calls to System.gc(), Runtime.getRuntime().gc(), and System.runFinalization() are not advis…</li>
<li><a href="pmd_rules_java_errorprone.html#donotextendjavalangthrowable">DoNotExtendJavaLangThrowable</a>: Extend Exception or RuntimeException instead of Throwable.</li>
<li><a href="pmd_rules_java_errorprone.html#donothardcodesdcard">DoNotHardCodeSDCard</a>: Use Environment.getExternalStorageDirectory() instead of "/sdcard"</li>
<li><a href="pmd_rules_java_errorprone.html#donotterminatevm">DoNotTerminateVM</a>: Web applications should not call System.exit(), since only the web container or the application…</li>
<li><a href="pmd_rules_java_errorprone.html#donotthrowexceptioninfinally">DoNotThrowExceptionInFinally</a>: Throwing exceptions within a finally block is confusing since they may mask other exceptions or…</li>
<li><a href="pmd_rules_java_errorprone.html#dontimportsun">DontImportSun</a>: Avoid importing anything from the sun. packages. These packages are not portable and are likely…</li>
<li><a href="pmd_rules_java_errorprone.html#dontusefloattypeforloopindices">DontUseFloatTypeForLoopIndices</a>: Dont use floating point for loop indices. If you must use floating point, use double unless you</li>
<li><a href="pmd_rules_java_errorprone.html#emptycatchblock">EmptyCatchBlock</a>: Empty Catch Block finds instances where an exception is caught, but nothing is done. In most circ…</li>
<li><a href="pmd_rules_java_errorprone.html#emptyfinalizer">EmptyFinalizer</a>: Empty finalize methods serve no purpose and should be removed. Note that Oracle has declared Obje…</li>
<li><a href="pmd_rules_java_errorprone.html#equalsnull">EqualsNull</a>: Tests for null should not use the equals() method. The == operator should be used instead.</li>
<li><a href="pmd_rules_java_errorprone.html#finalizedoesnotcallsuperfinalize">FinalizeDoesNotCallSuperFinalize</a>: If the finalize() is implemented, its last action should be to call super.finalize. Note that Ora…</li>
<li><a href="pmd_rules_java_errorprone.html#finalizeonlycallssuperfinalize">FinalizeOnlyCallsSuperFinalize</a>: If the finalize() is implemented, it should do something besides just calling super.finalize(). N…</li>
<li><a href="pmd_rules_java_errorprone.html#finalizeoverloaded">FinalizeOverloaded</a>: Methods named finalize() should not have parameters. It is confusing and most likely an attempt …</li>
<li><a href="pmd_rules_java_errorprone.html#finalizeshouldbeprotected">FinalizeShouldBeProtected</a>: When overriding the finalize(), the new method should be set as protected. If made public, other…</li>
<li><a href="pmd_rules_java_errorprone.html#idempotentoperations">IdempotentOperations</a>: Avoid idempotent operations - they have no effect.</li>
<li><a href="pmd_rules_java_errorprone.html#implicitswitchfallthrough">ImplicitSwitchFallThrough</a>: Switch statements without break or return statements for each case option may indicate problemati…</li>
<li><a href="pmd_rules_java_errorprone.html#instantiationtogetclass">InstantiationToGetClass</a>: Avoid instantiating an object just to call getClass() on it; use the .class public member instead.</li>
<li><a href="pmd_rules_java_errorprone.html#invalidlogmessageformat">InvalidLogMessageFormat</a>: Check for messages in slf4j and log4j2 (since 6.19.0) loggers with non matching number of argumen…</li>
<li><a href="pmd_rules_java_errorprone.html#jumbledincrementer">JumbledIncrementer</a>: Avoid jumbled loop incrementers - its usually a mistake, and is confusing even if intentional.</li>
<li><a href="pmd_rules_java_errorprone.html#junitspelling">JUnitSpelling</a>: In JUnit 3, the setUp method is used to set up all data entities required in running tests. …</li>
<li><a href="pmd_rules_java_errorprone.html#junitstaticsuite">JUnitStaticSuite</a>: The suite() method in a JUnit test needs to be both public and static.</li>
<li><a href="pmd_rules_java_errorprone.html#methodwithsamenameasenclosingclass">MethodWithSameNameAsEnclosingClass</a>: A method should not have the same name as its containing class. This would be confusing as it wou…</li>
<li><a href="pmd_rules_java_errorprone.html#misplacednullcheck">MisplacedNullCheck</a>: The null check here is misplaced. If the variable is null a NullPointerException will be thrown…</li>
<li><a href="pmd_rules_java_errorprone.html#missingserialversionuid">MissingSerialVersionUID</a>: Serializable classes should provide a serialVersionUID field. The serialVersionUID field is also …</li>
<li><a href="pmd_rules_java_errorprone.html#missingstaticmethodinnoninstantiatableclass">MissingStaticMethodInNonInstantiatableClass</a>: A class that has private constructors and does not have any static methods or fields cannot be us…</li>
<li><a href="pmd_rules_java_errorprone.html#morethanonelogger">MoreThanOneLogger</a>: Normally only one logger is used in each class. This rule supports slf4j, log4j, Java Util Loggin…</li>
<li><a href="pmd_rules_java_errorprone.html#noncaselabelinswitch">NonCaseLabelInSwitch</a>: A non-case label (e.g. a named break/continue label) was present in a switch statement or switch …</li>
<li><a href="pmd_rules_java_errorprone.html#noncaselabelinswitchstatement">NonCaseLabelInSwitchStatement</a>: <span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> The rule has been renamed. Use instead <a href="pmd_rules_java_errorprone.html#noncaselabelinswitch">NonCaseLabelInSwitch</a>.</li>
<li><a href="pmd_rules_java_errorprone.html#nonserializableclass">NonSerializableClass</a>: If a class is marked as Serializable, then all fields need to be serializable as well. In order…</li>
<li><a href="pmd_rules_java_errorprone.html#nonstaticinitializer">NonStaticInitializer</a>: A non-static initializer block will be called any time a constructor is invoked (just prior to in…</li>
<li><a href="pmd_rules_java_errorprone.html#nullassignment">NullAssignment</a>: Assigning a "null" to a variable (outside of its declaration) is usually bad form. Sometimes, th…</li>
<li><a href="pmd_rules_java_errorprone.html#overridebothequalsandhashcode">OverrideBothEqualsAndHashcode</a>: Override both public boolean Object.equals(Object other), and public int Object.hashCode(), or ov…</li>
<li><a href="pmd_rules_java_errorprone.html#propercloneimplementation">ProperCloneImplementation</a>: Object clone() should be implemented with super.clone().</li>
<li><a href="pmd_rules_java_errorprone.html#properlogger">ProperLogger</a>: A logger should normally be defined private static final and be associated with the correct class…</li>
<li><a href="pmd_rules_java_errorprone.html#returnemptycollectionratherthannull">ReturnEmptyCollectionRatherThanNull</a>: For any method that returns an collection (such as an array, Collection or Map), it is better to …</li>
<li><a href="pmd_rules_java_errorprone.html#returnfromfinallyblock">ReturnFromFinallyBlock</a>: Avoid returning from a finally block, this can discard exceptions.</li>
<li><a href="pmd_rules_java_errorprone.html#simpledateformatneedslocale">SimpleDateFormatNeedsLocale</a>: Be sure to specify a Locale when creating SimpleDateFormat instances to ensure that locale-approp…</li>
<li><a href="pmd_rules_java_errorprone.html#singlemethodsingleton">SingleMethodSingleton</a>: Some classes contain overloaded getInstance. The problem with overloaded getInstance methods is t…</li>
<li><a href="pmd_rules_java_errorprone.html#singletonclassreturningnewinstance">SingletonClassReturningNewInstance</a>: A singleton class should only ever have one instance. Failure to check whether an ins…</li>
<li><a href="pmd_rules_java_errorprone.html#staticejbfieldshouldbefinal">StaticEJBFieldShouldBeFinal</a>: According to the J2EE specification, an EJB should not have any static fields with write access. …</li>
<li><a href="pmd_rules_java_errorprone.html#stringbufferinstantiationwithchar">StringBufferInstantiationWithChar</a>: Individual character values provided as initialization arguments will be converted into integers….</li>
<li><a href="pmd_rules_java_errorprone.html#suspiciousequalsmethodname">SuspiciousEqualsMethodName</a>: The method name and parameter number are suspiciously close to Object.equals, which can denote …</li>
<li><a href="pmd_rules_java_errorprone.html#suspicioushashcodemethodname">SuspiciousHashcodeMethodName</a>: The method name and return type are suspiciously close to hashCode(), which may denote an intenti…</li>
<li><a href="pmd_rules_java_errorprone.html#suspiciousoctalescape">SuspiciousOctalEscape</a>: A suspicious octal escape sequence was found inside a String literal. The Java language specifica…</li>
<li><a href="pmd_rules_java_errorprone.html#testclasswithouttestcases">TestClassWithoutTestCases</a>: Test classes typically end with the suffix "Test", "Tests" or "TestCase". Having a non-test class…</li>
<li><a href="pmd_rules_java_errorprone.html#unconditionalifstatement">UnconditionalIfStatement</a>: Do not use "if" statements whose conditionals are always true or always false.</li>
<li><a href="pmd_rules_java_errorprone.html#unnecessarybooleanassertion">UnnecessaryBooleanAssertion</a>: A JUnit test assertion with a boolean literal is unnecessary since it always will evaluate to the…</li>
<li><a href="pmd_rules_java_errorprone.html#unnecessarycasechange">UnnecessaryCaseChange</a>: Using equalsIgnoreCase() is faster than using toUpperCase/toLowerCase().equals()</li>
<li><a href="pmd_rules_java_errorprone.html#unnecessaryconversiontemporary">UnnecessaryConversionTemporary</a>: Avoid the use temporary objects when converting primitives to Strings. Use the static conversion …</li>
<li><a href="pmd_rules_java_errorprone.html#unusednullcheckinequals">UnusedNullCheckInEquals</a>: After checking an object reference for null, you should invoke equals() on that object rather tha…</li>
<li><a href="pmd_rules_java_errorprone.html#usecorrectexceptionlogging">UseCorrectExceptionLogging</a>: To make sure the full stacktrace is printed out, use the logging statement with two arguments: a …</li>
<li><a href="pmd_rules_java_errorprone.html#useequalstocomparestrings">UseEqualsToCompareStrings</a>: Using == or != to compare strings is only reliable if the interned string (String#intern())…</li>
<li><a href="pmd_rules_java_errorprone.html#uselessoperationonimmutable">UselessOperationOnImmutable</a>: An operation on an immutable object will not change the object itself since the result of the ope…</li>
<li><a href="pmd_rules_java_errorprone.html#uselocalewithcaseconversions">UseLocaleWithCaseConversions</a>: When doing String::toLowerCase()/toUpperCase() conversions, use an explicit locale argument to …</li>
<li><a href="pmd_rules_java_errorprone.html#useproperclassloader">UseProperClassLoader</a>: In J2EE, the getClassLoader() method might not work as expected. Use Thread.currentThread().getCo…</li>
</ul>
<h2 id="multithreading">Multithreading</h2>
<div class="bs-callout bs-callout-">Rules that flag issues when dealing with multiple threads of execution.</div>
<ul>
<li><a href="pmd_rules_java_multithreading.html#avoidsynchronizedatmethodlevel">AvoidSynchronizedAtMethodLevel</a>: Method-level synchronization will pin virtual threads and can cause performance problems. Additio…</li>
<li><a href="pmd_rules_java_multithreading.html#avoidsynchronizedstatement">AvoidSynchronizedStatement</a>: Synchronization will pin virtual threads and can cause performance problems.</li>
<li><a href="pmd_rules_java_multithreading.html#avoidthreadgroup">AvoidThreadGroup</a>: Avoid using java.lang.ThreadGroup; although it is intended to be used in a threaded environment i…</li>
<li><a href="pmd_rules_java_multithreading.html#avoidusingvolatile">AvoidUsingVolatile</a>: Use of the keyword volatile is generally used to fine tune a Java application, and therefore, r…</li>
<li><a href="pmd_rules_java_multithreading.html#donotusethreads">DoNotUseThreads</a>: The J2EE specification explicitly forbids the use of threads. Threads are resources, that should …</li>
<li><a href="pmd_rules_java_multithreading.html#dontcallthreadrun">DontCallThreadRun</a>: Explicitly calling Thread.run() method will execute in the callers thread of control. Instead, …</li>
<li><a href="pmd_rules_java_multithreading.html#doublecheckedlocking">DoubleCheckedLocking</a>: Partially created objects can be returned by the Double Checked Locking pattern when used in Java…</li>
<li><a href="pmd_rules_java_multithreading.html#nonthreadsafesingleton">NonThreadSafeSingleton</a>: Non-thread safe singletons can result in bad state changes. Eliminate static singletons if possib…</li>
<li><a href="pmd_rules_java_multithreading.html#unsynchronizedstaticformatter">UnsynchronizedStaticFormatter</a>: Instances of java.text.Format are generally not synchronized. Sun recommends using separate for…</li>
<li><a href="pmd_rules_java_multithreading.html#useconcurrenthashmap">UseConcurrentHashMap</a>: Since Java5 brought a new implementation of the Map designed for multi-threaded access, you can p…</li>
<li><a href="pmd_rules_java_multithreading.html#usenotifyallinsteadofnotify">UseNotifyAllInsteadOfNotify</a>: Thread.notify() awakens a thread monitoring the object. If more than one thread is monitoring, th…</li>
</ul>
<h2 id="performance">Performance</h2>
<div class="bs-callout bs-callout-">Rules that flag suboptimal code.</div>
<ul>
<li><a href="pmd_rules_java_performance.html#addemptystring">AddEmptyString</a>: The conversion of literals to strings by concatenating them with empty strings is inefficient. It…</li>
<li><a href="pmd_rules_java_performance.html#appendcharacterwithchar">AppendCharacterWithChar</a>: Avoid concatenating characters as strings in StringBuffer/StringBuilder.append methods.</li>
<li><a href="pmd_rules_java_performance.html#avoidarrayloops">AvoidArrayLoops</a>: Instead of manually copying data between two arrays, use the more efficient Arrays.copyOf or S…</li>
<li><a href="pmd_rules_java_performance.html#avoidcalendardatecreation">AvoidCalendarDateCreation</a>: Problem: java.util.Calendar is a heavyweight object and expensive to create. It should only be …</li>
<li><a href="pmd_rules_java_performance.html#avoidfilestream">AvoidFileStream</a>: The FileInputStream and FileOutputStream classes contains a finalizer method which will cause gar…</li>
<li><a href="pmd_rules_java_performance.html#avoidinstantiatingobjectsinloops">AvoidInstantiatingObjectsInLoops</a>: New objects created within loops should be checked to see if they can created outside them and re…</li>
<li><a href="pmd_rules_java_performance.html#bigintegerinstantiation">BigIntegerInstantiation</a>: Dont create instances of already existing BigInteger (BigInteger.ZERO, BigInteger.ONE), for …</li>
<li><a href="pmd_rules_java_performance.html#consecutiveappendsshouldreuse">ConsecutiveAppendsShouldReuse</a>: Consecutive calls to StringBuffer/StringBuilder .append should be chained, reusing the target obj…</li>
<li><a href="pmd_rules_java_performance.html#consecutiveliteralappends">ConsecutiveLiteralAppends</a>: Consecutively calling StringBuffer/StringBuilder.append(…) with literals should be avoided. Sin…</li>
<li><a href="pmd_rules_java_performance.html#inefficientemptystringcheck">InefficientEmptyStringCheck</a>: String.trim().length() == 0 (or String.trim().isEmpty() for the same reason) is an inefficient wa…</li>
<li><a href="pmd_rules_java_performance.html#inefficientstringbuffering">InefficientStringBuffering</a>: Avoid concatenating non-literals in a StringBuffer constructor or append() since intermediate buf…</li>
<li><a href="pmd_rules_java_performance.html#insufficientstringbufferdeclaration">InsufficientStringBufferDeclaration</a>: Failing to pre-size a StringBuffer or StringBuilder properly could cause it to re-size many times…</li>
<li><a href="pmd_rules_java_performance.html#optimizabletoarraycall">OptimizableToArrayCall</a>: Calls to a collections toArray(E[]) method should specify a target array of zero size. This al…</li>
<li><a href="pmd_rules_java_performance.html#redundantfieldinitializer">RedundantFieldInitializer</a>: Java will initialize fields with known default values so any explicit initialization of those sam…</li>
<li><a href="pmd_rules_java_performance.html#stringinstantiation">StringInstantiation</a>: Avoid instantiating String objects; this is usually unnecessary since they are immutable and can …</li>
<li><a href="pmd_rules_java_performance.html#stringtostring">StringToString</a>: Avoid calling toString() on objects already known to be string instances; this is unnecessary.</li>
<li><a href="pmd_rules_java_performance.html#toofewbranchesforaswitchstatement">TooFewBranchesForASwitchStatement</a>: <span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> The rule has been renamed. Use instead <a href="pmd_rules_java_performance.html#toofewbranchesforswitch">TooFewBranchesForSwitch</a>.</li>
<li><a href="pmd_rules_java_performance.html#toofewbranchesforswitch">TooFewBranchesForSwitch</a>: Switch statements are intended to be used to support complex branching behaviour. Using a switch …</li>
<li><a href="pmd_rules_java_performance.html#usearraylistinsteadofvector">UseArrayListInsteadOfVector</a>: ArrayList is a much better Collection implementation than Vector if thread-safe operation is not …</li>
<li><a href="pmd_rules_java_performance.html#usearraysaslist">UseArraysAsList</a>: The java.util.Arrays class has a asList() method that should be used when you want to create …</li>
<li><a href="pmd_rules_java_performance.html#useindexofchar">UseIndexOfChar</a>: Use String.indexOf(char) when checking for the index of a single character; it executes faster.</li>
<li><a href="pmd_rules_java_performance.html#useiostreamswithapachecommonsfileitem">UseIOStreamsWithApacheCommonsFileItem</a>: Problem: Use of [FileItem.get()](https://javadoc.io/static/commons-fileupload/commons-fileupload/…</li>
<li><a href="pmd_rules_java_performance.html#uselessstringvalueof">UselessStringValueOf</a>: No need to call String.valueOf to append to a string; just use the valueOf() argument directly.</li>
<li><a href="pmd_rules_java_performance.html#usestringbufferforstringappends">UseStringBufferForStringAppends</a>: The use of the += operator for appending strings causes the JVM to create and use an internal S…</li>
<li><a href="pmd_rules_java_performance.html#usestringbufferlength">UseStringBufferLength</a>: Use StringBuffer.length() to determine StringBuffer length rather than using StringBuffer.toStrin…</li>
</ul>
<h2 id="security">Security</h2>
<div class="bs-callout bs-callout-">Rules that flag potential security flaws.</div>
<ul>
<li><a href="pmd_rules_java_security.html#hardcodedcryptokey">HardCodedCryptoKey</a>: Do not use hard coded values for cryptographic operations. Please store keys outside of source code.</li>
<li><a href="pmd_rules_java_security.html#insecurecryptoiv">InsecureCryptoIv</a>: Do not use hard coded initialization vector in cryptographic operations. Please use a randomly ge…</li>
</ul>
<h2 id="additional-rulesets">Additional rulesets</h2>
<ul>
<li>
<p>quickstart (<code class="language-plaintext highlighter-rouge">rulesets/java/quickstart.xml</code>):</p>
<p>Quickstart configuration of PMD. Includes the rules that are most likely to apply everywhere.</p>
<p>It contains the following rules:</p>
<p><a href="pmd_rules_java_design.html#abstractclasswithoutanymethod">AbstractClassWithoutAnyMethod</a>, <a href="pmd_rules_java_errorprone.html#assignmentinoperand">AssignmentInOperand</a>, <a href="pmd_rules_java_errorprone.html#assignmenttononfinalstatic">AssignmentToNonFinalStatic</a>, <a href="pmd_rules_java_errorprone.html#avoidaccessibilityalteration">AvoidAccessibilityAlteration</a>, <a href="pmd_rules_java_errorprone.html#avoidbranchingstatementaslastinloop">AvoidBranchingStatementAsLastInLoop</a>, <a href="pmd_rules_java_errorprone.html#avoidcatchingthrowable">AvoidCatchingThrowable</a>, <a href="pmd_rules_java_errorprone.html#avoiddecimalliteralsinbigdecimalconstructor">AvoidDecimalLiteralsInBigDecimalConstructor</a>, <a href="pmd_rules_java_codestyle.html#avoiddollarsigns">AvoidDollarSigns</a>, <a href="pmd_rules_java_errorprone.html#avoidinstanceofchecksincatchclause">AvoidInstanceofChecksInCatchClause</a>, <a href="pmd_rules_java_bestpractices.html#avoidmessagedigestfield">AvoidMessageDigestField</a>, <a href="pmd_rules_java_errorprone.html#avoidmultipleunaryoperators">AvoidMultipleUnaryOperators</a>, <a href="pmd_rules_java_codestyle.html#avoidprotectedfieldinfinalclass">AvoidProtectedFieldInFinalClass</a>, <a href="pmd_rules_java_codestyle.html#avoidprotectedmethodinfinalclassnotextending">AvoidProtectedMethodInFinalClassNotExtending</a>, <a href="pmd_rules_java_bestpractices.html#avoidstringbufferfield">AvoidStringBufferField</a>, <a href="pmd_rules_java_multithreading.html#avoidthreadgroup">AvoidThreadGroup</a>, <a href="pmd_rules_java_bestpractices.html#avoidusinghardcodedip">AvoidUsingHardCodedIP</a>, <a href="pmd_rules_java_errorprone.html#avoidusingoctalvalues">AvoidUsingOctalValues</a>, <a href="pmd_rules_java_multithreading.html#avoidusingvolatile">AvoidUsingVolatile</a>, <a href="pmd_rules_java_performance.html#bigintegerinstantiation">BigIntegerInstantiation</a>, <a href="pmd_rules_java_errorprone.html#brokennullcheck">BrokenNullCheck</a>, <a href="pmd_rules_java_bestpractices.html#checkresultset">CheckResultSet</a>, <a href="pmd_rules_java_errorprone.html#checkskipresult">CheckSkipResult</a>, <a href="pmd_rules_java_errorprone.html#classcastexceptionwithtoarray">ClassCastExceptionWithToArray</a>, <a href="pmd_rules_java_codestyle.html#classnamingconventions">ClassNamingConventions</a>, <a href="pmd_rules_java_design.html#classwithonlyprivateconstructorsshouldbefinal">ClassWithOnlyPrivateConstructorsShouldBeFinal</a>, <a href="pmd_rules_java_errorprone.html#clonemethodmustbepublic">CloneMethodMustBePublic</a>, <a href="pmd_rules_java_errorprone.html#clonemethodmustimplementcloneable">CloneMethodMustImplementCloneable</a>, <a href="pmd_rules_java_errorprone.html#clonemethodreturntypemustmatchclassname">CloneMethodReturnTypeMustMatchClassName</a>, <a href="pmd_rules_java_errorprone.html#closeresource">CloseResource</a>, <a href="pmd_rules_java_errorprone.html#compareobjectswithequals">CompareObjectsWithEquals</a>, <a href="pmd_rules_java_errorprone.html#comparisonwithnan">ComparisonWithNaN</a>, <a href="pmd_rules_java_bestpractices.html#constantsininterface">ConstantsInInterface</a>, <a href="pmd_rules_java_codestyle.html#controlstatementbraces">ControlStatementBraces</a>, <a href="pmd_rules_java_bestpractices.html#defaultlabelnotlastinswitch">DefaultLabelNotLastInSwitch</a>, <a href="pmd_rules_java_errorprone.html#donotcallgarbagecollectionexplicitly">DoNotCallGarbageCollectionExplicitly</a>, <a href="pmd_rules_java_design.html#donotextendjavalangerror">DoNotExtendJavaLangError</a>, <a href="pmd_rules_java_errorprone.html#donotextendjavalangthrowable">DoNotExtendJavaLangThrowable</a>, <a href="pmd_rules_java_multithreading.html#dontcallthreadrun">DontCallThreadRun</a>, <a href="pmd_rules_java_errorprone.html#dontusefloattypeforloopindices">DontUseFloatTypeForLoopIndices</a>, <a href="pmd_rules_java_bestpractices.html#doublebraceinitialization">DoubleBraceInitialization</a>, <a href="pmd_rules_java_multithreading.html#doublecheckedlocking">DoubleCheckedLocking</a>, <a href="pmd_rules_java_errorprone.html#emptycatchblock">EmptyCatchBlock</a>, <a href="pmd_rules_java_codestyle.html#emptycontrolstatement">EmptyControlStatement</a>, <a href="pmd_rules_java_errorprone.html#emptyfinalizer">EmptyFinalizer</a>, <a href="pmd_rules_java_errorprone.html#equalsnull">EqualsNull</a>, <a href="pmd_rules_java_codestyle.html#extendsobject">ExtendsObject</a>, <a href="pmd_rules_java_design.html#finalfieldcouldbestatic">FinalFieldCouldBeStatic</a>, <a href="pmd_rules_java_codestyle.html#finalparameterinabstractmethod">FinalParameterInAbstractMethod</a>, <a href="pmd_rules_java_bestpractices.html#forloopcanbeforeach">ForLoopCanBeForeach</a>, <a href="pmd_rules_java_codestyle.html#forloopshouldbewhileloop">ForLoopShouldBeWhileLoop</a>, <a href="pmd_rules_java_codestyle.html#formalparameternamingconventions">FormalParameterNamingConventions</a>, <a href="pmd_rules_java_codestyle.html#genericsnaming">GenericsNaming</a>, <a href="pmd_rules_java_bestpractices.html#guardlogstatement">GuardLogStatement</a>, <a href="pmd_rules_java_errorprone.html#idempotentoperations">IdempotentOperations</a>, <a href="pmd_rules_java_codestyle.html#identicalcatchbranches">IdenticalCatchBranches</a>, <a href="pmd_rules_java_errorprone.html#implicitswitchfallthrough">ImplicitSwitchFallThrough</a>, <a href="pmd_rules_java_errorprone.html#instantiationtogetclass">InstantiationToGetClass</a>, <a href="pmd_rules_java_errorprone.html#jumbledincrementer">JumbledIncrementer</a>, <a href="pmd_rules_java_codestyle.html#lambdacanbemethodreference">LambdaCanBeMethodReference</a>, <a href="pmd_rules_java_bestpractices.html#literalsfirstincomparisons">LiteralsFirstInComparisons</a>, <a href="pmd_rules_java_codestyle.html#localvariablenamingconventions">LocalVariableNamingConventions</a>, <a href="pmd_rules_java_design.html#logicinversion">LogicInversion</a>, <a href="pmd_rules_java_bestpractices.html#loosecoupling">LooseCoupling</a>, <a href="pmd_rules_java_codestyle.html#methodnamingconventions">MethodNamingConventions</a>, <a href="pmd_rules_java_errorprone.html#misplacednullcheck">MisplacedNullCheck</a>, <a href="pmd_rules_java_bestpractices.html#missingoverride">MissingOverride</a>, <a href="pmd_rules_java_errorprone.html#missingstaticmethodinnoninstantiatableclass">MissingStaticMethodInNonInstantiatableClass</a>, <a href="pmd_rules_java_errorprone.html#noncaselabelinswitch">NonCaseLabelInSwitch</a>, <a href="pmd_rules_java_bestpractices.html#nonexhaustiveswitch">NonExhaustiveSwitch</a>, <a href="pmd_rules_java_errorprone.html#nonstaticinitializer">NonStaticInitializer</a>, <a href="pmd_rules_java_multithreading.html#nonthreadsafesingleton">NonThreadSafeSingleton</a>, <a href="pmd_rules_java_codestyle.html#nopackage">NoPackage</a>, <a href="pmd_rules_java_bestpractices.html#onedeclarationperline">OneDeclarationPerLine</a>, <a href="pmd_rules_java_performance.html#optimizabletoarraycall">OptimizableToArrayCall</a>, <a href="pmd_rules_java_errorprone.html#overridebothequalsandhashcode">OverrideBothEqualsAndHashcode</a>, <a href="pmd_rules_java_codestyle.html#packagecase">PackageCase</a>, <a href="pmd_rules_java_bestpractices.html#preservestacktrace">PreserveStackTrace</a>, <a href="pmd_rules_java_bestpractices.html#primitivewrapperinstantiation">PrimitiveWrapperInstantiation</a>, <a href="pmd_rules_java_errorprone.html#propercloneimplementation">ProperCloneImplementation</a>, <a href="pmd_rules_java_errorprone.html#properlogger">ProperLogger</a>, <a href="pmd_rules_java_errorprone.html#returnemptycollectionratherthannull">ReturnEmptyCollectionRatherThanNull</a>, <a href="pmd_rules_java_errorprone.html#returnfromfinallyblock">ReturnFromFinallyBlock</a>, <a href="pmd_rules_java_bestpractices.html#simplifiabletestassertion">SimplifiableTestAssertion</a>, <a href="pmd_rules_java_design.html#simplifiedternary">SimplifiedTernary</a>, <a href="pmd_rules_java_design.html#simplifybooleanreturns">SimplifyBooleanReturns</a>, <a href="pmd_rules_java_design.html#simplifyconditional">SimplifyConditional</a>, <a href="pmd_rules_java_errorprone.html#singlemethodsingleton">SingleMethodSingleton</a>, <a href="pmd_rules_java_errorprone.html#singletonclassreturningnewinstance">SingletonClassReturningNewInstance</a>, <a href="pmd_rules_java_design.html#singularfield">SingularField</a>, <a href="pmd_rules_java_errorprone.html#suspiciousequalsmethodname">SuspiciousEqualsMethodName</a>, <a href="pmd_rules_java_errorprone.html#suspicioushashcodemethodname">SuspiciousHashcodeMethodName</a>, <a href="pmd_rules_java_errorprone.html#suspiciousoctalescape">SuspiciousOctalEscape</a>, <a href="pmd_rules_java_documentation.html#uncommentedemptyconstructor">UncommentedEmptyConstructor</a>, <a href="pmd_rules_java_documentation.html#uncommentedemptymethodbody">UncommentedEmptyMethodBody</a>, <a href="pmd_rules_java_errorprone.html#unconditionalifstatement">UnconditionalIfStatement</a>, <a href="pmd_rules_java_codestyle.html#unnecessaryannotationvalueelement">UnnecessaryAnnotationValueElement</a>, <a href="pmd_rules_java_codestyle.html#unnecessaryconstructor">UnnecessaryConstructor</a>, <a href="pmd_rules_java_errorprone.html#unnecessaryconversiontemporary">UnnecessaryConversionTemporary</a>, <a href="pmd_rules_java_codestyle.html#unnecessaryfullyqualifiedname">UnnecessaryFullyQualifiedName</a>, <a href="pmd_rules_java_codestyle.html#unnecessaryimport">UnnecessaryImport</a>, <a href="pmd_rules_java_codestyle.html#unnecessarylocalbeforereturn">UnnecessaryLocalBeforeReturn</a>, <a href="pmd_rules_java_codestyle.html#unnecessarymodifier">UnnecessaryModifier</a>, <a href="pmd_rules_java_codestyle.html#unnecessaryreturn">UnnecessaryReturn</a>, <a href="pmd_rules_java_codestyle.html#unnecessarysemicolon">UnnecessarySemicolon</a>, <a href="pmd_rules_java_multithreading.html#unsynchronizedstaticformatter">UnsynchronizedStaticFormatter</a>, <a href="pmd_rules_java_bestpractices.html#unusedformalparameter">UnusedFormalParameter</a>, <a href="pmd_rules_java_bestpractices.html#unusedlocalvariable">UnusedLocalVariable</a>, <a href="pmd_rules_java_errorprone.html#unusednullcheckinequals">UnusedNullCheckInEquals</a>, <a href="pmd_rules_java_bestpractices.html#unusedprivatefield">UnusedPrivateField</a>, <a href="pmd_rules_java_bestpractices.html#unusedprivatemethod">UnusedPrivateMethod</a>, <a href="pmd_rules_java_bestpractices.html#usecollectionisempty">UseCollectionIsEmpty</a>, <a href="pmd_rules_java_errorprone.html#useequalstocomparestrings">UseEqualsToCompareStrings</a>, <a href="pmd_rules_java_errorprone.html#uselessoperationonimmutable">UselessOperationOnImmutable</a>, <a href="pmd_rules_java_design.html#uselessoverridingmethod">UselessOverridingMethod</a>, <a href="pmd_rules_java_codestyle.html#uselessparentheses">UselessParentheses</a>, <a href="pmd_rules_java_codestyle.html#uselessqualifiedthis">UselessQualifiedThis</a>, <a href="pmd_rules_java_errorprone.html#uselocalewithcaseconversions">UseLocaleWithCaseConversions</a>, <a href="pmd_rules_java_multithreading.html#usenotifyallinsteadofnotify">UseNotifyAllInsteadOfNotify</a>, <a href="pmd_rules_java_bestpractices.html#usestandardcharsets">UseStandardCharsets</a>, <a href="pmd_rules_java_design.html#useutilityclass">UseUtilityClass</a></p>
</li>
</ul>
<div class="tags">
<b>Tags: </b>
<a href="tag_rule_references.html" class="btn btn-outline-secondary navbar-btn cursorNorm" role="button">rule_references</a>
</div>
</div>
<footer>
<hr />
<div class="row">
<div class="col-lg-12 footer">
&copy;2024 PMD Open Source Project. All rights
reserved. <br />
Site last generated: Nov 21, 2024 <br />
<p>
<img src="images/logo/pmd-logo-70px.png" alt="PMD
logo"/>
</p>
</div>
</div>
</footer>
</div>
<!-- /.row -->
</div>
<!-- /.container -->
</div>
<!-- Sticky TOC column -->
<div class="toc-col">
<div id="toc"></div>
</div>
<!-- /.toc-container-wrapper -->
</div>
</div>
<script type="application/javascript" src="assets/jquery-3.5.1/jquery-3.5.1.min.js"></script>
<script type="application/javascript" src="assets/anchorjs-4.2.2/anchor.min.js"></script>
<script type="application/javascript" src="assets/navgoco-0.2.1/src/jquery.navgoco.min.js"></script>
<script type="application/javascript" src="assets/bootstrap-4.5.2-dist/js/bootstrap.bundle.min.js"></script>
<script type="application/javascript" src="assets/Simple-Jekyll-Search-1.0.8/dest/jekyll-search.js"></script>
<script type="application/javascript" src="assets/jekyll-table-of-contents/toc.js"></script>
<script type="application/javascript" src="js/tabstate.js"></script>
<script type="application/javascript" src="js/customscripts.js"></script>
</body>
</html>