Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

What is Error Prone and how does it differ from tools like SpotBugs?

Error Prone is a static analysis tool from Google that plugs into javac, the Java compiler, and reports bug patterns as compile errors or warnings during the normal build. It works on the compiler's syntax tree with full type information and can suggest or apply fixes. SpotBugs, by contrast, runs as a separate step after compilation and analyses the compiled bytecode.

Why this question is asked

Most teams already run some static analysis, but where it runs changes how much it helps. A warning that appears in a report ten minutes after the build is easy to ignore; an error that stops the compile on the developer's laptop gets fixed straight away. Interviewers ask this question to see whether we understand that difference and can pick the right tool for each job. In this answer, we will recap what static analysis is, see how Error Prone hooks into the compiler, compare it with SpotBugs step by step, and finish with NullAway, the nullness checker built on top of Error Prone.

1A Quick Recap of Static Analysis

Static analysis means examining code without running it, looking for patterns that are very likely to be bugs. A classic example is comparing two strings with == instead of equals(), or calling a method whose return value must be used and then throwing the result away. The compiler accepts this code because it is legal Java, but it almost never does what the author meant.

Tools differ in what they look at. Some read the source text, some read the compiler's internal model of the program, and some read the compiled class files. That choice decides when the tool can run, how fast it gives feedback and what kind of bugs it can see.

2How Error Prone Hooks Into javac

Error Prone is a plugin for javac. While javac compiles our code, it builds an abstract syntax tree, a tree of objects that represents every class, method, expression and statement, and it attaches type information to each node: which method a call resolves to, what type an expression has, which overload was chosen. Error Prone registers a set of checks, called bug patterns, that walk this tree. Each check looks for one kind of mistake.

When a check matches, Error Prone reports it through the compiler's own diagnostics. A check at ERROR severity fails the compile exactly like a type error; a WARNING check prints a warning. So there is no separate tool to run and no report to open: the problem appears in the same place as every other compile error, in the IDE or the terminal.

Java
import java.util.Set;
class Example {
boolean sameName(String a, String b) {
return a == b; // warning: strings compared with ==, reference equality
}
void normalise(String s) {
s.trim(); // error: [ReturnValueIgnored] return value of 'trim' must be used
}
boolean hasId(Set<Long> ids, int id) {
return ids.contains(id); // error: [CollectionIncompatibleType] Integer can never be in Set<Long>
}
}

Notice the last example. The set holds Long values, but we pass an int, which is boxed to Integer, so contains() can never return true. Only a tool that knows the exact generic types can spot this, and that is exactly what the compiler's type information gives Error Prone. Many checks also carry a suggested fix, such as replacing a == b with a.equals(b), and Error Prone can apply these fixes automatically in patch mode.

3How SpotBugs Works Differently

SpotBugs is the successor of FindBugs. It does not run inside the compiler. It runs afterwards, usually as a Maven or Gradle task bound to the verify phase, and it reads the compiled .class files. It analyses bytecode, the instructions the JVM executes, and looks for patterns there: possible null dereferences along certain paths, streams that are opened and never closed, mutable objects exposed from getters, and many more. Plugins such as Find Security Bugs add security patterns.

Working on bytecode has real advantages. SpotBugs can analyse any compiled code, including code generated by other tools, and its data-flow analysis follows values through branches inside a method. The cost is that it is a separate step, it usually produces a report rather than a compile error, and it has lost some source detail such as exact expressions and comments. Its findings can also be noisier, so teams often keep a filter file of excluded patterns.

Error Prone and SpotBugs side by side
AspectError ProneSpotBugs
Runsinside javac, during compilationafter compilation, as a separate task
Readssyntax tree with type informationcompiled bytecode (.class files)
Reportscompile errors and warningsa report (XML, HTML), can fail the build
Fixessuggested fixes, patch mode can apply themno automatic fixes
Feedbackimmediate, in the IDE and terminallater, in CI or a verify step
Extends withcustom BugCheckers, NullAwayplugins such as Find Security Bugs
Error Prone gives feedback while we compile; SpotBugs looks at the result afterwards.

So the two tools are complementary. Error Prone is fast, precise feedback at compile time on mistakes visible in the source and types. SpotBugs is a broader bytecode sweep that catches some path-based problems Error Prone does not look for. Many teams run Error Prone on every compile and SpotBugs, or a platform such as SonarQube, in CI.

4NullAway: A Nullness Checker Built on Error Prone

Because Error Prone is a framework for checks, other projects build on it. The best known is NullAway, from Uber. NullAway is an Error Prone plugin that checks nullness annotations: it reports a dereference of a value that may be null, a null passed where a non-null parameter is expected, or a nullable value returned from a method declared non-null.

NullAway is designed to be fast enough to run on every compile, which is why it relies on annotations such as JSpecify's @Nullable instead of trying to infer everything. Together with Error Prone, it turns many NullPointerExceptions into compile errors. Spring Framework 7 itself is checked with NullAway, which is a good sign of how practical the combination has become.

5Follow-up questions

Can Error Prone and SpotBugs run in the same build?

Yes, and many builds do. Error Prone runs as part of the compile step, so it adds a little time to every compilation. SpotBugs is a separate plugin goal, typically in the verify phase, so it runs on CI and on a full local build. The overlap between their checks is small enough that running both is worthwhile, as long as we keep the noisier SpotBugs patterns filtered.

Does Error Prone slow down compilation?

It adds work, because every check walks the syntax tree. The overhead is usually modest, often in the range of ten to twenty percent of compile time, but it depends on the code base and the checks enabled, so it is worth measuring on our own build rather than trusting a number.

Can we write our own Error Prone checks?

Yes. A custom check is a class extending BugChecker that implements matcher interfaces for the tree nodes it cares about, for example method invocations. Teams use this to ban internal APIs or enforce local conventions, and the check can supply a suggested fix just like the built-in ones.

6Conclusion

In this answer, we saw that Error Prone is a javac plugin from Google that works on the syntax tree with type information, reports bug patterns as ordinary compile errors or warnings, and can suggest fixes. SpotBugs runs after compilation on bytecode as a separate step and produces a report, which makes it a useful complement rather than a replacement. We also met NullAway, the nullness checker built on Error Prone.

What to say in the interviewAbout 80 seconds aloud

Open with

Error Prone is Google's static analysis tool, and the key thing about it is that it runs as a javac plugin. While the compiler builds the syntax tree and resolves types, Error Prone runs its bug-pattern checks on that tree, so it knows exactly which method is called and what the generic types are.

Then, if they want more

It can catch things like calling contains with an Integer on a Set of Long, or ignoring the result of trim. Problems show up as normal compile errors or warnings, so the feedback is immediate, in the IDE or the terminal, and many checks come with a suggested fix that patch mode can apply. SpotBugs works differently.

It runs after compilation as a separate step, reads the bytecode, and does data-flow analysis, so it finds things like unclosed resources or possible null paths, but it produces a report rather than stopping the compile, and it cannot fix anything. So I see them as complementary: Error Prone on every compile, SpotBugs or Sonar in CI.

And Error Prone is also a platform: NullAway, from Uber, is built on top of it and checks nullness annotations such as JSpecify at compile time, which is how Spring Framework 7 itself is checked.

About this answer

Last updated
12 November 2026
Versions it names
Spring Framework 7
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What is Error Prone and how does it differ from tools like SpotBugs?": https://scrivio-interview-library.netlify.app/java/code-quality-tools/6b74b94ea4/