RFR: 8325179: Race in BasicDirectoryModel.validateFileCache

Sergey Bylokhov serb at openjdk.org
Tue Mar 5 00:50:56 UTC 2024


On Mon, 4 Mar 2024 20:21:30 GMT, Alexey Ivanov <aivanov at openjdk.org> wrote:

> 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.

src/java.desktop/share/classes/javax/swing/plaf/basic/BasicDirectoryModel.java line 101:

> 99:      */
> 100:     public synchronized void invalidateFileCache() {
> 101:         if (filesLoader != null) {

This is a public API method, can we minimize the change and use "synchronized (this)" instead?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/18111#discussion_r1511986238


More information about the client-libs-dev mailing list