Eclipse null分析:int类型的表达式需要未经检查的转换以符合'@Nonnull Integer'

时间:2013-04-26 17:23:43

标签: java eclipse null static-analysis non-nullable

配置Eclipse 4.2.0以执行空分析(配置为使用@javax.annotation.Nonnull等)时,以下代码将生成警告

  

空类型安全性:int类型的表达式需要取消选中   转换为符合'@Nonnull Integer'

class C
{
  static void foo(int i)
  {
    bar(i); // Warning
  }

  static void bar(@javax.annotation.Nonnull Integer i)
  {
  }
}

我该如何解决这个问题(不使用@SuppressWarnings("null"))?似乎分析器不知道盒装基元不能是null

1 个答案:

答案 0 :(得分:3)

我认为它是Eclipse中的一个错误。我尝试使用IntelliJ进行相同操作,并且在那里工作正常。

当我传递Null时,IntelliJ正确地告诉我不允许空值。

enter image description here

然而,当我使用普通的i变量时,没有错误弹出,这是非常正确的。 enter image description here

我甚至尝试了这个,仅仅是为了实验,所以我不确定你是否坚持使用Eclipse,否则我建议使用免费的Community version IntelliJ,或Ultimate edition

enter image description here