JDK-8324973 : Replace Vector with ArrayList in BasicDirectoryModel.FilesLoader
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7,8,11,17,21,22,23
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • Submitted: 2024-01-30
  • Updated: 2024-03-04
  • Resolved: 2024-03-04
Related Reports
Relates :  
Relates :  
Relates :  
Description
javax.swing.plaf.basic.BasicDirectoryModel.FilesLoader.run0() stores its temporary lists in Vector objects:

Vector<File> newFileCache;
Vector<File> newFiles;

These are local variables, they aren't accessed concurrently. Therefore, the collections could be replaced with ArrayList which has no synchronisation overhead.

newFileCache is used from another thread.

On Linux and macOS, ShellFolder.invoke runs the Callable on the same thread, using sun.awt.shell.ShellFolderManager.DirectInvoker.

On Windows ShellFolder.invoke executes the code on the COM thread, using sun.awt.shell.Win32ShellFolderManager2.ComInvoker. In this case, the Callable is wrapped into a Future object.

In either case, no additional synchronisation is needed for newFileCache.


I noticed this issue during code review for JDK-8323670.
https://github.com/openjdk/jdk/pull/17462#discussion_r1465414103
Comments
This can't be done. Both newFileCache and newFiles are passed as parameters to sort() method which requires Vector.
04-03-2024

The variables newFileCache and newFiles could be ArrayList instead of Vector to avoid synchronisation penalty where it's not needed. https://github.com/openjdk/jdk/pull/17462#discussion_r1465088991 …I'm for replacing Vector with ArrayList for the newFileCache and newFiles variables. These are local variables, they're not accessed concurrently. https://github.com/openjdk/jdk/pull/17462#discussion_r1465414103
30-01-2024