The fact that you throw the NPE yourself means that it is an expected
Exception.
If you read EnforcerRuleException as "an/any Exception in this
EnforcerRule", it is valid for me to throw this kind of Exception,
although I can imagine the doubt.
If you don't want to use the ERE, then create a new RuntimeException,
matching the real issue, like MissingParentException. I agree with several
code quality checkers that you should avoid to throw NPEs yourself.
Robert
On Tue, 14 May 2013 09:26:48 +0200, Michael Koch <[email protected]>
wrote:
Throwing a NPE yourself? There must be a better solution....
+
+ // fail fast if the defining parent could not be found due to
a bug in the rule
+ if ( parent == null )
+ {
+ throw new NullPointerException( "failed to find parent
POM which defines the current rule" );
+ }
This code is originally from me, so I'll explain. If the rule fails to
find the parent this is due to an error in the rule code. The explicit
check makes it easier to diagnose. Without it, a NPE will be thrown
later when the parent value is needed. This is not always the case:
without the explicit check the plugin execution will succeed when used
in the parent POM, but fail with a NPE in the child POM which inherits
the configuration.
It is debatable whether NullPointerException is a good choice, but I
think none of the other standard RuntimeExceptions are a better fit. I
also didn't want to use EnforcerRuleException, because the NPE is an
internal error, not an expected result of the rule configuration /
execution.
Cheers
Michael Koch
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email