[concurrency-interest] concurrency errors in java.lang.Throwable
forax at univ-mlv.fr
Wed Aug 2 09:33:26 EDT 2006
I think i've found a concurrency bug in the Sun implementation
Since 1.4, Throwable accepts a cause at construction time
using a ad hoc constructors or after if initilialisation using
the method initCause().
First, the field can't be final and is not volatile, the method
getCause() is not
synchronized and doesn't use a lock, so a thread can create an exception
with a cause and another thread can see the same exception without
Second, initCause is synchronized but getCause() is not, so a thread
can call initCause() and another thread never see the change.
Am i right ?
Should the field that store the cause be volatile and use
a CAS in initCause() to initialize the cause (the cause can't be
initialized twice) ?
More information about the Concurrency-interest