Issue Details (XML | Word | Printable)

Key: LANG-369
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Sebb
Votes: 0
Watchers: 0
Operations

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

ExceptionUtils not thread-safe

Created: 30/Oct/07 05:36 PM   Updated: 16/May/09 07:32 AM
Return to search
Component/s: None
Affects Version/s: None
Fix Version/s: 3.0, 2.x

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works LANG-369-2.patch 2009-03-14 02:39 PM Sebb 3 kB
Text File Licensed for inclusion in ASF works LANG-369.patch 2007-11-09 08:20 AM Henri Yandell 4 kB

Resolution Date: 17/Mar/09 08:55 PM


 Description  « Hide
The ExceptionUtils class does not appear to be thread-safe:
  • CAUSE_METHOD_NAMES is not final, so may not be visible to all threads
  • addCauseMethodName() and removeCauseMethodName() can update CAUSE_METHOD_NAMES but are not synch.
  • all accesses to CAUSE_METHOD_NAMES probably need to be synchronised

The documentation does not state whether or not the class is thread-safe, but given that it only has static methods it does not make any sense unless it is thread-safe.



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Henri Yandell added a comment - 03/Nov/07 08:06 AM
Agreed - synchronizing the variable seems the best thing to do.

Henri Yandell made changes - 03/Nov/07 08:06 AM
Field Original Value New Value
Fix Version/s 2.4 [ 12312481 ]
Henri Yandell added a comment - 09/Nov/07 08:20 AM
Patch that liberally splashes synchronized around the variable.

Henri Yandell made changes - 09/Nov/07 08:20 AM
Attachment LANG-369.patch [ 12369216 ]
Ben Speakmon added a comment - 12/Nov/07 07:46 PM
Patch looks safe.

Repository Revision Date User Message
ASF #594278 Mon Nov 12 19:58:30 UTC 2007 bayard Applying the synchronization from LANG-369
Files Changed
MODIFY /commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ExceptionUtils.java

Henri Yandell added a comment - 12/Nov/07 07:58 PM
svn ci -m "Applying the synchronization from LANG-369" src/java/org/apache/commons/lang/exception/ExceptionUtils.java

Sending src/java/org/apache/commons/lang/exception/ExceptionUtils.java
Transmitting file data .
Committed revision 594278.


Henri Yandell made changes - 12/Nov/07 07:58 PM
Status Open [ 1 ] Closed [ 6 ]
Resolution Fixed [ 1 ]
Sebb added a comment - 14/Mar/09 02:33 PM
I think the wrong lock object is used in the synchronization.

The code uses the CAUSE_METHOD_NAMES object as the lock and then changes it in the synchronized block, i.e. the lock object is changed.

This occurs in removeCauseMethodName() and addCauseMethodName().

Either lock on the class, or use a dummy static final Object as the lock.

This applies to 2.4 branch and trunk


Sebb made changes - 14/Mar/09 02:33 PM
Status Closed [ 6 ] Reopened [ 4 ]
Resolution Fixed [ 1 ]
Sebb added a comment - 14/Mar/09 02:39 PM
Patch which adds static final Object as a lock.

Sebb made changes - 14/Mar/09 02:39 PM
Attachment LANG-369-2.patch [ 12402204 ]
Henri Yandell made changes - 15/Mar/09 02:39 AM
Fix Version/s 2.4 [ 12312481 ]
Fix Version/s 2.x [ 12313695 ]
Fix Version/s 3.0 [ 12311714 ]
Repository Revision Date User Message
ASF #755391 Tue Mar 17 20:54:52 UTC 2009 sebb LANG-369 - must use fixed object as lock target
Files Changed
MODIFY /commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ExceptionUtils.java

Sebb added a comment - 17/Mar/09 08:55 PM
Applied patch:

URL: http://svn.apache.org/viewvc?rev=755391&view=rev
Log:
LANG-369 - must use fixed object as lock target


Sebb made changes - 17/Mar/09 08:55 PM
Resolution Fixed [ 1 ]
Status Reopened [ 4 ] Resolved [ 5 ]
Henri Yandell made changes - 16/May/09 07:32 AM
Status Resolved [ 5 ] Closed [ 6 ]