简体   繁体   English

Sonarqube 不会抱怨空布尔拆箱

[英]Sonarqube does not complain about null Boolean unboxing

My Sonar 6.7.1 LTS instance does not recognize the NullPointerException in the following code:我的 Sonar 6.7.1 LTS 实例无法识别以下代码中的 NullPointerException:

public static boolean getBooleanFromMap() {
    final Map<String, Boolean> map = new HashMap<>();
    map.put("a", false);
    return map.get("b"); // line 118
}

public static void main(final String[] args) {
    System.out.println(getBooleanFromMap());
}

In Method "getBooleanFromMap()", a null Boolean value is retrieved from a HashMap, and that null value is then unboxed and returned as a boolean (line 118 in my example).在方法“getBooleanFromMap()”中,从 HashMap 检索空布尔值,然后将该空值拆箱并作为布尔值返回(在我的示例中为第 118 行)。 The unboxing results in a NullPointerException, for example when the "main" method is run.拆箱会导致 NullPointerException,例如在运行“main”方法时。

Sonar (with the built-in Java analyzer 5.1 (build 13090)) does not complain about that.声纳(带有内置的 Java 分析器 5.1 (build 13090))并没有抱怨。 Why?为什么?

Also, when I do not have a HashMap but a more complex method with a "org.apache.sling.api.resource.ValueMap", where the "get" method is even annotated with @CheckForNull, Sonar is also not seeing anything.此外,当我没有 HashMap 但有一个更复杂的方法时,它带有“org.apache.sling.api.resource.ValueMap”,其中“get”方法甚至用@CheckForNull 注释,Sonar 也看不到任何东西。 Is there a way to make Sonar complain about that?有没有办法让声纳抱怨呢?

The detection of unboxing of null values is currently not supported.当前不支持检测空值的拆箱。

You can follow this ticket https://jira.sonarsource.com/browse/SONARJAVA-2126您可以关注此票https://jira.sonarsource.com/browse/SONARJAVA-2126

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM