Java Code Quality: Alibaba Guidelines, CheckStyle, PMD, FindBugs, SonarLint
To maintain stable, high‑quality Java services as projects grow, this guide introduces five essential static‑analysis tools—Alibaba Java Coding Guidelines, CheckStyle, PMD, FindBugs, and SonarLint—detailing their installation, core features, usage steps, and how they collectively reduce bugs and improve code standards.
As systems expand, simple stable functions can become complex, exposing risks and causing service instability. Improving code quality through static analysis tools helps reduce bugs and streamline code reviews.
1. Alibaba Java Coding Guidelines
Focuses on Java coding standards, categorizing violations as Blocker, Critical, or Major, many of which can be auto‑fixed. It provides real‑time inspection during coding.
Installation
Open File > Settings > Plugins > Marketplace, search for "Alibaba Java Coding Guidelines", install and restart.
Usage
Run the scan via Tools > 阿里编码规约 > 编码规约扫描 or right‑click in the editor and select "编码规约扫描". Results are grouped by severity (Blocker > Critical > Major) and can be filtered, expanded, or navigated to the source code.
2. CheckStyle
Checks coding style and format (naming, Javadoc, whitespace, method length, duplicate code, unused imports, etc.). It enforces style but has limited bug‑detection capability.
Installation
Search for "CheckStyle" in the IntelliJ Marketplace, install, and restart.
Usage
Run the inspection from the Tools menu; it highlights style violations in the code.
3. PMD
Targets security‑related rules and performs data‑flow and path analysis. Supports custom rule sets.
Potential bugs : try/catch/finally/switch misuse
Dead code : unused variables, parameters, private methods
Optional code : misuse of String/StringBuffer
Complex expressions : unnecessary ifs, for‑loops that can be while
Duplicate code : copy‑paste bugs
Object creation in loops
Resource closing
Installation
Search for "PMDPlugin" in the Marketplace, install, and restart.
Usage
Run via Tools > Run PMD for the whole project or right‑click a file/package and select "Run PMD". Configure rule sets under File > Settings > Other Settings > PMD.
4. FindBugs
Detects runtime bugs such as null‑pointer dereferences, resource leaks, and incorrect string comparisons.
Installation
Search for "FindBugs" in the Marketplace, install, and restart.
Usage
Analyze a file, package, module, or whole project via the right‑click menu. Results show problem categories like Bad Practice, Dodgy Code, Internationalization, Performance, etc., with links to the offending source lines.
5. SonarLint
Provides a higher level of analysis than FindBugs, covering code quality, dependencies, complexity, and duplication. It works as an IDE plugin or connects to a SonarQube server.
Installation
Search for "SonarLint" in the Marketplace, install, and restart.
Usage
Run SonarLint on a project or file; it reports issues and offers quick‑fix suggestions. When committing code, enable "Perform SonarLint analysis" to enforce checks.
Summary
For coding‑style enforcement, use Alibaba Java Coding Guidelines.
For bug detection, combine PMD, FindBugs, and SonarLint for complementary coverage.
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.
Programmer DD
A tinkering programmer and author of "Spring Cloud Microservices in Action"
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.
