When the ParameterResolver's supports() and resolve() methods were changed to use ParameterContext, the statement that the Parameter was never null was replaced by text that stated ParamterResolver is never null. ParameterResolver itself makes no assertion that getParameter() always returns a non-null value. Thus, I'm now checking for null parameters as follows:
boolean supported = false;
Parameter parameter = parameterContext.getParameter();
if (parameter != null && Performance.class.equals(parameter.getType())) {
supported = true;
}
return supported;
For the ParameterContext, it wouldn't make sense to ever have a non-null parameter (otherwise it would be a SomethingElseContext), so this code is probably completely unnecessary. As a defensive coder, I put it in anyway. Here are my recommendations in order of priority/complexity:
I know the JUnit team's policy on avoiding dependencies - adding JSR-305 as provided allows those of us who chose to perform static analysis on our Engine, Extension and test code to choose to add the dependency to our classpath.
Related Resources
When the
ParameterResolver'ssupports()andresolve()methods were changed to useParameterContext, the statement that theParameterwas nevernullwas replaced by text that statedParamterResolveris never null.ParameterResolveritself makes no assertion that getParameter() always returns a non-null value. Thus, I'm now checking for null parameters as follows:For the
ParameterContext, it wouldn't make sense to ever have a non-null parameter (otherwise it would be aSomethingElseContext), so this code is probably completely unnecessary. As a defensive coder, I put it in anyway. Here are my recommendations in order of priority/complexity:Optionalwhen a return type might benull.null.@CheckForNull,@Nonnulland@Nullableto all public APIs.I know the JUnit team's policy on avoiding dependencies - adding JSR-305 as provided allows those of us who chose to perform static analysis on our Engine, Extension and test code to choose to add the dependency to our classpath.
Related Resources