commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Phil Steitz (JIRA)" <>
Subject [jira] Commented: (MATH-505) TestUtils is thread-hostile
Date Tue, 01 Feb 2011 05:16:29 GMT


Phil Steitz commented on MATH-505:

Making the methods instance sort of defeats the purpose of the class.  None of the instance
data in any of the static singletons is actually used or depended on by the methods of this
class.  You are correct though that if one thread changes the impl for one of the singletons
while another is using the class, the other could see a different than expected impl.  I think
the practical likelihood of this is pretty much nil, as it is hard to imagine an application
supplying two different implementations for the tests and wanting different threads to use
different impls.  Personally, I would be happy just documenting the fact that the class is
not threadsafe and if concurrent threads want to plug in different implementations, they need
to synchronize on the class.  If this is not acceptable, my next preference would be to remove
the pluggability - i.e., make the singletons final or get rid of them altogether, creating
instances as needed for static method calls.  There is no initialization overhead creating
the test classes.

> TestUtils is thread-hostile
> ---------------------------
>                 Key: MATH-505
>                 URL:
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 1.2, 2.1
>            Reporter: Sebb
> TestUtils has several mutable static fields which are not synchronised, or volatile.
> If one of the fields is updated by thread A, there is no guarantee that thread B will
see the full update - it may see a partially updated object.
> Furthermore, at least some of the static fields reference a mutable object, which can
be changed whilst another thread is using it.
> As far as I can tell, this class must only ever be used by a single thread otherwise
the results will be unpredictable.

This message is automatically generated by JIRA.
For more information on JIRA, see:


View raw message