Quick revision
The short answer
We introduce the tools without stopping delivery by never asking anyone to fix 40,000 warnings at once. We start with a small rule set focused on correctness and security, record the existing warnings as a baseline or exclusion file and fail the build only on new ones, and fix high-value categories of old warnings in focused clean-up work over time. The tools run both in CI and in the IDE so developers see results early, and we remove noisy rules quickly, because the whole approach depends on developers trusting the findings.
What to remember
In this answer, we saw that introducing SpotBugs and PMD into a 10-year-old codebase works when we start with a small rule set for correctness and security, record existing warnings in a baseline and fail only on new ones, clean up high-value categories in focused work over time, run the same configuration in CI and the IDE, and remove noisy rules quickly so developers keep trusting the findings. Delivery never stops, because nobody is blocked by warnings they did not create.
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.
We introduce the tools without stopping delivery by never asking anyone to fix 40,000 warnings at once. We start with a small rule set focused on correctness and security, record the existing warnings as a baseline or exclusion file and fail the build only on new ones, and fix high-value categories of old warnings in focused clean-up work over time. The tools run both in CI and in the IDE so developers see results early, and we remove noisy rules quickly, because the whole approach depends on developers trusting the findings.
Why this question is asked
Turning on static analysis in an old codebase usually goes one of two ways. Either the team enables the default rules, sees tens of thousands of warnings, and switches the tool off again within a week, or someone tries to fix everything in a big clean-up that touches thousands of files, conflicts with every feature branch and introduces bugs of its own. Interviewers ask this design question because a good answer shows how to bring a tool into a living codebase gradually. In this answer, we will see why the default approach fails, choose a starting rule set, set up a baseline so only new warnings fail the build, plan the clean-up of old ones, and make the tools part of developers' normal loop.
1Why 40,000 Warnings Is the Wrong Starting Point
A count of 40,000 tells us almost nothing about risk. In a typical legacy codebase, most of those warnings come from a few style and convention rules applied to every file, such as missing final modifiers, long methods or naming patterns. Hidden among them are perhaps a few hundred warnings that point to real bugs: possible null dereferences, ignored exceptions, broken equals methods, or SQL built from strings.
If we fail the build on all of them, nothing ships. If we only report them, nobody reads a list of 40,000. Either way the few hundred important findings are lost in the noise. So the plan has to separate what matters from what does not, and separate old warnings from new ones.
2Start With a Small Rule Set for Correctness and Security
We begin with rules that find real defects and have a low false positive rate. In SpotBugs, that means categories such as CORRECTNESS, MT_CORRECTNESS (multithreading), BAD_PRACTICE selectively, and SECURITY with the FindSecBugs plugin. In PMD, we start from the errorprone category and a few rules from bestpractices, such as empty catch blocks and unused private methods, and leave design and code style rules for later. Both tools read their rule selection from a file that we keep in the repository and version like code.
Notice the effect: the same codebase now shows under 2,000 warnings instead of 40,000, and most of them are worth reading. Rule names and categories change between PMD and SpotBugs versions, so check yours; the principle is to start narrow and grow.
3Record a Baseline and Fail Only on New Warnings
Even 1,940 warnings cannot be fixed before the next release, so we accept the existing ones for now and stop new ones from appearing. This is called a baseline: a recorded list of today's warnings that the build ignores, while any warning not on the list fails it. SpotBugs supports this directly by excluding bugs listed in a previous result file (its excludeBugs option; check your Maven or Gradle plugin for the property name). For PMD, depending on the version and plugin, we can generate an exclusion file from the current report or use a tool that compares the report with the main branch and reports only differences.
- Analysis finds a warningSpotBugs or PMD with the core rules
- Is it in the baseline file?Yesignored for now, tracked for clean-upNocontinue
- Fail the buildthe change introduced it, so the author fixes it now
- Clean-up removes baseline entries over timeregenerate the baseline after each fix
4 steps in order. Play them, or step through them one at a time.
The rule is fair to developers: nobody is blocked by warnings they did not create, but nobody can add new ones. When someone edits a file with old warnings, the baseline still covers them, so small changes are not turned into big clean-ups. We regenerate the baseline when warnings are fixed, so it only shrinks, and we review any change that makes it grow.
4Clean Up High-Value Categories Over Time
The baseline is a backlog, and we work it by value, not by file. We sort the old warnings by category and pick the ones with real risk first: possible null dereferences on frequently used paths, security findings, ignored exceptions in transaction or payment code, and concurrency bugs. Each clean-up is a focused, small piece of work, for example all broken equals and hashCode pairs in one module, done in a few pull requests that are easy to review.
Focused clean-ups avoid the problems of a big-bang fix. They touch fewer files at once, so they conflict less with feature work, and each change is understood by its reviewer. Teams often reserve a little time each sprint or attach clean-up to work in the same area. Tracking the baseline size per category on a dashboard shows progress and keeps it from stalling.
5Run the Tools in CI and in the IDE
CI is where the rules are enforced, but CI is the slowest place to learn about a problem: the developer has already moved on when the result arrives. So we also make the same rules visible in the IDE. IntelliJ IDEA and Eclipse both have SpotBugs and PMD plugins that can read the project's rule files, and running the tools in the local build, for example as part of mvn verify or ./gradlew check, gives the same answer as CI.
The important detail is one configuration. The rule files and the baseline live in the repository and are used by CI, the local build and the IDE plugins alike, so a developer never sees a warning in CI that their own machine did not show.
6Remove Noisy Rules Quickly
The last part of the plan is about trust. Within the first weeks, some rules will turn out to be noisy in this codebase: they fire often, and developers agree the findings are not worth fixing. If those rules stay, developers start suppressing warnings by reflex and the real ones get suppressed too. So we watch suppressions and complaints closely at the start, and when a rule is clearly noisy, we remove it or tune it within days, not months.
Rules are added the same careful way they are removed: one at a time, with the team's agreement, and with the existing warnings for the new rule added to the baseline. Over a year, the rule set grows into something the team trusts, and the baseline shrinks towards zero for the categories that matter.
7Follow-up questions
Why not just use @SuppressWarnings on the old code?
Annotating thousands of places is itself a large change that touches every file, and the annotations hide the warnings permanently, so they never come back for clean-up. A baseline file keeps the code untouched, keeps the old warnings visible as a backlog, and shrinks as they are fixed. We still use suppressions for individual, reviewed cases where a warning is genuinely wrong.
How do you choose which old warnings to fix first?
By risk and by exposure. Security and correctness findings in code that handles money, personal data or concurrency come first, then findings in frequently changed or frequently executed code. Production incidents are a good guide: if a past incident came from a bug class a rule detects, every remaining instance of that rule is high priority.
Would you use SonarQube instead of SpotBugs and PMD?
It is a reasonable alternative, and its new-code approach gives the same effect as a baseline without managing files. Many teams use both, with SpotBugs and PMD in the build for fast local feedback and SonarQube for history and reporting. What matters most is the same strategy either way: a small trusted rule set, failing only on new problems, and a planned clean-up of old ones.
8Conclusion
In this answer, we saw that introducing SpotBugs and PMD into a 10-year-old codebase works when we start with a small rule set for correctness and security, record existing warnings in a baseline and fail only on new ones, clean up high-value categories in focused work over time, run the same configuration in CI and the IDE, and remove noisy rules quickly so developers keep trusting the findings. Delivery never stops, because nobody is blocked by warnings they did not create.
Open with
I would never start from the 40,000. Most of them come from a few style and convention rules, and the real bugs are a small fraction hidden inside.
Then, if they want more
So first I would pick a small rule set focused on correctness and security: SpotBugs categories like CORRECTNESS, multithreading correctness and FindSecBugs for security, and PMD's errorprone rules plus a few best practices. That typically cuts the count to a couple of thousand warnings that are mostly worth reading.
Second, I would record the current warnings as a baseline, using SpotBugs' option to exclude bugs from a previous result and an exclusion file or diff-based reporting for PMD, and fail the build only on new warnings. Nobody is blocked by old problems, but nobody can add new ones.
Third, I would plan clean-ups by value: null dereferences, security findings, swallowed exceptions and concurrency bugs first, in small focused pull requests, and shrink the baseline as they are fixed. Fourth, the same rule files run in CI, the local build and the IDE plugins, so developers see findings early.
And finally I would watch suppressions and remove or tune noisy rules within days, because the approach only works if developers trust the findings.
About this answer
- Last updated
- 12 November 2026
- 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 join a team with a 10-year-old codebase producing 40,000 static analysis warnings....": https://scrivio-interview-library.netlify.app/java/code-quality-tools/2111d9ab1d/