Skip to content
11 changes: 11 additions & 0 deletions core/src/main/java/hudson/FilePath.java
Original file line number Diff line number Diff line change
Expand Up @@ -3762,6 +3762,12 @@ public Boolean invoke(@NonNull File parentFile, @NonNull VirtualChannel channel)
}

Path parentAbsolutePath = Util.fileToPath(parentFile.getAbsoluteFile());
// --- FIX START: Handle potential null from Util.fileToPath ---
if (parentAbsolutePath == null) {
LOGGER.log(Level.FINE, "Invalid path characters in parentFile: {0}", parentFile);
return false;
}
// --- FIX END ---
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

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

This null check is unnecessary. The Util.fileToPath method is annotated with @NonNull and throws IOException on invalid paths rather than returning null. If an InvalidPathException occurs, Util.fileToPath will throw IOException which will propagate from this invoke method (which declares throws IOException). Remove this null check as it creates unreachable code.

Suggested change
// --- FIX START: Handle potential null from Util.fileToPath ---
if (parentAbsolutePath == null) {
LOGGER.log(Level.FINE, "Invalid path characters in parentFile: {0}", parentFile);
return false;
}
// --- FIX END ---

Copilot uses AI. Check for mistakes.
Path parentRealPath;
try {
if (Functions.isWindows()) {
Expand All @@ -3781,6 +3787,11 @@ public Boolean invoke(@NonNull File parentFile, @NonNull VirtualChannel channel)
Path currentFilePath = parentFile.toPath();
while (!remainingPath.isEmpty()) {
Path directChild = this.getDirectChild(currentFilePath, remainingPath);
// --- FIX #2: Handle if directChild is null ---
Copy link
Contributor

Choose a reason for hiding this comment

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

The extra comment text is incorrect now and doesn't help comprehension

Suggested change
// --- FIX #2: Handle if directChild is null ---

if (directChild == null) {
return false;
}
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

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

Add test coverage for the case where getDirectChild returns null. While the existing isDescendant tests are comprehensive, none appear to exercise the specific edge case where getDirectChild would return null (when the child path cannot be resolved to a direct child of the parent path).

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

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

none appear to exercise the specific edge case where getDirectChild would return null (when the child path cannot be resolved to a direct child of the parent path).

I don't think that edge case can be exercised because there is specific code in the method that rejects absolute paths

// ---------------------------------------------
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't help comprehension of the change

Suggested change
// ---------------------------------------------

Path childUsingFullPath = currentFilePath.resolve(remainingPath);
String childUsingFullPathAbs = childUsingFullPath.toAbsolutePath().toString();
String directChildAbs = directChild.toAbsolutePath().toString();
Expand Down
Loading