问题
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)))
回答1:
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
lastUpdateis null then the condition is true without evaluating the right hand side of the||and if it is false, thenlastUpdate != nullwill always evaluate to true so you can actually remove it.
来源:https://stackoverflow.com/questions/34063605/java-plugin-3-8-s2583-false-positive