hazelcast/hazelcast — pull request #684 by MrEasy (2013-08-15 12:37:18+00:00)
Title: Prevent IndexOutOfBoundsException when index reaches Integer.MAX_VALUE + 2

When the cast to int (which is unneeded btw. if you use an Integer in the first place) returns a negative value, then modulo will be -1, which throws an IndexOutOfBoundsException.
Patch fixes this, by ensuring a positive value.

long longNumber = Integer.MAX_VALUE + 2;
int intNumber = (int)longNumber;
System.out.println("longNumber = " + longNumber);
System.out.println("intNumber = " + intNumber);
System.out.println("mod2 = " + intNumber % 2);
System.out.println("mod2 = " + (intNumber % 2 + 2) % 2);