Repository navigation
fix(gui): don't crash when the file chooser is in "This PC" on Windows - #3049
Merged
Merged
Conversation
Windows shell folders like This PC have no file system path, so File.toPath() threw InvalidPathException when the dialog was approved inside one. Keep the previous current directory in that case, and don't approve a selection without a path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2548 (also reported in #2586, #2635 and #3029).
On Windows, the Swing file chooser can navigate into shell folders such as "This PC", whose path is
::{20D04FE0-3AEA-1069-A2D8-08002B30309D}. If the dialog is approved while it is in such a folder, for example after picking a drive there,showDialog()callsgetCurrentDirectory().toPath(). That throwsInvalidPathException: Illegal char <:> at index 0on the EDT, which is the trace in all four reports. A name typed in that folder fails the same way later inFileUtils.toPathsWithTrim.Changes in
CustomFileChooser:showDialog()remembers the current directory only when it has a file system path. Otherwise the previous one is kept.approveSelection()checks each selected file (trimmed, astoPathWithTrimdoes). If one has no file system path, the dialog opens it when it is a folder, or gives the usual error feedback and stays open, instead of returning a path that would crash.toPathOrNull(File)helper does the conversion.Real paths behave as before, including names typed with a trailing space. The "Use alternative file dialog" workaround is no longer needed.
Testing:
CustomFileChooserTestcovers the helper. It uses a NUL character so the test fails the same way on every OS.FileSystemView.getParentDirectory(C:/), aWin32ShellFolder2. ItstoPath()throws, andtoPathOrNullreturns null for it;C:/Usersconverts normally. I could not click through the dialog itself here../gradlew clean build distpasses in jadx-gui (78 tests), jadx-cli and spotless. The 7 jadx-core integration tests that fail here (e.g.TestAnonymousClass2) fail because JDK 24's javac warns that-source 8is obsolete. This change does not touch them.