I think we found a false positive:
private static void copy(File from, File to) throws FileNotFoundException, IOException {
FileChannel src = null;
FileChannel dst = null;
try {
src = new FileInputStream(from).getChannel();
dst = new FileOutputStream(to).getChannel();
dst.transferFrom(src, 0, src.size());
} finally {
if (src != null) {
Change this condition so that it does not always evaluate to "true"
or do I miss anything? another example:
if (lastUpdate == null|| lastUpdate != null && lastUpdate.before(new Date(System.currentTimeMillis() - 900000)))
You are actually asking question for two different cases :
You are hitting a known limitation https://jira.sonarsource.com/browse/SONARJAVA-1295 we plan to fix this (hard) one in the next release of java plugin.
This one is actually not a false positive at all ! :) if your variable lastUpdate is null then the condition is true without evaluating the right hand side of the || and if it is false, then lastUpdate != null will always evaluate to true so you can actually remove it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With