When numbers lie: the Java equality bug every dev hits at least once
dev.to·15h·
Discuss: DEV
Flag this post

A deep dive into Java’s integer cache, why == sometimes betrays you, and how a tiny quirk caused a massive bug in production.

Ever had code look you dead in the face and lie to you? That’s what Java did to me when I first discovered that 1 == 1 happily returns true… but 1000 == 1000 betrays you with a cold, hard false. Same number, same syntax, completely different vibes.

At first, I thought I was losing it. I reran the code, rebuilt, even asked a teammate to sanity check. Nope. Java wasn’t bugged I was. Turns out I had stumbled into one of those hidden traps that separates “I can code” from “I can debug at 3 cups of coffee deep.”

And the worst part? This wasn’t just a classroom curiosity. This exact bug once tanked part of an auth system I worked on. IDs under …

Similar Posts

Loading similar posts...