error-prone

googleApache-2.0活跃维护

在编译期捕获 Java 常见错误的静态分析工具,把容易写错的代码模式直接变成编译报错,帮团队在提交前就拦住低级 bug。

Catch common Java mistakes as compile-time errors

v2.52.0发布于 2026-11-02 12:32 UTC7,267star +2 / 7 天834fork同步于 2026-11-10 05:32 UTC

怎么上手

README 里没有找到可直接复制的安装命令

README 里没有找到可直接复制的安装命令,请到 README 或官方文档查看安装方式。

硬件要求

README 没有说明硬件要求。

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

这个项目的说明还在生成中,先参考下面「最近发版」和 README。

最近发版

5 个版本v2.52.0
  1. v2.52.0Error Prone 2.52.0最新正式版2026-11-02 · 2026-11-02 12:32 UTC

    New checks:

    • AlmostExhaustiveTestParameter: Prefer an exhaustive @TestParameter with an assumption to filter out specific enum values, so newly added enum values are automatically tested (disabled by default).
    • SingleTestParameter: Suggest @TestParameter on the parameter instead of @TestParameters when there is only one test parameter, replacing PreferTestParameter (disabled by default).
    • SingleValueTestParameter: Suggest replacing a @TestParameter that has only a single value with a local variable in the test method (disabled by default).
    • ValueClassEquals: Require non-record concrete value classes to explicitly override equals and hashCode.

    Other changes:

    • LoopToTestParameter: Changed severity to SUGGESTION (disabled by default).
    • DistinctVarargsChecker: Allow duplicate arguments to Iterables.concat (#6239) and Mockito argument matchers such as any() (#6240).
    • UnusedVariable: Treat fields accessed via MethodHandles.Lookup (VarHandle/getter/setter lookups) or Atomic*FieldUpdater.newUpdater as used.
    • StringBuilderInitWithChar / StringBuffer refactoring: Refactor StringBuffer to StringBuilder even when used with Matcher.appendReplacement and appendTail (when supported by the target JDK or Android minSdkVersion).
    • CompileTimeConstant: Treat record and interface fields and field accesses on compile-time constants (compileTimeConstant.compileTimeConstantField) as compile-time constants.
    • ValueClassIdentity / ReferenceEquality: Handle JEP 401 value classes.
    • FieldCanBeFinal / ThreadSafety: Improve compile-time performance on large classes and deep type hierarchies, and update SafeRE to 1.1.0 (#6230).
    • Added ClassName for caching resolved ClassSymbol, Type, and binary Name lookups across a compilation.

    Closed issues: #5964, #6165, #6230, #6239, #6240, #6275

    Full changelog: https://github.com/google/error-prone/compare/v2.51.0...v2.52.0

  2. v2.51.0Error Prone 2.51.02026-10-22 · 2026-10-22 08:55 UTC
    查看更新说明

    New checks:

    • HashCodeInObjectsHash: Detect redundant hashCode() or Objects.hash() calls inside Objects.hash(...), and simplify single-argument Objects.hash(x) calls to Objects.hashCode(x).
    • LoopToTestParameter: Suggest migrating loops in unit tests to TestParameterInjector.
    • MissingJavadoc: Flag public types that are missing Javadoc comments (disabled by default).
    • PreferCharsetOverload: Prefer calling method and constructor overloads that accept a Charset over those that accept a String encoding name.
    • PreferPreconditions: Suggest using Guava's Preconditions instead of explicit if-throw statements for parameter validation (disabled by default).
    • RequireNonNullRefactoring: Refactor explicit if (x == null) { throw new NullPointerException(...); } checks to Objects.requireNonNull (disabled by default).
    • SimplifyTestParameter: Remove redundant explicit value lists on @TestParameter annotations for boolean and Enum types when all values are specified (disabled by default).
    • TraditionalJavadocToMarkdown: Convert traditional /** ... */ Javadoc comments into /// Markdown Javadoc comments (disabled by default).
    • ValueClassIdentity: Flag reliance on identity semantics (such as synchronization, WeakReference, IdentityHashMap, or System.identityHashCode) of value-based classes (disabled by default).

    Other changes:

    • CompareToZero: Upgraded from warning to error, and expanded to flag non-relational operations, unary negation, and switch statements/expressions on compareTo and compare results without Integer.signum.
    • IfChainToSwitch: Enabled by default as a warning.
    • UndefinedEquals: Merged ArrayAsKeyOfSetOrMap and CollectionUndefinedEquality into UndefinedEquals (retaining their names as altNames), and generalized detection of types without well-defined equals or hashCode across direct equality, collection containment, and hash-based containers.
    • EqualsIncompatibleType / TruthIncompatibleType: Flag equality comparisons between distinct record types (#6107).
    • ReferenceEquality: Allow == comparisons on private classes whose type hierarchy does not override Object.equals (#5865), private static final sentinel fields, Thread (#5900), and com.sun.source.tree.Tree.
    • PatternMatchingInstanceof: Support while and for loops, parenthesized expressions (#5843), and replacing additional redundant casts when the instanceof already introduces a pattern variable.
    • DistinctVarargsChecker: Expanded to check Objects.hash, CompletableFuture.allOf/anyOf, EnumSet.of, Sets.union/intersection/difference, Stream.concat, Math.min/max, and additional JDK, Guava, Protobuf, Truth, and Mockito methods.
    • MustBeClosedChecker: Require java.lang.foreign.Arena.ofConfined and Arena.ofShared to be closed.
    • [ImpossibleNullComparison](https://errorprone.info
  3. v2.50.0Error Prone 2.50.02026-06-10 · 2026-06-10 10:40 UTC
    查看更新说明

    New checks:

    Closed issues: #5553, #5649, #5778

    Full changelog: https://github.com/google/error-prone/compare/v2.49.0...v2.50.0

  4. v2.49.0Error Prone 2.49.02026-04-07 · 2026-04-07 10:59 UTC
    查看更新说明

    This release includes several changes to Matcher APIs, and removed some deprecated or problematic APIs:

    New checks:

    Closed issues: #2283, #3503, #5210, #5289, #5548, #5548, #5554, #5609, #5614, #5656

    Full changelog: https://github.com/google/error-prone/compare/v2.48.0...v2.49.0

  5. v2.48.0Error Prone 2.48.02026-02-27 · 2026-02-27 13:26 UTC
    查看更新说明

    Changes:

    New checks:

    Closed issues: #5529, #5537, #5522, #5521

    Full changelog: https://github.com/google/error-prone/compare/v2.47.0...v2.48.0

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    Error Prone

    Error Prone is a static analysis tool for Java that catches common programming mistakes at compile-time.

    public class ShortSet {
      public static void main (String[] args) {
        Set<Short> s = new HashSet<>();
        for (short i = 0; i < 100; i++) {
          s.add(i);
          s.remove(i - 1);
        }
        System.out.println(s.size());
      }
    }
    
    error: [CollectionIncompatibleType] Argument 'i - 1' should not be passed to this method;
    its type int is not compatible with its collection's type argument Short
          s.remove(i - 1);
                  ^
        (see https://errorprone.info/bugpattern/CollectionIncompatibleType)
    1 error
    

    Getting Started

    Our documentation is at errorprone.info.

    Error Prone works with Bazel, Maven, Ant, and Gradle. See our installation instructions for details.

    Developing Error Prone

    Developing and building Error Prone is documented on the wiki.

    Links