Part of #224: Improve Thread Safety in Component and Container
Scope
Address issues #1 and #2 from the parent issue:
-
Component.parent field not protected by lock (Component.java line 28)
getParent() and setParent() (lines 116-122) access without synchronization
repaint() (line 228) walks the parent chain without locking
-
Component.repaint() walks parent chain unsynchronized (Component.java lines 226-234)
- Creates race with
Container.add()/remove() which call setParent()
- Could read null or stale parent during tree mutation
Proposed Fix
- Protect parent field access with
renderLock or use AtomicReference<Component>
- Acquire
renderLock before walking parent chain in repaint(), or use copy-on-write parent reference
Acceptance Criteria
Part of #224: Improve Thread Safety in Component and Container
Scope
Address issues #1 and #2 from the parent issue:
Component.parent field not protected by lock (
Component.javaline 28)getParent()andsetParent()(lines 116-122) access without synchronizationrepaint()(line 228) walks the parent chain without lockingComponent.repaint() walks parent chain unsynchronized (
Component.javalines 226-234)Container.add()/remove()which callsetParent()Proposed Fix
renderLockor useAtomicReference<Component>renderLockbefore walking parent chain inrepaint(), or use copy-on-write parent referenceAcceptance Criteria
parentfield access is synchronized or atomicrepaint()parent chain traversal is thread-saferepaint()andContainer.add()/remove()