提交 64f2beb9 编写于 作者: D Dekel Pilli 提交者: Rossen Stoyanchev

Fixing NPE in AbstractNamedValueMethodArgumentResolver

See gh-23882
上级 fd967883
......@@ -26,6 +26,7 @@ import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.core.MethodParameter;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.handler.annotation.ValueConstants;
......@@ -72,10 +73,10 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
* @param beanFactory a bean factory for resolving {@code ${...}}
* placeholders and {@code #{...}} SpEL expressions in default values
*/
protected AbstractNamedValueMethodArgumentResolver(ConversionService conversionService,
protected AbstractNamedValueMethodArgumentResolver(@Nullable ConversionService conversionService,
@Nullable ConfigurableBeanFactory beanFactory) {
this.conversionService = conversionService;
this.conversionService = conversionService != null ? conversionService : DefaultConversionService.getSharedInstance();
this.configurableBeanFactory = beanFactory;
this.expressionContext = (beanFactory != null ? new BeanExpressionContext(beanFactory, null) : null);
}
......
......@@ -41,7 +41,7 @@ public class DestinationVariableMethodArgumentResolver extends AbstractNamedValu
DestinationVariableMethodArgumentResolver.class.getSimpleName() + ".templateVariables";
public DestinationVariableMethodArgumentResolver(ConversionService conversionService) {
public DestinationVariableMethodArgumentResolver(@Nullable ConversionService conversionService) {
super(conversionService, null);
}
......
......@@ -49,7 +49,7 @@ public class HeaderMethodArgumentResolver extends AbstractNamedValueMethodArgume
public HeaderMethodArgumentResolver(
ConversionService conversionService, @Nullable ConfigurableBeanFactory beanFactory) {
@Nullable ConversionService conversionService, @Nullable ConfigurableBeanFactory beanFactory) {
super(conversionService, beanFactory);
}
......
......@@ -145,6 +145,14 @@ public class HeaderMethodArgumentResolverTests {
assertThat(result).isEqualTo(Optional.of("bar"));
}
@Test
public void resolveOptionalHeaderWithValueFromNullConversionServiceInput() throws Exception {
GenericApplicationContext context = new GenericApplicationContext();
context.refresh();
resolver = new HeaderMethodArgumentResolver(null, context.getBeanFactory());
resolveOptionalHeaderWithValue();
}
@Test
public void resolveOptionalHeaderAsEmpty() throws Exception {
Message<String> message = MessageBuilder.withPayload("foo").build();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册