1

I am using @NotNull annotation, as you can see I am using:

StringUtils.isNotBlank()

to check NP, but I have still Eclipse warning there. If I use

oldlink != null

it wont show warning.

Does anyone know what can be problem when using apache commons StringUtils ?

NPE warning

To Kra
  • 3,344
  • 3
  • 38
  • 45
  • There is no problem. When you use the ``!=null`` comparison, the compiler sees that you check for null. When you use a call to some method such as ``isNotBlank()``, the compiler has no idea that this method checks for null as well. That's why you still receive the warning. But that is a compiler warning and you can just ignore it. – f1sh Jul 13 '16 at 09:40
  • 1
    I have similar problem with Apache `CollectionUtils.isNotEmpty()` in IntelliJ IDEA 13. It shown potential NPE even though this method checks for it. And I think later version of IDEA don't do that and actually consider what's going on inside apache method. – dty Jul 13 '16 at 09:41
  • @f1sh I know but they could improve this thing, as isNotBlank() method has a null check, so they could introduce some exceptions when using `apache commons` – To Kra Jul 13 '16 at 10:38
  • @ToKra that's not an easy thing to do. That would require the compiler to look up that code. In this case, it's a static method an can be done. With non-static methods it's impossible for the compiler to do that reiliably. – f1sh Jul 13 '16 at 11:38
  • @f1sh I did not mean to look into method, Eclipse team knows Apache Commons libs, so they could make some exceptions into framework, which would not require any compiler involving... just quessing. – To Kra Jul 13 '16 at 18:55

1 Answers1

0

Looks like only this help, null check and the use of StringUtils.isNotEmpty(), even StringUtils.isNotBlank() does the same:

enter image description here

To Kra
  • 3,344
  • 3
  • 38
  • 45