{"record":{"id":"9277ccdead0b4312","repo":"OpenFeign/feign","slug":"writing-file-s-s-content-error","errorCode":null,"errorMessage":"Writing file's '%s' content error","messagePattern":"Writing file's '(.+?)' content error","errorType":"exception","errorClass":"EncodeException","httpStatus":null,"severity":"error","filePath":"form/src/main/java/feign/form/multipart/SingleFileWriter.java","lineNumber":51,"sourceCode":"  public boolean isApplicable(Object value) {\n    return value instanceof File;\n  }\n\n  @Override\n  protected void write(Output output, String key, Object value) throws EncodeException {\n    val file = (File) value;\n    writeFileMetadata(output, key, file.getName(), null);\n\n    try (InputStream input = new FileInputStream(file)) {\n      val buf = new byte[4096];\n      int length = input.read(buf);\n      while (length > 0) {\n        output.write(buf, 0, length);\n        length = input.read(buf);\n      }\n    } catch (IOException ex) {\n      val message = String.format(\"Writing file's '%s' content error\", file.getName());\n      throw new EncodeException(message, ex);\n    }\n  }\n}\n","sourceCodeStart":33,"sourceCodeEnd":55,"githubUrl":"https://github.com/OpenFeign/feign/blob/e2a1e27560a1e68840c34f031afca88b36096e30/form/src/main/java/feign/form/multipart/SingleFileWriter.java#L33-L55","documentation":"In SingleFileWriter.write (feign-form), the multipart writer fails while streaming the content of a java.io.File into the form output. The file was opened with FileInputStream but an IOException occurred during reading or writing (typical causes: file deleted or unreadable after metadata was written, disk/pipe I/O failure). The exception is rethrown as an EncodeException carrying the file name, so multipart encoding of the request aborts.","triggerScenarios":"write() called while encoding a single-file multipart part and the InputStream read fails (file missing, unreadable, closed) or the output stream write fails mid-copy.","commonSituations":"Encoding a java.io.File that was deleted or moved after the request was built; permission issues on the file; network-backed streams that fail mid-read.","solutions":["Verify the file exists and is readable before adding it to the multipart request","Check disk space and output stream health if the read itself is failing","Log/inspect the wrapped IOException cause for the root filesystem error","Copy the file to a stable temporary location before encoding if it may change mid-write"],"exampleFix":"// before\nclient.upload(new File(\"/tmp/report.pdf\"));\n// after\nFile f = new File(\"/tmp/report.pdf\");\nif (!f.isFile() || !f.canRead()) throw new IllegalStateException(\"unreadable file: \" + f);\nclient.upload(f);","handlingStrategy":"validation","validationCode":"static void requireReadable(File f) {\n  if (f == null || !f.isFile() || !f.canRead())\n    throw new IllegalArgumentException(\"file missing or unreadable: \" + f);\n}","typeGuard":null,"tryCatchPattern":"try {\n  client.upload(file);\n} catch (EncodeException e) {\n  if (e.getMessage().contains(\"content error\")) {\n    throw new UncheckedIOException((IOException) e.getCause());\n  }\n  throw e;\n}","preventionTips":["Validate file existence/readability just before encoding","Avoid encoding files on volatile storage or that another process may replace","Prefer in-memory byte[] or a stable InputStream for uploads"],"tags":["feign","multipart","file-io","encoder"],"backgroundTag":"file-read-failed","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"}