BackendBench
Coffee
Daily

Spot the Bug: the daily Java puzzle

One short Java snippet, one real bug, a new puzzle every day. Tap the line you think is wrong, then see why it fails and how to fix it. Your streak stays in your browser.

0๐Ÿ”ฅ day streak
0best streak
0bugs found

Loading today's bug

One line of this Java code is wrong. Tap it.

Loading the puzzle. It needs JavaScript.

Last four weeks

Green = solved, grey = not yet. Tap a past day to play it. Weeks start on Monday and use UTC dates.

Why spot-the-bug beats reading about bugs

Most Java bugs are not exotic. They are an <= where a < belonged, a == that compares references, a cron expression with five fields where the framework wants six. Reviewers catch them by pattern, and patterns are learned by seeing many small, concrete cases. Spot the Bug gives you one a day: short enough to finish over coffee, real enough that you will meet the same mistake in a pull request next week.

How a puzzle works

You see a snippet of 8 to 20 lines. Exactly one line contains the bug. Tap it. A wrong tap costs nothing but shows in your share card; the right tap reveals what goes wrong at runtime, the corrected line, how to avoid it next time and a link to the concept page for a deeper explanation. Difficulty follows the weekday, so Monday is a gentle start and the weekend is for the nasty ones: lazy loading outside a session, double-checked locking, the Integer cache.

The bug families

The bank has 132 puzzles in 22 families. Browse every puzzle with its full write-up on the all bugs page, or open a single family below.

  • Off-by-one errors. Loop bounds, indexes and lengths are the oldest source of bugs in programming.
  • Equality and identity. In Java == compares primitive values but only compares references for objects.
  • Numeric overflow and precision. Java integers wrap around silently when they exceed their range, with no exception.
  • Modifying while iterating. Collections detect structural changes made during iteration and throw ConcurrentModificationException, but only some of the time, and not at all for certain patterns.
  • Resource leaks. Files, streams, sockets, connections and statements hold operating system handles that the garbage collector will not release promptly.
  • Shared and static mutable state. Static fields and singleton beans are shared by every request and thread.
  • Exception handling mistakes. Swallowed exceptions, lost causes and returns in finally blocks hide failures until the data is already wrong.
  • Scheduling and cron mistakes. Cron dialects differ in field count and meaning.

See also the daily cron quiz and the Java concepts library.

Frequently asked questions

How does Spot the Bug choose the daily puzzle?

Everyone gets the same puzzle each UTC day. The day number counts from a fixed start date, the weekday sets the difficulty (Monday and Tuesday easy, Wednesday to Friday medium, weekend hard), and the puzzle inside that difficulty comes from a fixed shuffle, so every puzzle appears once before any repeats. There are 132 puzzles in the bank.

Where are my streak and results stored?

Only in your browser, in local storage. Nothing is sent to a server, there is no account, and clearing site data resets the streak. The share card contains only the text you choose to copy.

What counts toward the streak?

Solving the puzzle on its own UTC day. Past days from the calendar and practice puzzles are marked solved but do not extend the streak. You keep a streak until a whole day passes without solving.

What kinds of bugs are in the bank?

Off-by-one errors, == versus equals, integer overflow, ConcurrentModificationException, unclosed resources, shared mutable state, swallowed exceptions, wrong cron fields, SQL injection, race conditions, NullPointerException chains, floating point comparison, time zones and DST, reusing a stream, LazyInitializationException, @Transactional self-invocation and more. Each puzzle has exactly one real bug.

Can I practise with more puzzles?

Yes. Switch to Practice for a random puzzle, filtered by difficulty. Every puzzle also has a permanent page with the full explanation, linked from the browse page.

More tools you might need