RV_RETURN_VALUE_OF_PUTIFABSENT_IGNORED works fine for ConcurrentMap. However, in JDK 8 the method putIfAbsent() has been added to Map interface. Findbugs 3.0.0 does not report this bug if Map is used.
Example:
import java.util.Calendar;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
public class CalendarUpdater {
private final ConcurrentMap<String, Calendar> calendars = new ConcurrentHashMap<>();
private final Map<String, Calendar> newCalendars = new ConcurrentHashMap<>();
public Calendar update(String key, Calendar newValue) {
calendars.putIfAbsent(key, newValue);
newValue.add(Calendar.DAY_OF_MONTH, 2);
return newValue;
}
public Calendar newUpdate(String key, Calendar newValue) {
newCalendars.putIfAbsent(key, newValue);
newValue.add(Calendar.DAY_OF_MONTH, 2);
return newValue;
}
}
Expected: RV_RETURN_VALUE_OF_PUTIFABSENT_IGNORED reported for update() and newUpdate()
Actual: bug reported only for update()
Fixed, thanks. If FindBugs TypeAnalysis can determine that actual field/variable type is derived from ConcurrentMap, then the warning will be issued. I think ignoring putIfAbsent result for non-concurrent maps is ok.
https://code.google.com/p/findbugs/source/detail?r=31db7004aea4ac45898e3ec7bdf7d40ff93221b1