-
Notifications
You must be signed in to change notification settings - Fork 106
wagon-ssh-external: Use absolute-dir in case localFile.getParentFile returns null
#817
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: wagon-3.x
Are you sure you want to change the base?
Conversation
…) returns null If using `mvn gpg:sign-and-deploy-file` as shown below, localFile becomes e.g. `gluegen-2.6.0-sources.jar`, i.e. relative and w/o parent-directory. Hence localFile.getParentFile() returns null and the previous code fails to transport the file. ``` mvn -e gpg:sign-and-deploy-file \ -DpomFile=pom.xml" \ -Dfile=gluegen.jar" \ -Dfiles=gluegen-2.6.0-sources.jar,gluegen-2.6.0-javadoc.jar" \ -Dclassifiers=sources,javadoc" \ -Dtypes=jar,jar" \ -Durl=scpexe://jordan/srv/www/jordan/deployment/maven/ \ -DrepositoryId=jordan-mirror ``` This patch uses the localFile.getAbsoluteFile() in case localFile.getParentFile() returns null and renders wagon-ssh-external functional w/ above `mvn gpg:sign-and-deploy-file` Tested via `mvn install -Dmaven.test.skip` and `mvn install` and JogAmp's maven install scripts at <https://jogamp.org/cgit/jogamp-scripting.git/>.
Using patched `wagon-ssh-external` version `3.5.4-SNAPSHOT`, as this version allows processing relative file names - [patch](sgothel/maven-wagon@e8ffd15) - [merge request](apache/maven-wagon#817)
|
bump, is this the right channel to ask for a merge? @olamy ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a bug where ScpExternalWagon fails when mvn gpg:sign-and-deploy-file is used with relative file paths. When a file is specified as a relative path (e.g., gluegen-2.6.0-sources.jar), the getParentFile() method returns null, causing the original code to fail with a NullPointerException.
Key changes:
- Added null check for
localFile.getParentFile()before setting the working directory - Falls back to using
getAbsoluteFile().getParentFile()when the parent is null - Includes SecurityException handling for the absolute path resolution
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| fireTransferError(resource, e, put ? TransferEvent.REQUEST_PUT : TransferEvent.REQUEST_GET); | ||
|
|
||
| throw new TransferFailedException("Error accessing absolute path of " + localFile, e); | ||
| } |
Copilot
AI
Dec 29, 2025
There was a problem hiding this comment.
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.
| } | |
| } | |
| 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; | |
| } |
| 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); | ||
| } | ||
| } |
Copilot
AI
Dec 29, 2025
There was a problem hiding this comment.
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.
If using
mvn gpg:sign-and-deploy-fileas shown below, localFile becomes e.g.gluegen-2.6.0-sources.jar, i.e. relative and w/o parent-directory. Hence localFile.getParentFile() returns null and the previous code fails to transport the file.This patch uses the localFile.getAbsoluteFile() in case localFile.getParentFile() returns null and renders wagon-ssh-external functional w/ above
mvn gpg:sign-and-deploy-fileTested via
mvn install -Dmaven.test.skipandmvn installand JogAmp's maven install scripts at https://jogamp.org/cgit/jogamp-scripting.git/.Following this checklist to help us incorporate your
contribution quickly and easily:
Note that commits might be squashed by a maintainer on merge.
This may not always be possible but is a best-practice.
mvn verifyto make sure basic checks pass.A more thorough check will be performed on your pull request automatically.
mvn -Prun-its verify).If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.
To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.