Consider using @Nullable
and @NonNull
annotations in your code. Partially it can solve your problem.
UPDATE: An example of use copied from http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftask-using_null_annotations.htm
@NonNull String getString(String maybeString) {
if (maybeString != null)
return maybeString; // the above null check is required
else
return "<n/a>";
}
void caller(String s) {
System.out.println(getString(s).toUpperCase()); // no null check required
}
UPDATE: case with @Nullable
public @Nullable String getMessage() {
return System.currentTimeMillis() % 2 != 0
? "That's odd..."
: null;
}
public void showCase() {
String msg = getMessage();
if (msg.isEmpty()) { //- Here it yields about possible null access
//...
}
}
UPDATE: Settings for Null Analysis in my environment:
Actual error message from Eclipse:
UPDATE: You need to include JAR with Eclipse annotation in build path. Move your mouse pointer over @NonNull
or @Nullable
annotation that can not be compiled (as shown on the image) and choose Copy library with default null annotations to build path —
New JAR should appear in Package Explorer and compiler should be able to see it. Then move your cursor to the annotation and press Ctrl+Space — Eclipse should find correct import (note, that you might see two different packages on the list — choose the one from JDT) — and select it. It should work.