
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
39 lines
936 B
Plaintext
39 lines
936 B
Plaintext
== Why is this an issue?
|
|
|
|
It is the sign, rather than the magnitude of the value returned from ``++compareTo++`` that matters. Returning ``++Integer.MIN_VALUE++`` does _not_ convey a higher degree of inequality, and doing so can cause errors because the return value of ``++compareTo++`` is sometimes inversed, with the expectation that negative values become positive. However, inversing ``++Integer.MIN_VALUE++`` yields ``++Integer.MIN_VALUE++`` rather than ``++Integer.MAX_VALUE++``.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,java]
|
|
----
|
|
public int compareTo(MyClass) {
|
|
if (condition) {
|
|
return Integer.MIN_VALUE; // Noncompliant
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,java]
|
|
----
|
|
public int compareTo(MyClass) {
|
|
if (condition) {
|
|
return -1;
|
|
}
|
|
----
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Simply return -1.
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|