RFR: 8327137: Add test for ConcurrentModificationException in BasicDirectoryModel

Sergey Bylokhov serb at openjdk.org
Thu Mar 14 19:41:41 UTC 2024


On Mon, 4 Mar 2024 15:52:45 GMT, Alexey Ivanov <aivanov at openjdk.org> wrote:

> I'm adding a regression test for [JDK-8323670](https://bugs.openjdk.org/browse/JDK-8323670) and [JDK-8307091](https://bugs.openjdk.org/browse/JDK-8307091); it's also a regression test for [JDK-8240690](https://bugs.openjdk.org/browse/JDK-8240690).
> 
> I referenced this test in PR #17462 in [this comment](https://github.com/openjdk/jdk/pull/17462#issuecomment-1914844026). I fine-tuned the test since that time.
> 
> The test doesn't fail all the time without the fix for JDK-8323670, however, it fails sometimes. If you run the test several times, it will likely fail _without the fix_.
> 
> For me, the test fails about 10 times from 40 runs in the CI. It fails on macOS more frequently than on Linux.
> 
> When the test passes, it usually completes in 5 minutes.
> 
> **How the test works**
> 
> The test creates a temporary directory in the current directory and creates a number of files in it. (The number of files is controlled by `NUMBER_OF_THREADS` constant). Then the test creates `JFileChooser` in the temporary directory.
> 
> The test starts several _scanner_ threads, the number is controlled by `NUMBER_OF_THREADS`, which repeatedly call `fileChooser.rescanCurrentDirectory()`. This results in calling `BasicDirectoryModel.validateFileCache` which starts a background thread — "Basic L&F File Loading Thread" — to enumerate the files.
> 
> A timer is used to create new files in the directory that the file chooser is using.
> 
> After enumerating the files, the File Loading Thread posts an event to EDT. The event updates `fileCache` and fires a `ListDataEvent`.
> 
> If the File Loading Thread is iterating over `fileCache` using `Iterator` (when `fileCache.subList` or `fileCache.equals` is running; or a new `Vector` instance is created from a `fileCache` or its sublist) and `fileCache` is being updated on EDT, then `ConcurrentModificationException` is thrown.
> 
> On Linux and on _headless_ macOS, `ShellFolder.invoke` is executed in the caller, which makes it easier to reproduce the issue. Because of [JDK-8325179](https://bugs.openjdk.org/browse/JDK-8325179), there are several File Loading Threads, which also helps to reproduce the issue.
> 
> On _headful_ macOS, the `BasicDirectoryModel` is not used, so the test does not reproduce the issue.
> 
> On Windows, the test does not fail or fails with `OutOfMemoryError`. It is because all the File Loading Threads are serialised on the COM thread, `ShellFolder.invoke` submits the task to the COM thread and waits for it to complete. The chance of updating `fileCache` whil...

test/jdk/javax/swing/plaf/basic/BasicDirectoryModel/ConcurrentModification.java line 1:

> 1: import java.io.IOException;

the header is missing.

test/jdk/javax/swing/plaf/basic/BasicDirectoryModel/ConcurrentModification.java line 99:

> 97:             createFiles(temp);
> 98: 
> 99:             final JFileChooser fc = new JFileChooser(temp.toFile());

it should be created on EDT, just in case.

test/jdk/javax/swing/plaf/basic/BasicDirectoryModel/ConcurrentModification.java line 211:

> 209:     private static void deleteFile(final Path file) {
> 210:         try {
> 211:             Files.delete(file);

Should we try to delete all files first and then throw an exception if any?

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/18109#discussion_r1525401885
PR Review Comment: https://git.openjdk.org/jdk/pull/18109#discussion_r1525401638
PR Review Comment: https://git.openjdk.org/jdk/pull/18109#discussion_r1525403026


More information about the client-libs-dev mailing list