Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,18 @@ private void executeScpCommand(Resource resource, File localFile, boolean put)
}
Commandline cl = createBaseCommandLine(putty, scpExecutable, privateKey);

cl.setWorkingDirectory(localFile.getParentFile().getAbsolutePath());
File parentFile = localFile.getParentFile();
if (null == parentFile) {
try {
File abs = localFile.getAbsoluteFile();
parentFile = abs.getParentFile();
} catch (SecurityException e) {
fireTransferError(resource, e, put ? TransferEvent.REQUEST_PUT : TransferEvent.REQUEST_GET);

throw new TransferFailedException("Error accessing absolute path of " + localFile, e);
}
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

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

After obtaining the absolute file, there's still no null check on the second call to getParentFile(). According to Java documentation, getAbsoluteFile().getParentFile() can still return null for filesystem roots (e.g., "/" on Unix or "C:" on Windows). This would cause a NullPointerException on line 243 when calling parentFile.getAbsolutePath(). Consider adding a null check after line 236 and throwing a TransferFailedException with a descriptive message if parentFile is still null.

Suggested change
}
}
if (parentFile == null) {
TransferFailedException e =
new TransferFailedException("Cannot determine parent directory of " + localFile);
fireTransferError(resource, e, put ? TransferEvent.REQUEST_PUT : TransferEvent.REQUEST_GET);
throw e;
}

Copilot uses AI. Check for mistakes.
}
Comment on lines +232 to +242
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

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

This change introduces new behavior for handling relative file paths without test coverage. Since the repository already has test files for ScpExternalWagon, consider adding a test case that verifies the behavior when localFile.getParentFile() returns null (e.g., when using a relative path like "gluegen-2.6.0-sources.jar"). This would help ensure the fix works as intended and prevent regressions.

Copilot uses AI. Check for mistakes.
cl.setWorkingDirectory(parentFile.getAbsolutePath());

int port =
repository.getPort() == WagonConstants.UNKNOWN_PORT ? ScpHelper.DEFAULT_SSH_PORT : repository.getPort();
Expand Down
Loading