I do not know this language (Java?), but doesn't the line
int offset = (int) (((size - 1) * ((long) key - min)) / (max - min));
compute (max - min) as an int (potentially overflowing), and then convert it to long, defeating the precautions obviously taken against this kind of event with the cast to long elsewhere?