Community
Participate
Working Groups
There are threading issues in SystemTempFileListener: * The _isSynching variable is not synchronized between main thread and worker thread, it should be marked volatile * The _changedResources ArrayList is modified in the main thread (by clearing it), but at the same time another thread may call add(), this may lead to a ConcurrentModificationException * In case an exception happens in the RefreshResourcesUIJob, the _isSynching variable is not reset so it can never sync again
Created attachment 75845 [details] Patch to fix threading issues Attached patch fixes the issues: * Declare _isSynching volatile to fix multi-thread access * Make the synchronized(_changedResources) block smaller, by first copying contents into a separate array then clearing the arrayList; that way, we are sure to never call out of the synchronized block, avoiding deadlock. * Add synchronzied(_changedResources) around the _changedResources.add() call in order to avoid ConcurrentModificationException * Put try ... finally block around the code between the _isSynching mutex
Patch committed: [199573] Fix potential threading issues in SystemTempFileListener SystemTempFileListener.java 1.21 Everybody please review the changes for educational purposes. It's a very typical example of how threading issues are to be avoided in Java.