简体   繁体   English

声纳更改此条件,以使其始终不等于“ true”。 假阳性

[英]Sonar Change this condition so that it does not always evaluate to “true”. False positive

Our sonar is giving a Change this condition so that it does not always evaluate to "true" issue and I think it is a false positive 我们的声纳正在给“ Change this condition so that it does not always evaluate to "true"问题,我认为这是一个误报

    for (Path file: stream) {
        FileDetails fileDetails = getFileDetails(path.toString() + '/' + file.getFileName().toString(), file);
        if (fileDetails != null) {
            fileList.add(fileDetails);
        }
    }
    // Process the list of non null files
    ...

The get file details method as defined later in class 稍后在类中定义的获取文件详细信息方法

private FileDetails getFileDetails(String absolutePathName, Path path) {
    FileDetails fileDetails = new FileDetails();
    fileDetails.setName(path.getFileName().toString());
    fileDetails.setAbsoluteName(absolutePathName);
    fileDetails.setDirectory(path.toFile().isDirectory());
    fileDetails.setFileStoreUri(fileStoreDetails.getUri());
    try {
        fileDetails.setSize(Files.size(path));
        fileDetails.setModifiedDate(new Date(Files.getLastModifiedTime(path).toMillis()));
    } catch (java.nio.file.AccessDeniedException e) {
        logger.info("Cannot get file details for " + path, e);
        fileDetails = null;
    } catch (IOException e) {
        // No need to throw a checked exception as we can't do anything with it.
        logger.error("Cannot get file details for " + path, e);
        throw new UncheckedIOException(e);
    }
    return fileDetails;
}

From my reading, fileDetails will most likely be non-null, but in a certain scenario it will be null, hence the check. 根据我的阅读,fileDetails很可能为非null,但在某些情况下它将为null,因此进行检查。 Is there a trick here that I'm missing? 这里有我想念的把戏吗?

We're using SonarQube 6.2, with the v4.4.0.8066 of the java plugin 我们正在使用SonarQube 6.2,以及Java插件的v4.4.0.8066

So, java.nio.file.AccessDeniedException is a sub class of IOException and isn't directly thrown. 因此, java.nio.file.AccessDeniedExceptionIOException的子类,不会直接抛出。 After review of the function, we decided that returning null for access denied is the wrong thing to do. 在检查了功能之后,我们认为为拒绝访问返回null是错误的做法。 So we removed this catch (leaving the IOException catch in place). 因此,我们删除了此捕获(将IOException捕获留在原处)。 This meant the method now can't return null. 这意味着该方法现在不能返回null。 Which made the if redundant as Sonar tells us 如Sonar所告诉我们的

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 声纳假阳性,“改变条件,使其不总是评估为真。” - Sonar false positive, “change condition so that it does not always evaluate to true.” SONAR抱怨改变条件,因此它并不总是评估为“假” - SONAR complaining to change the condition so that it does not always evaluate to “false” 处理空条件(在声纳中,请更改此条件,以使其始终不等于“ false”) - Handle null condition (In sonar Change this condition so that it does not always evaluate to “false”) 更改此条件,以使其始终不等于“ false” - Change this condition so that it does not always evaluate to “false” 如何避免“更改此条件,使其不总是评估为“假”” - How to avoid "Change this condition so that it does not always evaluate to "false"" “更改此条件,以便它不总是评估为假”-SonarQube - “Change this condition so that it does not always evaluate to false” - SonarQube SonarQube:更改此条件,使其不总是评估为真 - SonarQube: Change this condition so that it does not always evaluate to true Sonal lint :更改此条件,使其不总是评估为真 - Sonal lint : change this condition so that it does not always evaluate to true SonarQube:更改此条件,使其不会始终评估为“false”(最后在javax.mail接收中) - SonarQube: Change this condition so that it does not always evaluate to “false” (for finally in javax.mail receiving) squid:S2583:更改此条件,以便它并不总是评估为“ true” - squid:S2583 : Change this condition so that it does not always evaluate to “true”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM