Eclipse Zero Analysis: An int expression requires raw conversion to match "@Nonnull Integer"

When configuring Eclipse 4.2.0 to perform null analysis (configured to use @javax.annotation.Nonnull , etc.) the following code will generate a warning

Null type security: int type expression no conversion required to match "@Nonnull Integer"

 class C { static void foo(int i) { bar(i); // Warning } static void bar(@javax.annotation.Nonnull Integer i) { } } 

How can I fix this (without using @SuppressWarnings("null") )? The analyzer does not seem to know that the boxed primitives cannot be null .

+6
source share
1 answer

I think this is a bug in Eclipse. I tried the same with IntelliJ and it works as expected.

When I pass Null, IntelliJ correctly tells me that nulls are not allowed.

enter image description here

However, when I use the i variable, no error pops up, which is completely correct. enter image description here

I even tried this, just for the experiment, so I'm not sure if you are stuck in Eclipse, otherwise I would recommend using either the free IntelliJ Community Version , or the Ultimate edition .

enter image description here

+3
source

Source: https://habr.com/ru/post/943732/


All Articles