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);