Originally posted by Michal Charemza:
I was considering making a similar assertCurrentThreadOwnsLock method.
from my POV an assertion (std. java assertion or own assertXY method) should be used in order to be sure that necessary preconditions that you do expect to have met by surrounding/using code actually are.
hummm. strange sentence
i mean... i use assertions where i am kind of sure that things MUST (or CANNOT) happen unless programming errors.
example:
is supposed to be ok whereas
is not. as assertions can be turned off a client of this class may not be aware of a misuse/broken contract of this method then.
the main difference though between your selfmade assertion-method and the assert keyword (i suppose) is that it cannot (and maybe should not) be turned off.
so if you�re unsure about the name, i would just call it
"enforceCurrentThreadOwnsLock" no matter what kind of exception is/can be thrown.