https://bz.apache.org/bugzilla/show_bug.cgi?id=58535
Bug ID: 58535
Summary: ReverseComparator unsafely negates result
Product: Tomcat 8
Version: trunk
Hardware: PC
OS: Mac OS X 10.1
Status: NEW
Severity: normal
Priority: P2
Component: Catalina
Assignee: [email protected]
Reporter: [email protected]
Created attachment 33210
--> https://bz.apache.org/bugzilla/attachment.cgi?id=33210&action=edit
Patch to avoid negation risk
Consider the code:
@Override
public int compare(Session o1, Session o2) {
int returnValue = comparator.compare(o1, o2);
return (- returnValue);
}
This code negates the return value of the compare method. This is a
questionable or bad programming practice, since if the return value is
Integer.MIN_VALUE, negating the return value won't negate the sign of the
result. You can achieve the same intended result by reversing the order of the
operands rather than by negating the results.
See
http://findbugs.sourceforge.net/bugDescriptions.html#RV_NEGATING_RESULT_OF_COMPARETO
Recommend the following:
@Override
public int compare(Session o1, Session o2) {
// Note that comparing o2 with o1 to get reverse result...
return comparator.compare(o2, o1);
}
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]