You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] IOTinyUtils.copyFile throws NullPointerException for a target file in the current directory #11461
OpenJDK 1.8.0_302 (GraalVM CE 21.2.0), Maven 3.6.3.
Describe the Bug
copyFile(source, "copy.bin") constructs a File for the target and unconditionally calls tf.getParentFile().mkdirs(). A bare relative filename has no parent File, so copying fails with NullPointerException before any bytes are copied. Both new and existing target files are affected.
Steps to Reproduce
Create an ordinary source file with known bytes.
Call IOTinyUtils.copyFile(source.toString(), "copy-unique-name.bin") with a filename that has no directory component.
Repeat with an already existing bare target filename.
Remove the unique test target in finally.
Both calls fail at the getParentFile().mkdirs() line; an absolute or nested target is the control case.
What Did You Expect to See?
A bare filename is a valid target in the current working directory. New files should be copied, existing files overwritten with the source bytes, and nested target directories should still be created when present.
What Did You See Instead?
NullPointerException at IOTinyUtils.copyFile line 84, before the copy starts.
Additional Context
The minimal correction only guards the optional parent directory. Four new regression methods cover new/overwritten relative targets, nested directory creation, and preserving an existing target when the source is missing. Two bare-target cases fail before the correction; all four pass after. The independent native common run executes the 8 existing IOTinyUtilsTest tests plus the 4 new tests: 12 passed, 0 failures/errors/skips, with Checkstyle/SpotBugs passing.
#10208 and PR #10210 concern resource closure in the same method, but their diff does not change the null-parent call. PR #10733 does not modify IOTinyUtils. No matching discussion or relative-target fix was found in the reviewed results.
AI assistance: OpenAI Codex was used for investigation, implementation and tests.
The reported issue has been verified against the current codebase on the develop branch.
Root Cause: In IOTinyUtils.copyFile() (line 84), tf.getParentFile().mkdirs() is called unconditionally. When the target is a bare filename (e.g. "copy.bin"), getParentFile() returns null, causing NullPointerException before any bytes are copied.
Impact:common module — any caller using a relative bare filename as the copy target will crash. Absolute paths or nested relative paths are unaffected.
Severity: Medium — utility method, affects any code path that copies files to the current directory.
Verified reproduction:
IOTinyUtils.copyFile("source.txt", "copy.bin") → NPE at line 84
Control case: IOTinyUtils.copyFile("source.txt", "dir/copy.bin") works correctly
A null-guard on getParentFile() resolves this. An automated fix proposal may be generated. Reply /approve to proceed with PR generation.
Activity
RockteMQ-AI commentedon Oct 20, 2026
Issue Evaluation
Category:
type/bug| Status: ConfirmedThe reported issue has been verified against the current codebase on the
developbranch.Root Cause: In
IOTinyUtils.copyFile()(line 84),tf.getParentFile().mkdirs()is called unconditionally. When the target is a bare filename (e.g."copy.bin"),getParentFile()returnsnull, causingNullPointerExceptionbefore any bytes are copied.Impact:
commonmodule — any caller using a relative bare filename as the copy target will crash. Absolute paths or nested relative paths are unaffected.Severity: Medium — utility method, affects any code path that copies files to the current directory.
Verified reproduction:
IOTinyUtils.copyFile("source.txt", "copy.bin")→ NPE at line 84IOTinyUtils.copyFile("source.txt", "dir/copy.bin")works correctlyA null-guard on
getParentFile()resolves this. An automated fix proposal may be generated. Reply/approveto proceed with PR generation.Automated evaluation by RockteMQ-AI
[ISSUE apache#11461] Cover new and overwritten relative copy targets