lingochamp/FileDownloader · error · IllegalAccessException

receive (redirect) but the location is null with response […

Error message

receive %d (redirect) but the location is null with response [%s]

What it means

Thrown by RedirectHandler.process when an HTTP 3xx redirect response (e.g. 301/302/307/308) is received but the 'Location' response header is null or empty, so there is no URL to redirect to. The server sent a redirect status without a target, making the redirect chain impossible to follow, so the connection is rejected with IllegalAccessException.

Solutions

  1. Fix the server/CDN to always include a valid Location header on redirect responses.
  2. Use a non-redirecting final URL in the download request, or update the URL if the resource has permanently moved.
  3. Catch the exception at the download listener's error callback and retry with a fallback URL.
  4. Inspect the response headers via the message's response dump to identify the misbehaving server.
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at library/src/main/java/com/liulishuo/filedownloader/connection/RedirectHandler.java:64 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of lingochamp/FileDownloader@6237a8cac1 (2026-09-08). Data as JSON: /api/errors/dd5135ce72657a3d. Report an issue: GitHub.

Appendix: source

Thrown at library/src/main/java/com/liulishuo/filedownloader/connection/RedirectHandler.java:64

    private static final int HTTP_PERMANENT_REDIRECT = 308;


    public static FileDownloadConnection process(
            final Map<String, List<String>> requestHeaderFields,
            final FileDownloadConnection connection,
            List<String> redirectedUrlList)
            throws IOException, IllegalAccessException {

        int code = connection.getResponseCode();
        String location = connection.getResponseHeaderField("Location");

        List<String> redirectLocationList = new ArrayList<>();
        int redirectTimes = 0;
        FileDownloadConnection redirectConnection = connection;

        while (isRedirect(code)) {
            if (location == null) {
                throw new IllegalAccessException(FileDownloadUtils.
                        formatString(
                                "receive %d (redirect) but the location is null with response [%s]",
                                code, redirectConnection.getResponseHeaderFields()));
            }

            if (FileDownloadLog.NEED_LOG) {
                FileDownloadLog.d(RedirectHandler.class, "redirect to %s with %d, %s",
                        location, code, redirectLocationList);
            }

            redirectConnection.ending();
            redirectConnection =
                    buildRedirectConnection(requestHeaderFields, location);
            redirectLocationList.add(location);

            redirectConnection.execute();
            code = redirectConnection.getResponseCode();
            location = redirectConnection.getResponseHeaderField("Location");

View on GitHub (pinned to 6237a8cac1)