LinthelmIntroductions to linters, static analysis and code-quality tools

Static analysis · 5 tools

Top 5 static analysis tools for detecting code smells, unused code and duplication in Java

By the Linthelm editorial team · Published · Updated · Facts checked 21 November 2026 (Asia/Dhaka)

PMD, SonarQube and Error Prone are the first three tools on this shortlist, which is written for Java maintainers who are refactoring large codebases and need to find code smells, unused code and copy-paste. PMD comes first because its documentation covers unused variables, empty catch blocks and a built-in copy-paste detector. The remaining tools cover platform-level quality gates, compile-time checking, Kotlin smell analysis and technical-debt prioritization.

At a glance: the shortlist in order of fit for this use case
#ToolBest forKey featurePlatforms / deploymentPricingMore
1PMDPMDJava teams that want rule-based smell checks and duplicate detection in one open toolMore than 400 built-in rules, extendable with custom rules written in Java or as XPath queriesCommand line (check command); Windows install via Chocolatey; Eclipse plugin and other IDE and CI pluginsSee vendor pricing pageIntroduction
2SonarQubeSonarTeams that want maintainability and technical-debt checks enforced at merge timeAnalyzes branches and pull requests for bugs, maintainability issues and technical debt across 45+ languagesManaged cloud (SonarQube Cloud) or self-managed server (SonarQube Server), including air-gapped; common editors and major Git platformsSee vendor pricing pageIntroduction
3Error ProneGoogleJava teams that want refactoring mistakes caught during the buildAugments the compiler's type analysis to catch mistakes before they become production bugsJava build integration, for example Bazel Java compilationSee vendor pricing pageIntroduction
4detektdetektMixed Java and Kotlin codebases that need smell analysis on the Kotlin sideCode smell analysis on Kotlin projectsGradle, Maven and Bazel; Android, JVM, JS, Native and Multiplatform projectsSee vendor pricing pageIntroduction
5CodeSceneCodeSceneEngineering teams prioritizing which parts of a large codebase to refactorIdentifies and prioritizes high-impact technical debt using the CodeHealth™ metricHosted cloud or on-prem on your own machine or server; connects to GitHub, GitLab, BitBucket and Azure DevOps; IDE and CLISee vendor pricing pageOfficial site

1 PMD

By PMD

PMD is an extensible, cross-language static source code analyzer that finds common programming flaws such as unused variables, empty catch blocks and unnecessary object creation. It focuses mainly on Java and Apex.

Why it is here: It sits first because its documentation names unused variables explicitly and bundles CPD, a copy-paste detector, which covers two of the three needs in this use case in one tool.

Best for
Java teams that want rule-based smell checks and duplicate detection in one open tool
Key features
  • More than 400 built-in rules, extendable with custom rules written in Java or as XPath queries
  • Finds unused variables, empty catch blocks and unnecessary object creation
  • CPD copy-paste detector for duplicated code
  • Parses source into abstract syntax trees using JavaCC and Antlr before running rules
  • Eclipse plugin released alongside PMD, plus other IDE and CI plugins
Limits
The documentation lists unused variables as an example of what PMD finds; it does not describe whole-project dead-code analysis, so check the rule documentation for the unused-code cases you care about. Commercial support such as consulting and training comes from third-party companies.
Platforms / deployment
Command line (check command); Windows install via Chocolatey; Eclipse plugin and other IDE and CI plugins
Pricing
See vendor pricing page (not quoted here; facts checked 21 November 2026, Asia/Dhaka)

2 SonarQube

By Sonar

SonarQube is a code quality and security platform that automates reviews and verification of human-written and AI-generated code. It is available as a managed cloud service or a self-hosted server.

Why it is here: It follows PMD because it adds branch and pull request analysis for maintainability issues and technical debt, which suits ongoing refactoring work more than one-off scans.

Best for
Teams that want maintainability and technical-debt checks enforced at merge time
Key features
  • Analyzes branches and pull requests for bugs, maintainability issues and technical debt across 45+ languages
  • Quality gates decide what merges and record every check
  • Quality gate results appear in pull requests on major Git platforms
  • AI CodeFix suggests fixes, and the Remediation Agent opens verified pull requests
  • Architects define the intended structure and deviations are flagged in quality gates
Limits
The documented scope is maintainability issues, bugs and technical debt; duplicate-code and unused-code detection are not listed in the facts we checked, so confirm them in the vendor documentation. SCA requires SonarQube Advanced Security.
Platforms / deployment
Managed cloud (SonarQube Cloud) or self-managed server (SonarQube Server), including air-gapped; common editors and major Git platforms
Pricing
See vendor pricing page (not quoted here; facts checked 21 November 2026, Asia/Dhaka)

3 Error Prone

By Google

Error Prone is a Google-developed, open-source tool that augments the Java compiler's type analysis to catch mistakes at build time. Google uses it in its own Java build system.

Why it is here: It sits third because it is documented as a compile-time bug checker rather than a smell or duplication detector, but it is useful during refactoring for code that no longer does what was intended.

Best for
Java teams that want refactoring mistakes caught during the build
Key features
  • Augments the compiler's type analysis to catch mistakes before they become production bugs
  • Hooks into the standard build so all developers run it automatically
  • Findings surface as compilation errors, for example in a Bazel Java compilation
  • Each finding carries a named bug pattern, such as CollectionIncompatibleType, with a descriptive message
  • Produces suggested fixes, so tooling can be built on top of it
Limits
Documented as a bug-pattern checker for Java builds; it is not described as a duplicate-code or dead-code detector, so pair it with a tool that covers those. Teams on build systems other than those in the documentation should check the vendor documentation.
Platforms / deployment
Java build integration, for example Bazel Java compilation
Pricing
See vendor pricing page (not quoted here; facts checked 21 November 2026, Asia/Dhaka)

4 detekt

By detekt

detekt is an open-source static code analyzer for Kotlin that detects code smells and is configurable and extensible. It is developed by the community.

Why it is here: It sits fourth because its documented code smell analysis targets Kotlin, so it matters mainly for Java projects that also contain Kotlin code.

Best for
Mixed Java and Kotlin codebases that need smell analysis on the Kotlin side
Key features
  • Code smell analysis on Kotlin projects
  • Baselines let legacy projects suppress existing issues while ensuring no new issues are introduced
  • Complexity reports based on lines of code, cyclomatic complexity and number of code smells
  • Reports in HTML, Markdown, SARIF, Checkstyle (XML) and custom formats
  • First-party Gradle plugin, plus plugins for Maven and Bazel
Limits
Documented for Kotlin only; it is not described as analyzing Java source, so Java-only projects should look at the other tools first. Duplicate-code and unused-code detection are not listed in the facts we checked.
Platforms / deployment
Gradle, Maven and Bazel; Android, JVM, JS, Native and Multiplatform projects
Pricing
See vendor pricing page (not quoted here; facts checked 21 November 2026, Asia/Dhaka)

5 CodeScene

By CodeScene

CodeScene is a code quality and technical-debt analysis platform built around the CodeHealth™ metric. It helps teams prioritize debt, gate pull requests and safeguard AI-generated code.

Why it is here: It closes the list because it helps decide where to refactor first and guards against new debt, rather than listing individual smells, unused code or duplicates.

Best for
Engineering teams prioritizing which parts of a large codebase to refactor
Key features
  • Identifies and prioritizes high-impact technical debt using the CodeHealth™ metric
  • Pull request gates can block merges that drop Code Health below a configured bar
  • Real-time CodeHealth™ feedback in the IDE
  • CLI and REST API for pipelines and internal systems
  • Insight into knowledge distribution and bus-factor risk
Limits
The documentation does not say which languages it analyzes or describe duplicate-code or unused-code detection, so Java teams should check the vendor documentation for language coverage.
Platforms / deployment
Hosted cloud or on-prem on your own machine or server; connects to GitHub, GitLab, BitBucket and Azure DevOps; IDE and CLI
Pricing
See vendor pricing page (not quoted here; facts checked 21 November 2026, Asia/Dhaka)

How we chose these tools

We looked at three things: fit with the use case of finding smells, unused code and duplication in big Java codebases; the capabilities each vendor documents; and the deployment and platform options described in the documentation, such as build-system plugins, IDE support and self-hosting. Tools that document smell and duplication detection directly are placed first, and tools whose documented focus is compile-time checking, a different language or debt prioritization follow.

All facts come from official vendor pages and are checked against them at the time of writing. The order reflects editorial fit for this specific use case and is explained in each entry; it is not a statement that one tool is better than another overall. The list is built from documentation rather than product trials, so where a capability is not documented we say so and point you to the vendor documentation.

Order used in this guide: Ordered by smell and duplication detection strength, with compile-time checkers after.

Frequently asked questions

Which tool finds duplicated code in Java?

PMD includes CPD, a copy-paste detector that finds duplicated code in many languages. The other tools on this list do not document duplicate detection in the facts we checked.

Can PMD find unused code?

PMD's documentation lists unused variables, empty catch blocks and unnecessary object creation among the flaws it finds, using more than 400 built-in rules. Check the rule documentation for other unused-code cases.

Can I run these tools in a pull request workflow?

SonarQube shows quality gate results in pull requests on major Git platforms, and CodeScene's pull request gates can block merges below a configured Code Health bar. Error Prone surfaces findings as compilation errors in the build.

Does detekt work on Java code?

detekt is documented as a static analyzer for Kotlin, with Gradle, Maven and Bazel plugins. It is relevant to Java projects mainly where Kotlin code sits alongside the Java.

How can I adopt a smell checker on a legacy codebase without a wall of warnings?

detekt documents baselines that suppress existing issues while ensuring no new issues are introduced, though it applies to Kotlin. For Java, SonarQube's quality gates and CodeScene's pull request gates are documented ways to control what new code can merge.

Sources. Facts on this page come from each vendor's official pages, checked on the dates shown (Asia/Dhaka):

Linthelm is independent and not affiliated with the vendors listed. No vendor paid for inclusion or position. Product names belong to their owners. Features and prices change; confirm details on each official website.