Actually, when I search this in kafka code, It does not use the math.abs() to convert the negative to positive.
It use that:
public static int toPositive(int number) {
return number & 0x7fffffff;
}
So It can solve the problem you worried even if the number is 2147483648, it will be converted to 0
A cheap way to deterministically convert a number to a positive value. When the input is
positive, the original value is returned. When the input number is negative, the returned
positive value is the original value bit AND against 0x7fffffff which is not its absolutely
value.