lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dawid Weiss <>
Subject Re: com.carrotsearch.randomizedtesting.NotAnException
Date Sun, 15 Jul 2012 13:33:34 GMT
> That's just a little funny.

Yup. Check out the javadoc:
 * This is never thrown. The only purpose it serves it to carry
chained stack traces
 * for informational purposes.
final class NotAnException extends Throwable {

Suggestions on how it could be called better welcome...

> java.lang.IllegalStateException: This Random was created for/by another thread (Thread[[2EDBF53611C44F4C],5,]).
Random instances must not be shared (acquire per-thread). Current thread: Thread[Thread-52,5,]

Yes, this is caused by passing Random across threads. If you do this,
it'll cause races for values and make the test evel less reproducible
than it is. There are two solutions:

1) call LTC.random() instead of storing Random in a field (or passing
it down to a subthread); this method creates per-thread random
instances so every thread has its own random sequence.

2) if the above is not possible for some reason you can wrap with a
non-asserting regular Random and share it (not a good idea though):
new Random(random().nextLong()).

> I'll look into it. But you've got to love an Exception called NotAnException.

It's because it's not. It's never thrown from the code and is only
used to provide a stack trace of where the random was allocated, as
the message says. While this may be confusing it help in IDEs a lot
because you can click directly on t he stack trace frames instead of
searching manually for a particular place in the code.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message