Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8296198

JFileChooser throws InternalError java.lang.InternalError with Windows shortcuts

    XMLWordPrintable

Details

    • b27
    • x86_64
    • windows_10

    Description

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10, tried with Java 15, Java 17 and Java 20 (Early Access)

      A DESCRIPTION OF THE PROBLEM :
      When having a shortcut to a folder on Windows, you normally can follow the shortcut by double clicking it. If you are creating the JFileChooser with your own FileSystemView you always get an Exception:

      Exception in thread "AWT-EventQueue-0" java.lang.InternalError: Unable to bind C:\temp\myShortcutToFolder.lnk to parent
              at java.desktop/sun.awt.shell.Win32ShellFolder2$4.call(Win32ShellFolder2.java:474)
              at java.desktop/sun.awt.shell.Win32ShellFolder2$4.call(Win32ShellFolder2.java:458)
              at java.desktop/sun.awt.shell.Win32ShellFolderManager2$ComInvoker.invoke(Win32ShellFolderManager2.java:626)
              at java.desktop/sun.awt.shell.ShellFolder.invoke(ShellFolder.java:532)
              at java.desktop/sun.awt.shell.Win32ShellFolder2.getIShellFolder(Win32ShellFolder2.java:458)
              at java.desktop/sun.awt.shell.Win32ShellFolder2$16.call(Win32ShellFolder2.java:1261)
              at java.desktop/sun.awt.shell.Win32ShellFolder2$16.call(Win32ShellFolder2.java:1259)
              at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
              at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
              at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
              at java.desktop/sun.awt.shell.Win32ShellFolderManager2$ComInvoker$1.run(Win32ShellFolderManager2.java:595)
              at java.base/java.lang.Thread.run(Thread.java:1591)

      This Issue has ben reported multiple times but all bug reports I found here were either marked as "cannot reproduce" or as duplicate of an bug report marked as cannot reproduce.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Create a shortcut in "C:\temp" to a folder of your liking (you can create the shortcut anywhere else. It is just to have a short, easy to remeber path for the following setpes. The only condition is that the shortcut has to be a shortcut to a folder)
      2. Execute the attached java Program (a JFileChooser with a custom FileSystemView)
      => A File Chooser Opens
      3. Navigate to C:\temp (or the path you created the shortcut in)
      => The shortcut should be shown as an normal folder
      4. Double click on the shortcut
      => The exception is thrown "java.lang.InternalError: Unable to bind C:\temp\myShortcutToFolder.lnk to parent"


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The shortcut should be followed and the folder the shortcut points to should be displayed in the File Chooser
      ACTUAL -
      An Exception is thrown "java.lang.InternalError: Unable to bind C:\temp\myShortcutToFolder.lnk to parent"

      ---------- BEGIN SOURCE ----------
      import java.io.File;
      import java.io.FileNotFoundException;
      import java.io.IOException;

      import javax.swing.Icon;
      import javax.swing.JFileChooser;
      import javax.swing.filechooser.FileSystemView;

      public class JFileChooserError {

        public static void main(String[] args) {
          JFileChooser fc = new JFileChooser(new MyFileSystemView());
          fc.showOpenDialog(null);
        }

        private static class MyFileSystemView extends FileSystemView {

          FileSystemView delegate;

          MyFileSystemView() {
            delegate = FileSystemView.getFileSystemView();
            assert "javax.swing.filechooser.WindowsFileSystemView"
                .equals(delegate.getClass().getCanonicalName()) : "Please run this on Windows";
          }

          @Override
          public File createNewFolder(File containingDir) throws IOException {
            return delegate.createNewFolder(containingDir);
          }

          @Override
          public boolean isRoot(File f) {
            return delegate.isRoot(f);
          }

          @Override
          public Boolean isTraversable(File f) {
            return delegate.isTraversable(f);
          }

          @Override
          public String getSystemDisplayName(File f) {
            return delegate.getSystemDisplayName(f);
          }

          @Override
          public String getSystemTypeDescription(File f) {
            return delegate.getSystemTypeDescription(f);
          }

          @Override
          public Icon getSystemIcon(File f) {
            return delegate.getSystemIcon(f);
          }

          @Override
          public Icon getSystemIcon(File f, int width, int height) {
            return delegate.getSystemIcon(f, width, height);
          }

          @Override
          public boolean isParent(File folder, File file) {
            return delegate.isParent(folder, file);
          }

          @Override
          public File getChild(File parent, String fileName) {
            return delegate.getChild(parent, fileName);
          }

          @Override
          public boolean isFileSystem(File f) {
            return delegate.isFileSystem(f);
          }

          @Override
          public boolean isHiddenFile(File f) {
            return delegate.isHiddenFile(f);
          }

          @Override
          public boolean isFileSystemRoot(File dir) {
            return delegate.isFileSystemRoot(dir);
          }

          @Override
          public boolean isDrive(File dir) {
            return delegate.isDrive(dir);
          }

          @Override
          public boolean isFloppyDrive(File dir) {
            return delegate.isFloppyDrive(dir);
          }

          @Override
          public boolean isComputerNode(File dir) {
            return delegate.isComputerNode(dir);
          }

          @Override
          public File[] getRoots() {
            return delegate.getRoots();
          }

          @Override
          public File getHomeDirectory() {
            return delegate.getHomeDirectory();
          }

          @Override
          public File getDefaultDirectory() {
            return delegate.getDefaultDirectory();
          }

          @Override
          public File createFileObject(File dir, String filename) {
            return delegate.createFileObject(dir, filename);
          }

          @Override
          public File createFileObject(String path) {
            return delegate.createFileObject(path);
          }

          @Override
          public File[] getFiles(File dir, boolean useFileHiding) {
            return delegate.getFiles(dir, useFileHiding);
          }

          @Override
          public File getParentDirectory(File dir) {
            return delegate.getParentDirectory(dir);
          }

          @Override
          public File[] getChooserComboBoxFiles() {
            return delegate.getChooserComboBoxFiles();
          }

          @Override
          public boolean isLink(File file) {
            return delegate.isLink(file);
          }

          @Override
          public File getLinkLocation(File file) throws FileNotFoundException {
            return delegate.getLinkLocation(file);
          }

        }

      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      No workaround found

      FREQUENCY : always


      Attachments

        Issue Links

          Activity

            People

              tr Tejesh R
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: