Dodgy - Possible null pointer dereference due to return value of called method

findbugs : NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE

The return value from a method is dereferenced without a null check, and the return value of that method is one that should generally be checked for null (which requires to use Findbugs annotations to express the developer's intend). This may lead to a NullPointerException when the code is executed.

Noncompliant Code Example

public long getTime() {
  return getDate().getTime();      // NullPointerException may occur
}

@CheckForNull                      // See javax.annotation.CheckForNull (JSR-305)
public Date getDate() { /* ... */ }

Compliant Solution

public long getTime() {
  Date date = getDate();
  if (date == null) {
    throw new IllegalStateException("...");
  }
  return date.getTime();
}

@CheckForNull                      // See javax.annotation.CheckForNull (JSR-305)
public Date getDate() { /* ... */ }