Originally posted by MuraliRam Narasimhan:
A bug in Java
It's not a bug. As the API explains, "if the argument is equal to the value of Integer.MIN_VALUE, the most negative representable int value, the result is that same value, which is negative."
This is a consequence of how signed integral values are stored. As you probably know, the leading bit indicates whether a value is negative. And because zero is non-negative, there is 1 less positive value than there are negative values in the range of a signed integral value. In particular, int values range from -2147483648 to 2147483647.
Obviously, the absolute value of -2147483648 is 2147483648. However, this is one greater than what's allowed for an int, and so the result overflows to -2147483648.