On Tue, 24 Jan 2023 03:15:50 GMT, Sergey Bylokhov <s...@openjdk.org> wrote:

> Two methods in the BeanContextSupport class use two locks in a different 
> order, which can cause a deadlock. 
> 
> Here is the first order: (1) first acquire BeanContext.globalHierarchyLock 
> and then children:
> 
>     enter public method remove(Object) at line 484
>     call remove(Object, boolean) at line 485
>     acquire synchronization on BeanContext.globalHierarchyLock at line 502
>     acquire synchronization on children at line 534
> 
> Here is the second order: (2) first acquire children and then 
> BeanContext.globalHierarchyLock:
> 
>     enter public method propertyChange() at line 1110
>     acquire synchronization on children at line 1114
>     call remove(Object, boolean) at line 1121
>     acquire synchronization on BeanContext.globalHierarchyLock at line 502 
> 
> The fix added the "BeanContext.globalHierarchyLock" before the usage of the 
> "children" lock in the propertyChange method.

Oof... Approach for synchronization in `BeanContextServicesSupport` is 
confusing for me and inconsistent.
Do you know why read access to `children` is not syncrhonized in 
`java.beans.beancontext.BeanContextSupport#add` ?
https://github.com/openjdk/jdk/blob/3be5758bb413fb6b4dc6191d78ca38332d5153f1/src/java.desktop/share/classes/java/beans/beancontext/BeanContextSupport.java#L394

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

PR: https://git.openjdk.org/jdk/pull/12158

Reply via email to