Skip to content

[ISSUE #11461] Handle relative copy targets without a parent - #11464

Open
hickey-ai wants to merge 2 commits into
apache:developfrom
hickey-ai:codex/rocketmq-relative-copy-20261020
Open

hickey-ai wants to merge 2 commits into
apache:developfrom
hickey-ai:codex/rocketmq-relative-copy-20261020

Conversation

@hickey-ai

Copy link
Copy Markdown

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?

  • Exact-source regression: 4 tests, with the two relative-target cases failing with NPE before the fix and all 4 passing after.
  • Independent Java 8/Maven 3.6.3 run: mvn -B -pl common -am -Dtest=IOTinyUtilsTest,IOTinyUtilsRelativePathTest -Dsurefire.failIfNoSpecifiedTests=false -DfailIfNoTests=false test.
  • All 12 tests passed: 8 existing utility tests and 4 new regressions, with 0 failures/errors/skips; Checkstyle/SpotBugs passed.
  • Controls cover nested parent creation and keeping an existing target intact when the source is absent. Tests use unique filenames and cleanup.
  • Entire published Git tree equals the independently tested local tree.

No broker integration or whole-project test is claimed.

AI assistance: OpenAI Codex was used for investigation, implementation and tests; commits include tooling provenance.

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 RockteMQ-AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 RockteMQ-AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] IOTinyUtils.copyFile throws NullPointerException for a target file in the current directory

2 participants