Skip to content

fix(gui): don't crash when the file chooser is in "This PC" on Windows - #3049

Merged
skylot merged 1 commit into
skylot:masterfrom
Thanatos9404:fix-file-chooser-shell-folder
Nov 11, 2026
Merged

skylot merged 1 commit into
skylot:masterfrom
Thanatos9404:fix-file-chooser-shell-folder

Conversation

@Thanatos9404

Copy link
Copy Markdown
Contributor

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() calls getCurrentDirectory().toPath(). That throws InvalidPathException: Illegal char <:> at index 0 on the EDT, which is the trace in all four reports. A name typed in that folder fails the same way later in FileUtils.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, as toPathWithTrim does). 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.
  • A small 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:

  • CustomFileChooserTest covers the helper. It uses a NUL character so the test fails the same way on every OS.
  • On Windows 11 (JDK 24), a small harness took Swing's real "This PC" folder, FileSystemView.getParentDirectory(C:/), a Win32ShellFolder2. Its toPath() throws, and toPathOrNull returns null for it; C:/Users converts normally. I could not click through the dialog itself here.
  • ./gradlew clean build dist passes 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 8 is obsolete. This change does not touch them.

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.

@skylot skylot left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Looks good. Thanks.

@skylot
skylot merged commit c8e433b into skylot:master Nov 11, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[gui] Using Windows shell folder path in File Save dialog

2 participants