android-async-http/android-async-http · error · IllegalArgumentException

HTTP response may not be null

Error message

HTTP response may not be null

What it means

A null-guard inside MyRedirectHandler.isRedirectRequested, copied from DefaultRedirectHandler's contract. The redirect handler is invoked with the current HttpResponse; a null response means the redirect policy is being consulted outside a valid response context (internal client misuse). Note it is only reachable when enableRedirects is true.

Solutions

  1. Ensure the redirect handler is only used with a properly configured HttpClient that always passes a real HttpResponse
  2. Do not call isRedirectRequested manually; let the client's redirect strategy invoke it
  3. Wrap request execution so failures surface as client errors rather than reaching the redirect stage with no response
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at library/src/main/java/com/loopj/android/http/MyRedirectHandler.java:63 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of android-async-http/android-async-http@018a0b8d96 (2026-09-09). Data as JSON: /api/errors/76ce43c3b0ef426d. Report an issue: GitHub.

Appendix: source

Thrown at library/src/main/java/com/loopj/android/http/MyRedirectHandler.java:63

class MyRedirectHandler extends DefaultRedirectHandler {

    private static final String REDIRECT_LOCATIONS = "http.protocol.redirect-locations";
    private final boolean enableRedirects;

    public MyRedirectHandler(final boolean allowRedirects) {
        super();
        this.enableRedirects = allowRedirects;
    }

    @Override
    public boolean isRedirectRequested(
            final HttpResponse response,
            final HttpContext context) {
        if (!enableRedirects) {
            return false;
        }
        if (response == null) {
            throw new IllegalArgumentException("HTTP response may not be null");
        }
        int statusCode = response.getStatusLine().getStatusCode();
        switch (statusCode) {
            case HttpStatus.SC_MOVED_TEMPORARILY:
            case HttpStatus.SC_MOVED_PERMANENTLY:
            case HttpStatus.SC_SEE_OTHER:
            case HttpStatus.SC_TEMPORARY_REDIRECT:
                return true;
            default:
                return false;
        } //end of switch
    }

    @Override
    public URI getLocationURI(
            final HttpResponse response,
            final HttpContext context) throws ProtocolException {
        if (response == null) {

View on GitHub (pinned to 018a0b8d96)