Skip to content

Thread Safety: Protect Component.parent field and synchronize parent chain traversal #252

Description

@sfloess

Part of #224: Improve Thread Safety in Component and Container

Scope

Address issues #1 and #2 from the parent issue:

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

  • parent field access is synchronized or atomic
  • repaint() parent chain traversal is thread-safe
  • No race between repaint() and Container.add()/remove()
  • Existing tests pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions