Repository navigation
Conversation
Only create a target parent directory when one exists. Keep the copy, overwrite and resource handling paths unchanged. Generated-by: OpenAI Codex
Exercise bare target names, nested directory creation and preserving an existing target when the source is absent. Generated-by: OpenAI Codex
RockteMQ-AI
left a comment
There was a problem hiding this comment.
LGTM. The fix correctly handles relative file paths without a parent directory.
Summary
Fixed NPE in IOTinyUtils.copyFile() when the target file path has no parent directory (e.g., relative path like file.txt).
Analysis
File.getParentFile() returns null when the file has no parent path component. The original code called .mkdirs() directly on the result, causing NPE. The fix adds a null check before calling mkdirs(), which is the correct defensive approach.
The test suite covers relative paths, overwrite scenarios, nested directory creation, and missing source handling — all edge cases are well-covered.
Automated review by github-manager-bot
RockteMQ-AI
left a comment
There was a problem hiding this comment.
LGTM. Correct fix — File.getParentFile() returns null for bare relative filenames, causing NPE at mkdirs(). The null guard preserves nested directory creation for absolute/relative paths with parents while allowing copy to the current directory. The 4 regression tests cover relative copy, overwrite, nested creation, and missing-source safety, with the two relative-target cases failing before the fix.
Automated review by github-manager-bot
Which Issue(s) This PR Fixes
Fixes #11461
Brief Description
A bare relative target filename has no parent File. Guard that optional parent before mkdirs(), so copying to a new or existing file in the current directory works. Keep nested directory creation and the existing copy/overwrite behavior.
This deliberately does not include the resource-closure work in #10210.
How Did You Test This Change?
mvn -B -pl common -am -Dtest=IOTinyUtilsTest,IOTinyUtilsRelativePathTest -Dsurefire.failIfNoSpecifiedTests=false -DfailIfNoTests=false test.No broker integration or whole-project test is claimed.
AI assistance: OpenAI Codex was used for investigation, implementation and tests; commits include tooling provenance.