Repository navigation
fix: YamlSource leaking file handles and leaving truncated files on crash - #209
Open
DragonL0508 wants to merge 1 commit into
Open
DragonL0508 wants to merge 1 commit into
DragonL0508 wants to merge 1 commit into
Conversation
…rash Reading: readConfig used Files.lines without closing the stream, so every load kept the file open until the stream was garbage collected. On Windows an open file cannot be replaced or deleted, so anything that moves a file over a config right after loading it (backups, atomic replaces, the change below) fails with AccessDeniedException. Writing: saveConfiguration wrote the file in place with Files.write. A crash or kill during a save leaves a truncated file; if the cut happens at the end of a line the YAML still parses, the missing fields fall back to their defaults on the next load, and loadAndSave writes those defaults back, silently losing data. The dump is now written to a temporary file next to the config and moved over it (atomically when the file system supports it). The dump was also encoded with the platform default charset while Files.lines reads UTF-8, which breaks non-ASCII values on Java < 18 with a non-UTF-8 default charset (e.g. Windows). It is now always UTF-8. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
readConfigusedFiles.lineswithout closing the stream, so every load kept the file open until GC. On Windows an open file can't be replaced or deleted, so anything that moves a file over a config right after loading it fails withAccessDeniedException.saveConfigurationoverwrote the file in place withFiles.write. A crash or kill mid-save leaves a truncated file; if the cut lands at the end of a line the YAML still parses, the missing fields fall back to their defaults on the next load andloadAndSavewrites those defaults back, silently losing data. The dump is now written to a temporary file next to the config and moved over it (atomically when the file system supports it). The temporary file is created withFiles.writerather thanFiles.createTempFile, so the config keeps its usual permissions.Files.linesreads UTF-8, which breaks non-ASCII values on Java < 18 with a non-UTF-8 default (e.g. Windows). It is now always UTF-8.Tests:
YamlSourceFileTestcovers a UTF-8 round trip, replacing an existing file without leaving temporary files behind, and creating missing parent directories.🤖 Generated with Claude Code