-
-
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 1 commit
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 | ||
|---|---|---|---|---|
|
|
@@ -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 --- | ||||
| Path parentRealPath; | ||||
| try { | ||||
| if (Functions.isWindows()) { | ||||
|
|
@@ -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 --- | ||||
|
||||
| // --- FIX #2: Handle if directChild is null --- |
Outdated
Copilot
AI
Jan 12, 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.
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).
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.
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
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.
Doesn't help comprehension of the change
| // --------------------------------------------- |
Uh oh!
There was an error while loading. Please reload this page.
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 null check is unnecessary. The Util.fileToPath method is annotated with
@NonNulland 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.