Master Java Code Quality: CheckStyle, PMD, FindBugs & SonarLint
To maintain stable Java services as projects grow, this article introduces essential code quality tools—including Alibaba Java Coding Guidelines, CheckStyle, PMD, FindBugs, and SonarLint—detailing their installation, usage, and key features to streamline code reviews and reduce bugs.
1. Alibaba Java Coding Guidelines
1.1 Overview
Alibaba Java Coding Guidelines focuses on Java code conventions, providing real‑time inspection and categorizing violations as Blocker, Critical, or Major, many of which can be auto‑fixed.
1.2 Scanning Scope
OOP rules
Concurrency handling
Control statements
Naming conventions
Constant definitions
Comment standards
1.3 Installation
File > Settings > Plugins > Marketplace– search “Alibaba Java Coding Guidelines”, install and restart.
1.4 Usage
1.1 Run
(1) Tools > Alibaba Coding Guidelines > Scan
(2) Right‑click in editor or project view and choose “Coding Guidelines Scan”.
1.5 Toolbar Functions
Rerun Inspection– re‑run the scan Close – close the AJCG panel Expand All – expand result tree Collapse All – collapse result tree Go Pre Problem – previous issue Go Next Problem – next issue
Group by Severity Group by Directory Filter Resolved Items Autoscroll to Source Export– export results as XML or HTML Edit Settings – edit plugin settings
2. CheckStyle
2.1 Overview
CheckStyle checks coding style and format, such as naming, Javadoc, whitespace, method length, duplicate code, and unused imports, helping developers follow style guidelines; it has limited bug‑detection capability.
2.2 Installation
File > Settings > Plugins > Marketplace– search “CheckStyle”, install and restart.
2.3 Usage
After installation, the plugin shows style violations in the editor; most issues are related to indentation and formatting.
3. PMD
3.1 Overview
PMD focuses on security‑related coding rules and provides data‑flow and path analysis. It supports custom rules and detects potential bugs, dead code, misuse of String/StringBuffer, complex expressions, duplicated code, object creation inside loops, and resource leaks.
3.2 Installation
File > Settings > Plugins > Marketplace– search “PMDPlugin”, install and restart.
3.3 Usage
Run via Tools > Run PMD to scan the whole project, or right‑click a file/package and choose “Run PMD” for a selected scope.
Result panel shows rule sets, custom rules, and detected issues. Configuration can be opened via File > Settings > Other Settings > PMD.
4. FindBugs
4.1 Overview
FindBugs detects runtime bugs such as null‑pointer dereferences, unreleased resources, and incorrect string comparisons, providing suggestions for fixes.
4.2 Installation
File > Settings > Plugins > Marketplace– search “FindBugs”, install and restart.
4.3 Usage
Analyze a file, package, module, or whole project via right‑click and selecting the appropriate scope.
The result panel lists issues; clicking an item jumps to the offending code.
5. SonarLint
5.1 Overview
SonarLint extends static analysis beyond bugs to code quality, dependencies, coupling, and complexity, offering richer rules than FindBugs.
5.2 Installation
File > Settings > Plugins > Marketplace– search “SonarLint”, install and restart.
5.3 Usage
Right‑click a project or file and run SonarLint; issues appear in the report with suggested fixes. The plugin can also be linked to a SonarQube server for server‑side analysis.
Configure server connection and project selection via the plugin settings.
Conclusion
For coding‑style checks, use Alibaba Java Coding Guidelines.
For bug detection, combine PMD, FindBugs, and SonarLint; PMD offers strong custom‑rule support, FindBugs excels at bug discovery, and SonarLint provides comprehensive quality rules.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java High-Performance Architecture
Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
