Spotify

Underflow bug

Aug 1, 2015Lukáš Poláček
Underflow bug
SummaryAI, from the source post

This post describes a specific integer underflow bug in a round-robin algorithm implementation. It details the incorrect behavior of an `AtomicInteger` when its value reached -1, leading to `Integer.MIN_VALUE` being returned instead of a positive index. The post explains integer representation and provides two code fixes: one by adjusting the subtraction to `Integer.MIN_VALUE` and another by using a bitwise AND with `Integer.MAX_VALUE` to clear the sign bit. It also quantifies the bug's impact and duration.