Fix race condition in ImageHandleManager with ConcurrentHashMap#26
Draft
Fix race condition in ImageHandleManager with ConcurrentHashMap#26
Conversation
- Replace HashMap with ConcurrentHashMap in ImageHandleManager - Use computeIfAbsent() for thread-safe getOrCreate() - Fix similar race conditions in cachedImageData maps in provider wrappers - Add test snippet to demonstrate the race condition scenario Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com>
- Test verifies no race conditions with multiple threads - Ensures exactly one handle created per zoom level - Includes proper error handling and timeout - Validates the ConcurrentHashMap fix Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com>
- Remove redundant remove() call in destroyHandles() - Use public getImageData() API instead of internal win32_getHandle() in snippet - Build verification passed Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add testcase for race condition scenario in SWT
Fix race condition in ImageHandleManager with ConcurrentHashMap
Jan 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Multiple threads concurrently accessing
ImageHandleManager.getOrCreate()for the same zoom level could create duplicate handles, causing resource leaks and wasted CPU/memory. The non-thread-safe HashMap allowed this race:Changes
ImageHandleManager (Image.java)
HashMap→ConcurrentHashMapfor thread-safe handle storagegetOrCreate(): manual check-create-put → atomiccomputeIfAbsent()remove()call indestroyHandles()ImageData caching
HashMap→ConcurrentHashMapinImageFromImageDataProviderWrapperandBaseImageProviderWrappercomputeIfAbsent(), now properly thread-safeImplementation
Testing
Snippet_ImageHandleRaceCondition.java: Demonstrates race condition with 20 threads × 100 iterations, tracks duplicate creation
test_ConcurrentImageHandleAccess(): JUnit test verifying exactly 1 handle created per zoom under concurrent access (10 threads × 50 iterations)
Rationale
ConcurrentHashMap chosen over double-checked locking for simplicity, correctness, and lock-free read performance. A unified caching structure was considered but deferred as it requires architectural refactoring beyond immediate thread-safety needs.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
www.eclipse.org/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/21.0.9-10/x64/bin/java /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/21.0.9-10/x64/bin/java --enable-native-access=ALL-UNNAMED -classpath /opt/hostedtoolcache/maven/3.9.12/x64/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/opt/hostedtoolcache/maven/3.9.12/x64/bin/m2.conf -Dmaven.home=/opt/hostedtoolcache/maven/3.9.12/x64 -Dlibrary.jansi.path=/opt/hostedtoolcache/maven/3.9.12/x64/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/eclipse.platform.swt/eclipse.platform.swt org.codehaus.plexus.classworlds.launcher.Launcher clean compile -DskipTests -pl bundles/org.eclipse.swt -am(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.