Issue Details (XML | Word | Printable)

Key: MATH-253
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Luc Maisonobe
Reporter: Sebb
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Commons Math

MathRuntimeException and MathException are both thread-hostile.

Created: 04/Apr/09 09:22 PM   Updated: 23/Apr/09 02:26 AM
Return to search
Component/s: None
Affects Version/s: None
Fix Version/s: 2.0

Time Tracking:
Not Specified

Resolution Date: 05/Apr/09 03:37 PM


 Description  « Hide
MathRuntimeException and MathException are both thread-hostile.

They have a mutable static field cachedResources which is used in performing translations.

If two threads use different locales - which is highly likely in the case of non-US locales, as some methods use Locale.US - then they may get corrupt or incorrect output.

If a cache is really desired, it could either be ThreadLocal, or volatile, but it that case the translate method needs to fetch the value once (and update it once if necessary).

As it stands, the method can check the resource, find it is OK, then fetch it again to use it, by which time it might have changed. Further, one thread may set the variable, and another thread may see a partially constructed Resources object (it's not final).



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Repository Revision Date User Message
ASF #762107 Sun Apr 05 15:33:06 UTC 2009 luc Fixed threading issues with MathException and MathRuntimeException
Jira: MATH-253
Files Changed
MODIFY /commons/proper/math/trunk/src/site/xdoc/changes.xml
MODIFY /commons/proper/math/trunk/src/java/org/apache/commons/math/MathException.java
MODIFY /commons/proper/math/trunk/src/java/org/apache/commons/math/MathRuntimeException.java