java plugin 3.9 false positive - 总是验证为true(squid:S2583)

时间:2016-01-15 13:41:06

标签: sonarqube

以下代码导致误报:java 3.9中的“!标记始终为true”。我现在更新了示例代码。声纳说stilvallid总是假的。

public class Test {

public static void main(String[] args) {
    List<Entity> entities = new ArrayList<>();
    entities.add(new Entity());
    new Test().isMessageInThePast(entities);
}

public boolean isMessageInThePast(List<Entity> entities) {
    Boolean stillValid = false;
    Date now = new Date();
    for (Entity situation : entities) {
        List<Record> situationRecordList = situation.getRecords();
        for (Record situationRecord : situationRecordList) {
            if (situationRecord.getOverallEndTime().after(now)) {
                stillValid = true;
            }
        }
    }
    if (stillValid) {
        System.out.println("...");
    }
    return !stillValid;
}

static class Entity {
    List<Record> records = new ArrayList<>();

    Entity() {
        records.add(new Record());
    }

    public List<Record> getRecords() { return records; }
}

static class Record {
    Date endTime = new Date(new Date().getTime()+60000);
    public Date getOverallEndTime() { return endTime; }
}

1 个答案:

答案 0 :(得分:1)

这似乎是使用每个语句的嵌套计算流的问题。所以这确实是误报,应该在SonarQube UI中进行标记。

创建了故障单来处理​​此问题:https://jira.sonarsource.com/browse/SONARJAVA-1485