Details
-
Type:
Bug Detection
-
Status: Active
-
Resolution: Unresolved
-
Labels:
-
Message:Only the sign of the result should be examined.
-
Default Severity:Minor
-
Impact:Low
-
Likelihood:Low
-
Default Quality Profiles:Sonar way
-
Covered Languages:Java
-
Remediation Function:Constant/Issue
-
Constant Cost:5min
-
Analysis Scope:Main Sources
-
FindBugs:RV_CHECK_COMPARETO_FOR_SPECIFIC_RETURN_VALUE
Description
While most compareTo methods return -1, 0, or 1, some do not, and testing the result of a compareTo against a specific value other than 0 could result in false negatives.
Noncompliant Code Example
if (myClass.compareTo(arg) == -1) { // Noncompliant // ... }
Compliant Solution
if (myClass.compareTo(arg) < 0) { // ... }
Attachments
Issue Links
- is related to
-
SONARJAVA-3950 Add quick fixes for S2200 (CompareToResultTestCheck)
-
- Closed
-
-
SONARJAVA-3178 S2200 does not handle properly unary post/pre-fix increment/decrement
-
- Closed
-
- links to