05.10.09
Paranoid code
I’ve been wrestling with some legacy Java ME code in which the author doesn’t seem to have grasped the “do or throw” pattern.
That is, a method either returns a valid object OR throws a exception. You do not need to check the return value of a method satisfying this criterion as it can never be null.
e.g:
Thread t = Thread.currentThread();
if ( t != null )
t.sleep( seconds * 1000L );
That could be simplified to just:
Thread.sleep(seconds * 1000L);
There’s something existential about code that wonders if it’s the current running thread.
