harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Ellison <t.p.elli...@gmail.com>
Subject Re: [jira] Commented: (HARMONY-6009) [classlib][beans] NPE launching swingset2 example
Date Thu, 20 Nov 2008 20:54:58 GMT
Kevin Zhou wrote:
> The globalListeners can only be modified by synchronized
> "addPropertyChangeListener" and "removePropertyChangeListener".
> In addition, these listeners may also be serialized or deserialized by
> some applications via "writeObject" and "readObject" methods.
> But all of the above methods has excluded the null value from
> globalListeners.

Yep.

> In addition, since this defect can not be reproduced at my site. Thus I
> don't think it can be given a null in Beans code.
> If any code can add a null value, this should also occurs on my site.

I'll try to recreate it too.  While it was reliably reproducible for me,
I've since rebuilt and can't reproduce it now ;-/

> Assume one scenario as follows:
> If one thread calls doFirePropertyChange method, successfully acquires
> an array of all the global listeners and stops at line263; another
> thread calls removePropertyChangeListener; the 1st thread start to call
> propertyChange method, but one of listeners in the acquired array is
> null, then it throws NPE. (This may also happen when calling
> addPropertyChangeListener method.)
> Do you think this could happen on our code?

I don't think this can happen.

When the globalListeners list is copied into the gListeners array (lines
259/260) then any removals from globalListeners will not affect gListeners.

In theory, since ArrayList is not synchronized, we could be unlucky and
get a remove() during the toArray() that causes problems.

I wouldn't want to synchronize the whole doFirePropertyChange() method,
since the propertyChange() callback may take some indeterminate time to
execute and we don't want to lock the list for long.  We could
synchronize(this) for the .toArray() call.

Regards,
Tim

Mime
View raw message