{"record":{"id":"210cd02f158e14f5","repo":"OpenFeign/feign","slug":"error-occurred-during-encoding-of-the-uri","errorCode":null,"errorMessage":"Error occurred during encoding of the uri: ","messagePattern":"Error occurred during encoding of the uri: ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/feign/template/UriUtils.java","lineNumber":168,"sourceCode":"  private static String encodeChunk(String value, Charset charset, boolean allowReserved) {\n    if (isEncoded(value, charset)) {\n      return value;\n    }\n\n    byte[] data = value.getBytes(charset);\n    try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {\n      for (byte b : data) {\n        if (isUnreserved((char) b)) {\n          bos.write(b);\n        } else if (isReserved((char) b) && allowReserved) {\n          bos.write(b);\n        } else {\n          pctEncode(b, bos);\n        }\n      }\n      return new String(bos.toByteArray(), charset);\n    } catch (IOException ioe) {\n      throw new IllegalStateException(\n          \"Error occurred during encoding of the uri: \" + ioe.getMessage(), ioe);\n    }\n  }\n\n  /**\n   * Percent Encode the provided byte.\n   *\n   * @param data to encode\n   * @param bos with the output stream to use.\n   */\n  private static void pctEncode(byte data, ByteArrayOutputStream bos) {\n    bos.write('%');\n    char hex1 = Character.toUpperCase(Character.forDigit((data >> 4) & 0xF, 16));\n    char hex2 = Character.toUpperCase(Character.forDigit(data & 0xF, 16));\n    bos.write(hex1);\n    bos.write(hex2);\n  }\n","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/OpenFeign/feign/blob/e2a1e27560a1e68840c34f031afca88b36096e30/core/src/main/java/feign/template/UriUtils.java#L150-L186","documentation":"UriUtils wraps any IOException thrown while percent-encoding a URI chunk into an IllegalStateException. Encoding writes to an in-memory ByteArrayOutputStream, so an IOException here is unexpected and signals an internal encoding failure rather than bad user input.","triggerScenarios":"IOException thrown inside the encodeInternal loop (e.g. during charset operations or the internal byte stream) while calling UriUtils.encode/encodeChunk.","commonSituations":"Extremely rare in practice since ByteArrayOutputStream rarely throws; can surface from charset encoder issues or wrapped streams in modified/custom builds.","solutions":["Inspect the wrapped IOException (getCause) for the root cause","Verify the template/URI input and charset are valid","Upgrade Feign; if reproducible, file an issue with the input URI and charset"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  encoded = UriUtils.encode(value, charset);\n} catch (IllegalStateException e) {\n  logger.error(\"URI encoding failed: {}\", e.getCause());\n}","preventionTips":["Use standard charsets (UTF-8)","Keep Feign up to date; report reproducible cases upstream"],"tags":["uri-encoding","illegal-state","io"],"backgroundTag":"internal-invariant-violation","analyzedSha":"e2a1e27560a1e68840c34f031afca88b36096e30","analyzedAt":"2026-09-10T12:37:37.238Z","contentChangedAt":"2026-09-10T12:37:37.238Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}