osundblad / intellij-annotations-instrumenter-maven-plugin

IntelliJ IDEA annotations instrumenter maven plugin
Other
38 stars 11 forks source link

Allow a configurable Exception to be thrown upon detecting that an invariant does not hold #53

Open minborg opened 3 years ago

minborg commented 3 years ago

If, for example, a method with a @NotNull parameter is invoked with null (despite the contract), I would expect that method to throw NullPointerException rather than an IllegalArgumentException. This would better mimic the customary use of Objects::requireNonNull null invariant assertion and would allow the removal of all these calls with no impact on production and test code.

Thus, it would be advantageous to be able to set the type of exception thrown. Preferably as a Maven configuration property. If a general exception supplier setting is not easy to do, then at least a <useNullPointerException>true</useNullPointerException> could be considered.

See ThrowOnNullMethodVisitor.IAE_CLASS_NAME