The 37th of March — Java Bug Hunt
Inspired by Java's own java.util.Calendar in lenient mode — the API that happily turns "March 37th" into April 6th.
- Language: Java
- Layer: Backend
- Difficulty: Easy
- Concepts: Validation, Dates
- Modelled on: java.util.Calendar
- Visible tests: valid dates pass through; impossible days are rejected, not rolled; leap day is valid only in leap years
- Reward: 50 XP for a complete fix
Incident
- Severity: SEV-2 (priority: High (compliance))
- Ticket: BUG-LENIENT
- Reported by: legal ops
- Time to fix: 10 minutes, the target for an easy incident
Failing checks on the shipped build
- impossible days are rejected, not rolled — March 37th must be an error: expected condition to hold
- leap day is valid only in leap years — expected [2024, 2, 29] but got [2024, 3, 1]
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 Java's own java.util.Calendar in lenient mode — the API that happily turns "March 37th" into April 6th. Wonderful for math, catastrophic for validating user input: typos silently become different dates on legal documents.
DateInput.java must reject impossible dates, not "fix" them.
Bug report
BUG-LENIENT · Priority: High (compliance) · Reported by: legal ops
validate(year, month, day) -> int[]{y,m,d} or IllegalArgumentException:
- month 1..12, day 1..(length of that month, leap-aware)
- NO rollover. 2024-03-37 is an error, not April 6th.
Observed: contract dates typed with fat fingers silently shift by days.
Logs
[contracts] entered 2024-03-37, stored 2024-04-06The code as shipped
DateInput.java (editable)
class DateInput {
static final int[] DAYS = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
static boolean isLeap(int year) {
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
}
static int[] validate(int year, int month, int day) {
while (month > 12) {
month -= 12;
year++;
}
int len = DAYS[month - 1];
while (day > len) {
day -= len;
month++;
if (month > 12) { month = 1; year++; }
len = DAYS[month - 1];
}
return new int[] { year, month, day };
}
}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.