java plugin 3.8 - S2583 false positive

一笑奈何 提交于 2020-01-02 07:05:10

问题


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 :

  1. 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.

  2. 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.



来源:https://stackoverflow.com/questions/34063605/java-plugin-3-8-s2583-false-positive

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!