The Autosave That Cut You Off — Java Bug Hunt

Inspired by document editors that save while you're typing — snapshotting half-finished sentences — or save constantly with no edits at all.

  • Language: Java
  • Layer: Frontend
  • Difficulty: Medium
  • Concepts: Debounce, Timers
  • Modelled on: Document editors
  • Visible tests: no edits means no save; typing right now blocks the save; a quiet period after edits saves
  • Reward: 50 XP for a complete fix

Briefing

Inspired by document editors that save while you're typing — snapshotting half-finished sentences — or save constantly with no edits at all. Autosave should fire only after a quiet period follows an actual edit.

Autosave.java gets the timestamps; the logic is inverted.

Bug report

BUG-AUTOSAVE · Reported by: docs team

shouldSave(lastSaveMs, lastEditMs, nowMs) with a 2000ms quiet period:

  • there must BE unsaved edits: lastEditMs > lastSaveMs
  • and the user must have been quiet: nowMs - lastEditMs >= 2000

Observed: it saves every 2s regardless of edits, including mid-keystroke.

Logs

[docs] snapshot saved mid-word: "The quarterly resul"

The code as shipped

Autosave.java (editable)

class Autosave {
    static final long QUIET_MS = 2000;

    static boolean shouldSave(long lastSaveMs, long lastEditMs, long nowMs) {
        return nowMs - lastSaveMs >= QUIET_MS;
    }
}

Open the hunt to edit the files, run the visible tests and submit against the hidden ones. More Java bug hunts.