]
Adrian Brock updated JBAS-5564:
-------------------------------
Component/s: (was: MicroContainer bus)
Affects Version/s: (was: JBossAS-5.0.0.Beta3)
Assignee: (was: Alexey Loubyansky)
Probable logical problem in NonReentrantLock
--------------------------------------------
Key: JBAS-5564
URL:
http://jira.jboss.com/jira/browse/JBAS-5564
Project: JBoss Application Server
Issue Type: Bug
Security Level: Public(Everyone can see)
Components: EJB2
Affects Versions: JBossAS-5.0.0.Beta4, JBossAS-4.2.2.GA
Environment: None, source code analysis
Reporter: Domagoj Cosic
Introduction: My direct problem is distantly related to JBAS-4177. The difference is, I
use an own implementation of a BeanLock, which is so far correct an not an issue in this
ticket, nor is the my original problem that the NonReentrantLock causes. However, my
original problem led me to NonReentrantLock and I analyzed its source code in some depth.
I have a suspicion that there is a serious bug in it.
The problem I want to point at is in the line 143:
Up to the trunk revision there stands:
if(lockHolder != curThread && (miTx == null || miTx.equals(holdingTx)))
There is some contradiction to the description:
"It will throw a ReentranceException if the same thread tries to acquire twice
or the same transaction tries to acquire twice"
For a non re-entrant bean it means, in pseudo code:
if (sameThread or sameTransaction) {
throw new ReentrantException();
} else {
waitForOtherThreadOrTransaction;
on timeout return false;
return true;
}
This description does not apply to an re-entrant bean, but for re-entrant bean it
basically means (in pseudo code):
if (sameThread or sameTransaction) {
return true;
} else {
waitForOtherThreadOrTransaction;
on timeout return false;
return true;
}
I backtracked the code to the previous change, which was revision 16662 dated 27.08.2003
There it stands:
if (lockHolder == Thread.currentThread()) throw new ReentranceException();
if (miTx != null && miTx.equals(holdingTx)) throw new
ReentranceException();
Although this code was for the non re-eantrant case, for the re-entrant case the code
should return true for those cases, where ReentrantException was thrown.
Let us transform this code step by step:
Step 1:
if (lockHolder == Thread.currentThread()) return true;
if (miTx != null && miTx.equals(holdingTx)) return true;
Step 2:
if (lockHolder == Thread.currentThread() || miTx != null &&
miTx.equals(holdingTx)) {
return true;
} else {
wait;
return true;
}
Step 3 (negating):
if (lockHolder != Thread.currentThread() && (miTx == null ||
!miTx.equals(holdingTx))) {
wait;
return true;
} else {
return true;
}
You see the difference? Current code lacks "!" before miTx.equals(holdingTx).
It seems wrong to me and it causes a problem for me, so it would be nice if someone else
takes a look at this.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: