Fix bug in PlaceholderTargetSource for null values
This commit is contained in:
@@ -177,7 +177,7 @@ public class PlaceholderTargetSource extends SimpleBeanTargetSource implements I
|
||||
BeanWrapper wrapper = new BeanWrapperImpl(contextFactory.getContext());
|
||||
if (wrapper.isReadableProperty(key)) {
|
||||
Object property = wrapper.getPropertyValue(key);
|
||||
if (requiredType.isAssignableFrom(property.getClass())) {
|
||||
if (property==null || requiredType.isAssignableFrom(property.getClass())) {
|
||||
result = property;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,10 @@ public class PlaceholderTargetSourceTests extends ContextFactorySupport {
|
||||
@Qualifier("withDate")
|
||||
private PlaceholderTargetSource withDate;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("withNull")
|
||||
private PlaceholderTargetSource withNull;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("compound")
|
||||
private PlaceholderTargetSource compound;
|
||||
@@ -82,6 +86,10 @@ public class PlaceholderTargetSourceTests extends ContextFactorySupport {
|
||||
return date;
|
||||
}
|
||||
|
||||
public String getGarbage() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAfterPropertiesSet() throws Exception {
|
||||
PlaceholderTargetSource targetSource = new PlaceholderTargetSource();
|
||||
@@ -143,6 +151,13 @@ public class PlaceholderTargetSourceTests extends ContextFactorySupport {
|
||||
assertEquals("bar-#{date}", target.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNull() {
|
||||
Node target = (Node) withNull.getTarget();
|
||||
// Remains unconverted because null is explicitly excluded
|
||||
assertEquals("bar-#{garbage}", target.getName());
|
||||
}
|
||||
|
||||
public static interface Node {
|
||||
String getName();
|
||||
|
||||
|
||||
@@ -104,6 +104,18 @@
|
||||
<property name="name" value="bar-#{date}" />
|
||||
</bean>
|
||||
|
||||
<bean id="withNull"
|
||||
class="org.springframework.batch.core.scope.util.PlaceholderTargetSource">
|
||||
<property name="contextFactory" ref="context" />
|
||||
<property name="targetBeanName" value="withNullTarget" />
|
||||
</bean>
|
||||
|
||||
<bean id="withNullTarget"
|
||||
class="org.springframework.batch.core.scope.util.PlaceholderTargetSourceTests$Foo"
|
||||
lazy-init="true">
|
||||
<property name="name" value="bar-#{garbage}" />
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.beans.factory.config.CustomEditorConfigurer">
|
||||
<property name="customEditors">
|
||||
<map>
|
||||
|
||||
Reference in New Issue
Block a user