Daniel Pitts wrote:
Andreas Leitgeb wrote:
Daniel Pitts <newsgroup.spamfilter@virtualinfinity.net> wrote:
assert null == matesMap.put(a, b);
assert null == matesMap.put(b, a);
Ouch. Lew already pointed out this utterly flawed
use of assert.
double ouch, yes. First, I didn't see Lews post.
Second, that use of assert is very broken, and my bad!
it should be
if (null != matesMap.put(a, b)) throw new RuntimeException("FAIL!");
if (null != matesMap.put(b, a)) throw new RuntimeException("FAIL!");
... but these tests can't be enabled and disabled the way
assert statements can. Perhaps a variation on
Thing ax = matesMap.put(a, b);
Thing bx = matesMap.put(b, a);
assert ax == null && bx == null : "FAIL!";
.... would be preferable? Yes, it introduces two variables whose
only purpose is to allow the subsequent assert, and in some cases
that could be burdensome. But it puts the testing back into the
assertion framework, with its controls, and that seems a Good Thing.
disabled would be preferable in this case.