Skip to content

IonFactory leaks stream when parser/generator construction fails for File/Path #780

Description

@cowtowncoder

IonFactory extends DecorableTSFactory directly (it can use either textual or binary format), so it does not inherit the File/Path create methods from TextualTSFactory/BinaryTSFactory — and therefore not the leak fix from FasterXML/jackson-core#1693 either. Its own copies open the stream and hand it off with no try/catch:

// IonFactory.java:252
public JsonParser createParser(ObjectReadContext readCtxt, File f) {
    final InputStream in = _fileInputStream(f);
    IOContext ioCtxt = _createContext(_createContentReference(f), true);
    return _createParser(readCtxt, ioCtxt, _decorate(ioCtxt, in));
}

Anything that throws after the open — a user InputDecorator, or _createParser itself — leaks the file descriptor. Also note _fileInputStream(f) runs before _createContext(...), so a failure in _createContext leaks too; jackson-core opens the stream after.

Affects createParser(File) (:252), createParser(Path) (:260), and on the generator side createGenerator(File, JsonEncoding) (:358) and createGenerator(Path, JsonEncoding) (:366), which are the equivalent of FasterXML/jackson-core#1692.

Fix is the same shape as jackson-core: create the IOContext first, then open inside a try, and route RuntimeException through DecorableTSFactory._closeOnFailedConstruction(Closeable, RuntimeException) — protected as of jackson-core 3.1, so IonFactory can call it directly.

Every other backend (Smile, CBOR, Avro, Protobuf, XML, YAML, CSV) inherits the base-class methods and is already covered; Ion is the only one that opts out.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XrYRabZTvG9TjdXTCghvaM

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions