lysine-dev/retrofit · error · NullPointerException
response == null
Error message
response == null
What it means
Result.response(Response) is the public factory for building a success-valued Result, used by the rxjava adapter to wrap a completed HTTP response inside a reactive stream as data. It rejects null because a Result must carry a definite response or a definite error — a null response would make the Result empty and break the response()/error() accessor invariants. It throws NullPointerException ('response == null') behind a ConstantConditions suppression.
Source
Thrown at retrofit-adapters/rxjava/src/main/java/retrofit2/adapter/rxjava/Result.java:32
* limitations under the License.
*/
package retrofit2.adapter.rxjava;
import java.io.IOException;
import javax.annotation.Nullable;
import retrofit2.Response;
/** The result of executing an HTTP request. */
public final class Result<T> {
@SuppressWarnings("ConstantConditions") // Guarding public API nullability.
public static <T> Result<T> error(Throwable error) {
if (error == null) throw new NullPointerException("error == null");
return new Result<>(null, error);
}
@SuppressWarnings("ConstantConditions") // Guarding public API nullability.
public static <T> Result<T> response(Response<T> response) {
if (response == null) throw new NullPointerException("response == null");
return new Result<>(response, null);
}
private final @Nullable Response<T> response;
private final @Nullable Throwable error;
private Result(@Nullable Response<T> response, @Nullable Throwable error) {
this.response = response;
this.error = error;
}
/**
* The response received from executing an HTTP request. Only present when {@link #isError()} is
* false, null otherwise.
*/
public @Nullable Response<T> response() {
return response;
}View on GitHub (pinned to d0b112dad0)
Solutions
- Null-check the argument first: `if (resp != null) Result.response(resp) else ...`.
- If the call should represent a failure, use Result.error(...) instead.
- Fix the upstream source so it never hands a null Response to the wrapper.
Example fix
// before
Result<User> r = Result.response(cachedResponse);
// after
if (cachedResponse == null) {
return Result.error(new IllegalStateException("no cached response"));
}
Result<User> r = Result.response(cachedResponse); Defensive patterns
Strategy: validation
Validate before calling
Response<User> resp = executeOrCache();
if (resp == null) throw new IllegalStateException("no response available");
Result<User> result = Result.response(resp); Try / catch
try {
Result<User> r = Result.response(resp);
} catch (NullPointerException e) {
// resp was null; treat as an error Result instead
return Result.error(new IllegalStateException("null response", e));
} Prevention
- Use Objects.requireNonNull(resp, "response") before Result.response.
- Never cache null as a sentinel for 'no value'; use Optional or an explicit error Result.
- In tests, always pass a real retrofit2.Response instance.
When it happens
Trigger: Calling Result.response(null) — typically in custom operators/transformers or tests that re-wrap a Response reference that resolved to null, or when mapping an empty cache hit. Thrown immediately at the top of Result.response(Response).
Common situations: Writing custom RxJava operators that wrap Response values; mock/test setup; cache layers returning null on miss that are then wrapped unconditionally.
Related errors
- error == null
- response == null
- response == null
- scheduler == null
- Response must be parameterized as Response<Foo> or Response<
AI-assisted analysis of lysine-dev/retrofit@d0b112dad0 (2026-08-13).
Data as JSON: /api/errors/7a9213a9a6f9d629.
Report an issue: GitHub.