A Century of Missing Interest — Java Bug Hunt
Inspired by the interest-calculation bugs that have triggered real banking remediations: integer division runs before multiplication, rate / 100 becomes…
- Language: Java
- Layer: Backend
- Difficulty: Medium
- Concepts: Integer Division, Finance
- Modelled on: Core banking
- Visible tests: one year of five percent; two years compound; zero years returns the principal
- Reward: 50 XP for a complete fix
Incident
- Severity: SEV-1 (priority: Critical (regulatory))
- Ticket: BUG-DIV0INT
- Reported by: core banking
- Time to fix: 20 minutes, the target for a medium incident
Failing checks on the shipped build
- one year of five percent — expected 10500 but got 10000
- two years compound — expected 11025 but got 10000
How to work this incident
- Read the report: write down the expected behaviour and the actual one in a sentence each.
- Reproduce it: run the visible tests and find the failing check that matches the report.
- Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
- Follow the request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
- Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.
Briefing
Inspired by the interest-calculation bugs that have triggered real banking remediations: integer division runs before multiplication, rate / 100 becomes zero, and a decade of compounding earns exactly nothing.
Interest.java compounds yearly, in integer cents.
Bug report
BUG-DIV0INT · Priority: Critical (regulatory) · Reported by: core banking
compound(principalCents, ratePercent, years):
- one compounding per year: value = value * (100 + rate) / 100 (floor)
- 10000 cents at 5% for 1 year -> 10500; 2 years -> 11025
Observed: every account earned 0 interest — 5 / 100 is 0 in integer math.
Logs
[interest] 10000 @ 5% x 10y -> 10000The code as shipped
Interest.java (editable)
class Interest {
static long compound(long principalCents, int ratePercent, int years) {
long value = principalCents;
for (int i = 0; i < years; i++) {
value = value + value * (ratePercent / 100);
}
return value;
}
}Open the hunt to start the incident clock, edit the files, run the visible tests and submit against the hidden ones, then write the root cause down. More Java bug hunts.