Issue Details (XML | Word | Printable)

Key: JETTY-352
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Yug
Votes: 0
Watchers: 0
Operations

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

Don't use Strings as locks

Created: 29/May/07 04:16 AM   Updated: 04/Jun/07 11:18 AM   Resolved: 29/May/07 07:59 AM
Return to search
Component/s: None
Affects Version/s: 6.1.3
Fix Version/s: 6.1.4rc0

Time Tracking:
Not Specified


 Description  « Hide

Bad locking behavior in BoundedThreadPool may lead to unexpected deadlocks in conjunction with other code. This is caused by java's special string handling. Every String "LOCK" is the same object. If jetty uses synchronized("LOCK") and some other code which has absolutely nothing to do with jetty, but happens to run inside the same jvm , uses synchronized("LOCK"), they both lock the same object...

BoundedThreadPool :
private final String _lock = "LOCK";
...
synchronized(_lock)
{
...
}

From the java language specification:

  1. Literal strings within the same class (§8) in the same package (§7) represent references to the same String object (§4.3.1).
  2. Literal strings within different classes in the same package represent references to the same String object.
  3. Literal strings within different classes in different packages likewise represent references to the same String object.
  4. Strings computed by constant expressions (§15.28) are computed at compile time and then treated as if they were literals.
  5. Strings computed at run time are newly created and therefore distinct.
  6. The result of explicitly interning a computed string is the same string as any pre-existing literal string with the same contents.


Greg Wilkins added a comment - 29/May/07 07:59 AM

thanks - fixed


Greg Wilkins made changes - 29/May/07 07:59 AM
Field Original Value New Value
Resolution Fixed [ 1 ]
Status Open [ 1 ] Resolved [ 5 ]
Fix Version/s 6.1.4rc0 [ 13515 ]
Bill Pugh added a comment - 04/Jun/07 11:18 AM

Forgot another occurrence:

M M DL: Synchronization on shared constant could deadlock in org.mortbay.jetty.security.Credential$MD5.digest(String) At Credential.java:[line 185]

The head version of FindBugs now looks for this bug pattern.