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.

However, when I use the i variable, no error pops up, which is completely correct. 
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 .

source share