@SuppressWarnings("serial")
public class NullParameter extends AbstractParameter implements Serializable {
/**
* The one and only instance of null parameter.
*/
public static final NullParameter INSTANCE = new NullParameter();
/**
* Only once instance of Null parameter needed.
*/
protected NullParameter() {
}
/**
* {@inheritDoc}
* @see org.picocontainer.Parameter#accept(org.picocontainer.PicoVisitor)
*/
public void accept(PicoVisitor visitor) {
visitor.visitParameter(this);
}
/**
* {@inheritDoc}
* @see org.picocontainer.Parameter#resolve(org.picocontainer.PicoContainer, org.picocontainer.ComponentAdapter, org.picocontainer.ComponentAdapter, java.lang.reflect.Type, org.picocontainer.NameBinding, boolean, java.lang.annotation.Annotation)
*/
public Resolver resolve(PicoContainer container,
ComponentAdapter<?> forAdapter,
ComponentAdapter<?> injecteeAdapter, Type expectedType,
NameBinding expectedNameBinding, boolean useNames,
Annotation binding) {
return new ValueResolver(isAssignable(expectedType), null, null);
}
/**
* {@inheritDoc}
* @see org.picocontainer.Parameter#verify(org.picocontainer.PicoContainer, org.picocontainer.ComponentAdapter, java.lang.reflect.Type, org.picocontainer.NameBinding, boolean, java.lang.annotation.Annotation)
*/
public void verify(PicoContainer container, ComponentAdapter<?> adapter,
Type expectedType, NameBinding expectedNameBinding,
boolean useNames, Annotation binding) {
if (!isAssignable(expectedType)) {
throw new PicoCompositionException(expectedType + " cannot be assigned a null value");
}
}
/**
* Nulls cannot be assigned to primitives.
* @param expectedType
* @return
*/
protected boolean isAssignable(Type expectedType) {
if (expectedType instanceof Class<?>) {
Class<?> expectedClass = Class.class.cast(expectedType);
if (expectedClass.isPrimitive()) {
return false;
}
}
return true;
}
}
Initial attempt at fixing:
With test case:
Failure for new case is:
This is due to SingleMemberInjector.isNullParamAllowed();