FasterXML / FasterXML/jackson-dataformats-binary
IonFactory leaks stream when parser/generator construction fails for File/Path
- Dominant language
- Java
- Stars
- 347
- Forks
- 156
- Avg merge
- 3d 3h
- Merged PRs (30d)
- 22
Description
`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`:
```java
// 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.com/claude-code)
https://claude.ai/code/session_01XrYRabZTvG9TjdXTCghvaM
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in IonFactory.java at createParser(File), createParser(Path), createGenerator(File, JsonEncoding), and createGenerator(Path, JsonEncoding), then compare the corresponding fixes in FasterXML/jackson-core#1692 and #1693. Ensure IOContext creation precedes opening the stream and failed construction closes it through DecorableTSFactory._closeOnFailedConstruction. Done means decorator, parser/generator, and context failures do not leak file descriptors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100