问题描述
我认为我们发现了一个误报:
private static void copy(File from, File to) throws FileNotFoundException, IOException {文件通道 src = null;文件通道 dst = null;尝试 {src = new FileInputStream(from).getChannel();dst = new FileOutputStream(to).getChannel();dst.transferFrom(src, 0, src.size());} 最后 {if (src != null) {
更改此条件,使其不会总是评估为真"
还是我错过了什么?另一个例子:
if (lastUpdate == null|| lastUpdate != null && lastUpdate.before(new Date(System.currentTimeMillis() - 900000)))
您实际上是在针对两种不同的情况提出问题:
您遇到了已知限制 https://jira.sonarsource.com/browse/SONARJAVA-1295 我们计划在下一版本的 java 插件中修复这个(硬)问题.
这个其实根本不是误报!:) 如果您的变量
lastUpdate
为空,则条件为真,无需评估||
的右侧,如果为假,则lastUpdate !=null
将始终评估为 true,因此您可以实际删除它.
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) {
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, thenlastUpdate != null
will always evaluate to true so you can actually remove it.
这篇关于java 插件 3.8 - S2583 误报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!