Repository navigation
Description
Summary
The emlToEmailBuilder(File, ...) overload creates a FileInputStream and delegates to the InputStream overload. The delegated path intentionally does not close caller-owned streams, but the File overload owns the stream it created and does not close it after synchronous consumption. Repeated conversion can therefore retain file descriptors and can leave files locked on platforms such as Windows.
Code path
modules/simple-java-mail/src/main/java/org/simplejavamail/converter/EmailConverter.java:477-483: creates theFileInputStream.EmailConverter.java:513-520: delegates to theInputStreampath without closing the internally-created stream.modules/core-module/src/main/java/org/simplejavamail/internal/util/MiscUtil.java:114-124: consumes the stream without taking ownership of caller-provided streams.
Steps to reproduce
The ownership boundary can be observed by repeatedly calling the File overload on the same temporary EML file. The checked call chain has no try-with-resources or close operation after the FileInputStream is created. A descriptor-count probe against the current 9.1.3 bytecode showed the internal File path increasing open descriptors when garbage collection was prevented from masking the leak.
Expected behavior
The File overload should close the stream that it creates after the conversion completes, including when conversion throws. The InputStream overload should continue to leave caller-owned streams open.
Actual behavior
The File overload transfers the internally-created stream into a non-closing path and returns without a deterministic close.
Existing coverage
Issue #354 establishes the caller-owned InputStream contract. It does not add a close for this File overload. No exact fix was found. This report is intentionally limited to the library-created stream and does not ask the helper to close caller-owned streams.
Suggested fix
Use try-with-resources around the FileInputStream in the File overload and preserve the non-closing contract of the InputStream overload.
Suggested tests
- File overload closes a tracking stream on normal return.
- File overload closes it on conversion failure.
- InputStream overload does not close a caller-owned tracking stream.
- Repeated conversion does not retain descriptors or file locks.
Submitted with Codex.
Activity
fix(converter): close internally owned EML file streams (#669, #670)
bbottema commentedon Aug 5, 2026
Fixed on
develop:emlToEmailBuilder(File, ...)now closes the stream it creates after synchronous conversion, while caller-providedInputStreamownership remains unchanged. Targeted for 9.1.4.bbottema commentedon Aug 5, 2026
Released in Simple Java Mail 9.1.4 and available from Maven Central.