InvalidArgumentException is preferable to NPE in these cases.