RFR: 8139228: JFileChooser renders file names as HTML document [v2]
Tejesh R
tr at openjdk.org
Tue May 13 11:04:52 UTC 2025
On Tue, 13 May 2025 03:05:32 GMT, Sergey Bylokhov <serb at openjdk.org> wrote:
>>> Exception in thread "AWT-EventQueue-0" java.nio.file.InvalidPathException: Illegal char <<> at index 0: <html><h1 color=#ff00ff><font face="Comic Sans MS">SWING ROCKS!!!111
>>> at java.base/sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:191)
>>> at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:142)
>>> at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:46)
>>> at java.base/sun.nio.fs.WindowsPath.parse(WindowsPath.java:92)
>>> at java.base/sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:203)
>>> at java.base/java.nio.file.Path.of(Path.java:148)
>>> at java.base/java.nio.file.Paths.get(Paths.java:69)
>>> at java.desktop/sun.awt.shell.ShellFolder.getShellFolder(ShellFolder.java:260)
>>> at java.desktop/javax.swing.filechooser.FileSystemView.getShellFolder(FileSystemView.java:724)
>>> at java.desktop/javax.swing.filechooser.FileSystemView.getSystemIcon(FileSystemView.java:242)
>>> at java.desktop/com.sun.java.swing.plaf.windows.WindowsFileChooserUI$WindowsFileView.getIcon(WindowsFileChooserUI.java:1398)
>>> at java.desktop/javax.swing.JFileChooser.getIcon(JFileChooser.java:1614)
>>
>>
>> This exception looks like a bug? I think if the file was not found then null is an expected result.
>> For now it can be bypassed by this:
>>
>>
>> import java.io.File;
>> import java.lang.Override;
>>
>> import javax.swing.Icon;
>> import javax.swing.JFileChooser;
>> import javax.swing.SwingUtilities;
>> import javax.swing.UIManager;
>> import javax.swing.UnsupportedLookAndFeelException;
>> import javax.swing.filechooser.FileSystemView;
>>
>> public class VirtualFileChooser {
>>
>> public static void main(String[] args) throws UnsupportedLookAndFeelException, ClassNotFoundException, InstantiationException, IllegalAccessException {
>> UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
>> //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel");
>>
>>
>> SwingUtilities.invokeLater(() -> {
>> JFileChooser chooser = new JFileChooser(new VirtualFileSystemView());
>>
>> int result = chooser.showOpenDialog(null);
>> if (result == JFileChooser.APPROVE_OPTION) {
>> File selectedFile = chooser.getSelectedFile();
>> System.out.println("Selected: " + selectedFile.getAbsolutePath());
>> }
>> ...
>
> Note that the bug occurs both in the list of roots (in the dropdown) and in the list of files.
Yes, thank you for the updated virtual test. I've updated the PR with windows L&F fix and also have updated the test too.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/24439#discussion_r2086548132
More information about the client-libs-dev
mailing list