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

BasicDirectoryModel splits file list into directories and files twice

XMLWordPrintable

      BasicDirectoryModel provides methods getDirectories() and getFiles(). These methods go through `fileCache` which contains both and adds files into `directories` if the file is traversable or into `files` otherwise.

      https://github.com/openjdk/jdk/blob/f365d807e5552a6ad9a36afd82db8f0881d62cc3/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicDirectoryModel.java#L139-L146

      The same is done in validateFileCache(), in particular in javax.swing.plaf.basic.BasicDirectoryModel.FilesLoader.run0(). There are two lists (vectors): `newFileCache` and `newFiles`. The files are added into these two lists based on filechooser.isTraversable(file) condition.

      https://github.com/openjdk/jdk/blob/f365d807e5552a6ad9a36afd82db8f0881d62cc3/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicDirectoryModel.java#L318-L332

      After this loop, `newFileCache` contains directories only and `newFiles` contains files only.

      Later, `newFiles` are added into `newFileCache`. If a new variable is introduced, it will be possible to keep three lists: `newDirectories`, `newFiles` and `newFileCache`.

      Store all of them in DoChangeContents object and, after `fileCache` is updated

      https://github.com/openjdk/jdk/blob/f365d807e5552a6ad9a36afd82db8f0881d62cc3/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicDirectoryModel.java#L547-L556

      store the values of `newDirectories` and `newFiles` as the new values for `directories` and `files` correspondingly. And add '..' to `directories`.

            aivanov Alexey Ivanov
            aivanov Alexey Ivanov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: