{"record":{"id":"fe31648abb94b7c5","repo":"arduino/Arduino","slug":"too-many-redirect-requesturl","errorCode":null,"errorMessage":"Too many redirect {requestURL}","messagePattern":"Too many redirect (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"arduino-core/src/cc/arduino/utils/network/HttpConnectionManager.java","lineNumber":109,"sourceCode":"\n  }\n\n  public HttpURLConnection makeConnection(Consumer<HttpURLConnection> beforeConnection)\n    throws IOException, NoSuchMethodException, ScriptException, URISyntaxException {\n    return makeConnection(this.requestURL, 0, beforeConnection);\n  }\n\n\n  public HttpURLConnection makeConnection()\n    throws IOException, NoSuchMethodException, ScriptException, URISyntaxException {\n    return makeConnection(this.requestURL, 0, (c) -> {\n    });\n  }\n\n  private HttpURLConnection makeConnection(URL requestURL, int movedTimes,\n                                           Consumer<HttpURLConnection> beforeConnection) throws IOException, URISyntaxException, ScriptException, NoSuchMethodException {\n    if (movedTimes > maxRedirectNumber) {\n      throw new IOException(\"Too many redirect \" + requestURL);\n    }\n\n    Proxy proxy = new CustomProxySelector(PreferencesData.getMap()).getProxyFor(requestURL.toURI());\n\n    final String requestId = UUID.randomUUID().toString().toUpperCase().replace(\"-\", \"\").substring(0, 16);\n    HttpURLConnection connection = (HttpURLConnection) requestURL.openConnection(proxy);\n\n    // see https://github.com/arduino/Arduino/issues/10264\n    // Workaround for https://bugs.openjdk.java.net/browse/JDK-8163921\n    connection.setRequestProperty(\"Accept\", \"*/*\");\n\n    connection.setRequestProperty(\"User-agent\", userAgent);\n    connection.setRequestProperty(\"X-Request-ID\", requestId);\n    if (id != null) {\n      connection.setRequestProperty(\"X-ID\", id);\n    }\n    if (requestURL.getUserInfo() != null) {\n      String auth = \"Basic \" + new String(","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/arduino/Arduino/blob/a0df6e0e83b652c72bc78b0a1376c54d6ebc3bee/arduino-core/src/cc/arduino/utils/network/HttpConnectionManager.java#L91-L127","documentation":"Thrown by the private recursive makeConnection when a URL request exceeds the allowed redirect-following limit (movedTimes). HttpConnectionManager follows HTTP 3xx Location redirects up to a fixed cap; if the server keeps responding with redirects past that cap (redirect loop, auth bounce, etc.), this fires with the original requestURL. It means the target URL never yielded a direct response — fix the URL or the server's redirect behavior.","triggerScenarios":"makeConnection() recursively follows 3xx Location headers; movedTimes exceeds maxRedirectNumber for requestURL, commonly a redirect loop or a redirect chain longer than the configured limit.","commonSituations":"Server redirect loop (http->https misconfig, login loops); a redirect chain of 5+ hops; a misbehaving proxy rewriting Location headers; URL pointing to a captive portal.","solutions":["Verify the final URL resolves correctly (curl -IL <url>) and fix server-side redirect loops","Remove one hop by using the final destination URL directly","Increase maxRedirectNumber if the chain is legitimately long","Bypass or fix the proxy that is injecting redirects"],"exampleFix":"// before\nHttpURLConnection c = new HttpConnectionManager(url).makeConnection(consumer);\n// after: use the resolved final URL\nHttpURLConnection head = (HttpURLConnection) url.openConnection();\nhead.setInstanceFollowRedirects(false);\nString loc = head.getHeaderField(\"Location\");\nURL finalUrl = (loc != null) ? new URL(loc) : url;\nHttpURLConnection c = new HttpConnectionManager(finalUrl).makeConnection(consumer);","handlingStrategy":"try-catch","validationCode":"HttpURLConnection c = (HttpURLConnection) url.openConnection();\nc.setInstanceFollowRedirects(false);\nif (c.getResponseCode() >= 300 && c.getResponseCode() < 400) {\n  String loc = c.getHeaderField(\"Location\");\n  if (loc != null && new URL(loc).equals(url)) throw new IllegalStateException(\"Redirect loop\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  connection = new HttpConnectionManager(url).makeConnection(before);\n} catch (IOException e) {\n  if (e.getMessage().startsWith(\"Too many redirect\")) {\n    throw new IllegalStateException(\"Resolve redirect loop for \" + url, e);\n  } else throw e;\n}","preventionTips":["Point directly at final (non-redirecting) URLs","Fix http->https redirect loops on servers you control","Keep redirect chains short; test with curl -IL","Avoid captive-portal or auth-loop URLs for automated downloads"],"tags":["network","http","redirect","loop"],"backgroundTag":"too-many-redirects","analyzedSha":"a0df6e0e83b652c72bc78b0a1376c54d6ebc3bee","analyzedAt":"2026-09-06T10:13:38.901Z","contentChangedAt":"2026-09-06T10:13:38.901Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}