RFR: 8325179: Race in BasicDirectoryModel.validateFileCache
Alexey Ivanov
aivanov at openjdk.org
Mon Mar 4 20:25:01 UTC 2024
Ensure access to the `filesLoader` field of `BasicDirectoryModel` is synchronized.
Without synchronization, a thread checks if `filesLoader` is not null and creates a new `FilesLoader` thread. If the thread is pre-empted between these two operations, another thread or even several threads can see the `null` value and create new `FilesLoader` threads.
The same way, `BasicDirectoryModel.invalidateFileCache` needs to be synchornized to interrupt the current `filesLoader` and assign `null`.
This bug allows reproducing `ConcurrentModificationException` seen in [JDK-8323670](https://bugs.openjdk.org/browse/JDK-8323670) and [JDK-8307091](https://bugs.openjdk.org/browse/JDK-8307091) using the test in PR #18109.
-------------
Commit messages:
- Remove volatile modifier from DoChangeContents in FilesLoader
- Remove synchronized modifier from DoChangeContents.run
- Declare addStart and remStart in DoChangeContents as final
- Reverse condition in DoChangeContents.run to decrease indentation
- Remove cancelRunnables
- Declare newFiles as final
- Remove redundant fileSystem variable in FilesLoader.run0
- Create FilesLoader inside synchronized section
Changes: https://git.openjdk.org/jdk/pull/18111/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=18111&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8325179
Stats: 61 lines in 1 file changed: 14 ins; 23 del; 24 mod
Patch: https://git.openjdk.org/jdk/pull/18111.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/18111/head:pull/18111
PR: https://git.openjdk.org/jdk/pull/18111
More information about the client-libs-dev
mailing list