The Year 2038 Problem — Java Bug Hunt
Inspired by the countdown every 32-bit Unix system is on: at 03:14:07 UTC on January 19, 2038, signed 32-bit epoch seconds wrap negative and the clock jumps…
- Language: Java
- Layer: Backend
- Difficulty: Easy
- Concepts: Time, Overflow
- Modelled on: Unix time
- Visible tests: near-term scheduling is exact; crossing 2^31 stays positive
- Reward: 50 XP for a complete fix
Incident
- Severity: SEV-3
- Time to fix: 10 minutes, the target for an easy incident
Failing checks on the shipped build
- crossing 2^31 stays positive — expected 2200000000 but got -2094967296
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 countdown every 32-bit Unix system is on: at 03:14:07 UTC on January 19, 2038, signed 32-bit epoch seconds wrap negative and the clock jumps to 1901.
Epoch.java schedules future timestamps. It still lives in 32 bits.
Bug report
BUG-2038 · Reported by: infra futures team
futureTimestamp(nowSeconds, deltaSeconds) must stay exact past 2^31. Scheduling 5 years from 2035 currently produces a NEGATIVE timestamp, and every TTL comparison after it inverts.
Logs
[sched] now=2051222400 (+5y) -> -2085744896The code as shipped
Epoch.java (editable)
class Epoch {
// Seconds since 1970 for a moment delta seconds in the future.
static long futureTimestamp(long nowSeconds, long deltaSeconds) {
int result = (int) (nowSeconds + deltaSeconds);
return result;
}
}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.