Configs2026年7月15日·1 分钟阅读

Error Prone — Catch Common Java Mistakes at Compile Time

Error Prone is a static analysis tool by Google that plugs into the Java compiler to catch common programming mistakes as compile-time errors rather than runtime bugs.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Error Prone Overview
直接安装命令
npx -y tokrepo@latest install b4e7cfb7-802a-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

Error Prone is a compile-time static analysis tool by Google that hooks into javac to detect common Java programming errors. Unlike standalone linters, it runs during compilation and surfaces issues as compiler errors or warnings, catching bugs before code ever runs.

What Error Prone Does

  • Detects hundreds of common Java bug patterns during compilation
  • Produces compiler errors or warnings with clear fix suggestions
  • Integrates with Maven, Gradle, and Bazel build systems
  • Allows teams to write custom bug pattern checkers
  • Provides automatic refactoring patches for many detected issues

Architecture Overview

Error Prone operates as a javac plugin that analyzes the abstract syntax tree (AST) during compilation. Each bug pattern is implemented as a BugChecker class that inspects specific AST nodes. When a pattern matches, Error Prone emits a diagnostic with a human-readable description and often a suggested fix that can be applied automatically.

Self-Hosting & Configuration

  • Add as a dependency to Maven, Gradle, or Bazel build configuration
  • Requires JDK 11 or later
  • Enable or disable specific checks via compiler flags
  • Promote warnings to errors or demote errors to warnings per check
  • Write custom BugChecker classes for project-specific patterns

Key Features

  • 500+ built-in bug pattern detectors covering null safety, concurrency, and API misuse
  • Automatic fix suggestions that can be applied with a single command
  • Runs at compile time with minimal build overhead
  • Extensible: teams can write and distribute custom checkers
  • Battle-tested across Google internal codebase at massive scale

Comparison with Similar Tools

  • SpotBugs — Analyzes bytecode post-compilation; Error Prone works at the source level during compilation
  • PMD — Rule-based standalone linter; Error Prone integrates directly into javac
  • SonarQube — Server-based analysis platform; Error Prone is a lightweight compiler plugin
  • Checkstyle — Focuses on style and formatting; Error Prone focuses on correctness bugs

FAQ

Q: Does Error Prone slow down compilation? A: Overhead is typically under 10%, as it piggybacks on the existing compilation pass.

Q: Can I use it with Kotlin? A: No. Error Prone analyzes Java source code via javac. For Kotlin, consider detekt.

Q: How do I suppress a false positive? A: Use the @SuppressWarnings annotation with the check name.

Q: Is it used in production at Google? A: Yes. Error Prone is used across the entire Google Java codebase.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产