I got this Sonar Bug:
Use the original value instead. Rule: Neither "Math.abs" nor negation should be used on numbers that could be "MIN_VALUE"
in this method of compare date:
public int compareDates(MyDto a, MyDto b) {
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy hh:mm");
try {
Date dateA = sdf.parse(a.getStartDate() + " " + a.getStartHour());
Date dateB = sdf.parse(b.getStartDate() + " " + b.getStartHour());
return - dateA.compareTo(dateB); //Sonar BUG
} catch (ParseException e) {
logger.error("Unable to parse date: " + e.getMessage());
return 0;
}
}
I'm using this method to order collections of MyDto by date this way:
Collections.sort(myDtoList, (a,b) -> compareDates(a,b));
Now I really don't know what to do to amend. The integer given back from the compare can be negative or not, how can i solve to make SQ happy?