Instead of the usual if (myString == null || myString.equals("")) I prefer to use the org.apache.commons.lang.StringUtils class and do if (StringUtils.isEmpty(myString)) .
However, this, at least the way I do it, has a gigantic flaw: because FindBugs is either a compiler warning mechanism, f. ex. from Eclipse - will no longer see an explicit check for a null value, it will no longer consider myString be potentially null, so it will no longer trigger warnings about potential (or true) null pointers on it, and these warnings are extremely useful in my opinion.
Example (ADDED):
import org.apache.commons.lang.StringUtils; public class TestWarning { void testWarning(String myString) {
So I'm just trying to make sure that there is no way to eliminate or minimize this drawback so that you can use StringUtils.isEmpty and still get null pointer warnings. Maybe some kind of annotation, for example @Nullcheck , should be added to the isEmpty method or something else?
ADDED: for example, it would be possible to create a custom annotation, for example @Nullcheck , add it to arg isEmpty as public static boolean isEmpty(@Nullcheck String str) to indicate that the method performs a null check of this argument, and make the warning mechanism the compiler or FindBugs treated if (StringUtils.isEmpty(myString)) in the same way as explicit null checking?
source share