{"record":{"id":"dd5135ce72657a3d","repo":"lingochamp/FileDownloader","slug":"receive-d-redirect-but-the-location-is-null-wit","errorCode":null,"errorMessage":"receive %d (redirect) but the location is null with response [%s]","messagePattern":"receive (.+?) \\(redirect\\) but the location is null with response \\[(.+?)\\]","errorType":"exception","errorClass":"IllegalAccessException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/liulishuo/filedownloader/connection/RedirectHandler.java","lineNumber":64,"sourceCode":"    private static final int HTTP_PERMANENT_REDIRECT = 308;\n\n\n    public static FileDownloadConnection process(\n            final Map<String, List<String>> requestHeaderFields,\n            final FileDownloadConnection connection,\n            List<String> redirectedUrlList)\n            throws IOException, IllegalAccessException {\n\n        int code = connection.getResponseCode();\n        String location = connection.getResponseHeaderField(\"Location\");\n\n        List<String> redirectLocationList = new ArrayList<>();\n        int redirectTimes = 0;\n        FileDownloadConnection redirectConnection = connection;\n\n        while (isRedirect(code)) {\n            if (location == null) {\n                throw new IllegalAccessException(FileDownloadUtils.\n                        formatString(\n                                \"receive %d (redirect) but the location is null with response [%s]\",\n                                code, redirectConnection.getResponseHeaderFields()));\n            }\n\n            if (FileDownloadLog.NEED_LOG) {\n                FileDownloadLog.d(RedirectHandler.class, \"redirect to %s with %d, %s\",\n                        location, code, redirectLocationList);\n            }\n\n            redirectConnection.ending();\n            redirectConnection =\n                    buildRedirectConnection(requestHeaderFields, location);\n            redirectLocationList.add(location);\n\n            redirectConnection.execute();\n            code = redirectConnection.getResponseCode();\n            location = redirectConnection.getResponseHeaderField(\"Location\");","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/lingochamp/FileDownloader/blob/6237a8cac174bcc916e4342b14ab1ab72a5768d4/library/src/main/java/com/liulishuo/filedownloader/connection/RedirectHandler.java#L46-L82","documentation":"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.","triggerScenarios":"Thrown at library/src/main/java/com/liulishuo/filedownloader/connection/RedirectHandler.java:64 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix the server/CDN to always include a valid Location header on redirect responses.","Use a non-redirecting final URL in the download request, or update the URL if the resource has permanently moved.","Catch the exception at the download listener's error callback and retry with a fallback URL.","Inspect the response headers via the message's response dump to identify the misbehaving server."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"6237a8cac174bcc916e4342b14ab1ab72a5768d4","analyzedAt":"2026-09-08T23:50:48.168Z","contentChangedAt":"2026-09-08T23:50:48.168Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}