Quick revision
The short answer
Error Prone must be wired into the compiler plugin with the -Xplugin:ErrorProne argument and a few extra javac flags, and on JDK 16 and later it also needs --add-exports and --add-opens options because it uses compiler internals. Its version must match the JDK we compile with. We should start with the default ERROR checks, promote chosen WARNING checks to errors over time, use patch mode to fix existing code in bulk, and measure the extra build time.
What to remember
In this answer, we saw that Error Prone is added to the compiler plugin with -Xplugin:ErrorProne and a few javac flags, and that on recent JDKs the JVM running javac needs --add-exports and --add-opens for the compiler internals. We pin its version to the JDK, start with the default ERROR checks, promote selected warnings to errors after patch mode has fixed the existing code, exclude generated sources, and measure the build-time cost.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Error Prone must be wired into the compiler plugin with the -Xplugin:ErrorProne argument and a few extra javac flags, and on JDK 16 and later it also needs --add-exports and --add-opens options because it uses compiler internals. Its version must match the JDK we compile with. We should start with the default ERROR checks, promote chosen WARNING checks to errors over time, use patch mode to fix existing code in bulk, and measure the extra build time.
Why this question is asked
Adding a compiler plugin to one small project takes ten minutes. Adding it to a build with 150 modules, generated code, and several teams is a small project of its own, and it fails in predictable ways: cryptic module errors, a broken build after a JDK upgrade, or so many warnings that nobody reads them. Interviewers ask this to see whether we have done it for real. In this answer, we will set up Error Prone in Maven and Gradle, explain why the module flags are needed, look at version compatibility, plan the rollout of checks, use patch mode, and talk about build time.
1Wiring Error Prone Into the Compiler
Error Prone is not a separate tool we run; it is a javac plugin. So we add its jar to the compiler's annotation processor path and pass -Xplugin:ErrorProne to javac. It also needs -XDcompilePolicy=simple, which makes javac process each class through all stages in order so the checks see complete type information. Recent releases also ask for --should-stop=ifError=FLOW; check the installation notes for your version.
The harder part is the JDK module system. Since JDK 16 the compiler's internal packages, such as com.sun.tools.javac.code and com.sun.tools.javac.tree, are strongly encapsulated. Error Prone reaches into them, so the JVM that runs javac must be started with --add-exports for those packages, and --add-opens for a couple of them. Without these, the build fails with an IllegalAccessError mentioning a module that does not export a package.
Notice where the module flags go. Maven runs javac inside its own JVM by default, so the flags must be given to that JVM, which is what .mvn/jvm.config does. The alternative is fork=true on the compiler plugin and passing each flag with a -J prefix. In Gradle the net.ltgt.errorprone plugin adds the flags for us, and we only declare errorprone("com.google.errorprone:error_prone_core:<version>") as a dependency. In a large build, put this configuration once in the parent POM or a convention plugin, never copied into each module.
2Matching the Error Prone Version to the JDK
Because Error Prone uses compiler internals, each release supports a range of JDK versions. An old Error Prone release can crash on a new JDK with errors such as NoSuchMethodError inside com.sun.tools.javac, and new releases drop support for old JDKs; recent ones require at least JDK 17 to run. The release notes say which JDKs are supported.
So in practice we pin the Error Prone version in one place and treat a JDK upgrade and an Error Prone upgrade as linked changes. When the platform team moves the build from JDK 21 to 25, the same pull request bumps Error Prone. A dependency bot can propose Error Prone upgrades, but new releases also add checks, so an upgrade can turn a green build red; plan for that.
3Rolling Out the Checks
Out of the box, Error Prone enables a set of checks at ERROR severity: patterns that are almost always real bugs, such as CollectionIncompatibleType or DeadException. On an existing code base these usually find a small number of genuine problems, which is a good first win. We fix those, merge, and the build is now protected against those patterns.
The WARNING checks are where noise lives. If we leave hundreds of warnings in the log, nobody looks at them. A better approach is to pick a handful of warnings that matter to us, fix the existing occurrences, and then promote them to errors with -Xep:CheckName:ERROR, so they can never come back. Repeat every few weeks. Checks we decide against are turned off explicitly with -Xep:CheckName:OFF, with a comment explaining why.
- Pin one Error Prone versionmatched to the JDK, set in the parent build
- Enable default ERROR checksfix the real bugs they find
- Exclude generated code-
XepDisableWarningsInGeneratedCode - Pick a few WARNING checksthe ones the team agrees matter
- Patch existing code-
XepPatchChecksandIN_PLACE - Promote them to ERROR-Xep:
CheckName:ERROR - More checks worth it?YesPick the next fewNoKeep the build green and stop
7 steps in order. Play them, or step through them one at a time.
Each round fixes existing code first, then makes the check an error so it cannot come back.
Generated code needs special care. Code from annotation processors, OpenAPI generators or protobuf is not ours to fix, so we exclude it with -XepDisableWarningsInGeneratedCode and -XepExcludedPaths. For a single false positive in our own code, @SuppressWarnings("CheckName") on the smallest possible element is the escape hatch.
4Fixing Existing Code With Patch Mode
Turning a check into an error is easy when there are five violations and painful when there are 800. Patch mode solves this. Instead of reporting, Error Prone applies the suggested fixes of the named checks.
With -XepPatchLocation:IN_PLACE the files are rewritten directly; without it, Error Prone writes a patch file we can review. Notice that we run this as a separate, reviewed change, ideally one check per pull request, so reviewers can see the pattern. After it lands, we promote the check to ERROR in the same or next change.
5Measuring the Cost in Build Time
Every check walks the syntax tree, so compilation gets slower. The overhead is often around ten to twenty percent of compile time, but it varies with the code and the checks enabled, so we measure it: compare a clean compile before and after, on CI and on a typical laptop, and look at the slowest modules. Turning off a few expensive checks we do not care about, or disabling Error Prone for huge generated modules, usually brings it back to an acceptable level. A build that becomes noticeably slower without explanation is the fastest way to lose developers' support.
6Follow-up questions
What error do we get without the --add-exports flags?
Typically an IllegalAccessError or an exception saying a class cannot access a class in module jdk.compiler because that module does not export the package to the unnamed module. The fix is the list of --add-exports and --add-opens flags from the installation guide, given to the JVM that runs javac.
Should Error Prone run in the IDE as well?
IntelliJ IDEA can use Error Prone through a plugin, but many teams rely on the build: running the Maven or Gradle compile surfaces the errors with the same configuration, and the IDE's own inspections cover a lot of the same ground. What matters is that CI enforces the same configuration everyone uses locally.
How do we handle a check that produces false positives?
First suppress the specific occurrence with @SuppressWarnings on the smallest element, with a comment. If the check is wrong for our code base in general, turn it off with -Xep:CheckName:OFF in the shared configuration and record why, so the decision is visible rather than scattered across files.
7Conclusion
In this answer, we saw that Error Prone is added to the compiler plugin with -Xplugin:ErrorProne and a few javac flags, and that on recent JDKs the JVM running javac needs --add-exports and --add-opens for the compiler internals. We pin its version to the JDK, start with the default ERROR checks, promote selected warnings to errors after patch mode has fixed the existing code, exclude generated sources, and measure the build-time cost.
Open with
The first thing I would expect is setup friction. Error Prone is a javac plugin, so it goes on the annotation processor path with -Xplugin:ErrorProne and -XDcompilePolicy=simple, and on JDK 16 and later the JVM that runs javac needs a list of --add-exports and --add-opens flags for the compiler internals.
Then, if they want more
In Maven that means .mvn/jvm.config or a forked compiler; in Gradle the errorprone plugin handles it. I would put all of this in the parent POM or a convention plugin, once. Second, version compatibility: Error Prone depends on javac internals, so its version has to match the JDK, and I would upgrade the two together. Third, the rollout of checks.
I start with the default ERROR checks, which find a few real bugs, and exclude generated code. Then I pick a small number of warnings the team cares about, run patch mode with -XepPatchChecks and IN_PLACE to fix the existing code in a reviewed pull request, and promote those checks to ERROR so they never come back.
Leaving hundreds of warnings in the log just trains people to ignore them. Finally I measure compile time before and after, because a slower build is the quickest way to lose support, and switch off expensive checks we do not need.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 16, Java 17, Java 21
- 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.
- Official documentation
- Apache Maven guides, Gradle user manual
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 "You want to add Error Prone to a large Maven or Gradle build. What setup and rollout...": https://scrivio-interview-library.netlify.app/java/code-quality-tools/3252809e85/