-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Fix SpotBugs false positive in FilePath.IsDescendant #26108
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: master
Are you sure you want to change the base?
Changes from 3 commits
2b39931
9dd83a2
a1044e0
c3332aa
6fe47b6
c23d6a0
1923e13
3361308
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -3781,6 +3781,11 @@ | |||
| Path currentFilePath = parentFile.toPath(); | ||||
| while (!remainingPath.isEmpty()) { | ||||
| Path directChild = this.getDirectChild(currentFilePath, remainingPath); | ||||
| // --- FIX #2: Handle if directChild is null --- | ||||
| if (directChild == null) { | ||||
| return false; | ||||
| } | ||||
|
||||
| // --------------------------------------------- | ||||
|
||||
| // --------------------------------------------- |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -1297,4 +1297,17 @@ private static File newFolder(File root, String... subDirs) throws IOException { | |||
| } | ||||
| return result; | ||||
| } | ||||
|
|
||||
| @Test | ||||
| @Issue("SpotBugs") | ||||
|
||||
| @Issue("SpotBugs") |
Outdated
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.
Please use the JUnit @TempDir annotation to allow the JUnit framework to perform the directory cleanup rather than using try / finally to perform the cleanup yourself. There are several examples available in the Jenkins tests.
Outdated
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.
The coverage report says that the return false line is not covered. It was also not reached when I ran the test in the debugger. Please adjust the test to show the null pointer exception before your change.
Also, if you use the variable temp it is already available in the test class as a TempDir that will be automatically deleted at the end of the test.
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.
I made several attempts to reach the added return null from a test. I was unsuccessful. I'm curious if you can find a way to reach it that I missed.
Copilot
AI
Jan 13, 2026
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 test is redundant with existing comprehensive test coverage for isDescendant. Tests in isDescendant_regularFiles() (lines 1042, 1049-1050, 1053-1057, 1060-1061) already validate the behavior with ".." path traversals, including cases like "sub/../sub/sub-regular.txt", "../protected/secret.txt", "./../workspace", and "./../../root/workspace/regular.txt".
The new test doesn't add meaningful coverage beyond what's already tested. Consider removing this test to avoid redundancy, or if there's a specific edge case this test targets that isn't covered by existing tests, update the test comment to explain what unique scenario is being validated.
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.
The extra comment text is incorrect now and doesn't help comprehension