== Why is this an issue?

This rule involves the use of `Math.abs` and negation on numbers that could be `MIN_VALUE`.
It is a problem because it can lead to incorrect results and unexpected behavior in the program.

When `Math.abs` and negation are used on numbers that could be `MIN_VALUE`, the result can be incorrect due to integer overflow.
Common methods that can return a `MIN_VALUE` and raise an issue when used together with `Math.abs` are:

- `Random.nextInt()` and `Random.nextLong()`
- `hashCode()`
- `compareTo()`

Alternatively, the `absExact()` method throws an `ArithmeticException` for `MIN_VALUE`.

=== Noncompliant code example

[source,java,diff-id=1,diff-type=noncompliant]
----
public void doSomething(String str) {
  if (Math.abs(str.hashCode()) > 0) { // Noncompliant
    // ...
  }
}
----

=== Compliant solution

[source,java,diff-id=1,diff-type=compliant]
----
public void doSomething(String str) {
  if (str.hashCode() != 0) {
    // ...
  }
}
----

== Resources

* https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/lang/Math.html#abs(int)[Oracle SDK 20 - Math.abs(int)]


ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

=== Message

Use the original value instead.


endif::env-github,rspecator-view[]
