I want to check preconditions on a base class so that I know subtypes will always use constructor arguments that are valid.
Let\'s take as an example a constructor that:
This should have been a comment, but it's too long.
super
before the test is harmless provided that the super ctor doesn't do things which it shouldn't do anyway.More important: The exceptions you're throwing are probably inferior to the ones you'd get without all the checks. Imagine the user provides a cause and no message. That's bad, you think, but you replace it with an NPE lacking any cause. That's worse.
Look at Guava's Preconditions.format
(package private). They could check the correct number of arguments first, but they do not. You can provide too few or too many, which is an error, but ignoring it is the best way to handle it.