WW-4360: Fix a few NullPointerExceptions identified by Eclipse #15 

Eclipse's static analysis of nulls identifies a number of spots where a NullPointerException can occur. This change fixes them either to rearrange things so they can't happen or to throw a more specific exception.