Skip to content

Commit

Permalink
Fixing NPE in AbstractNamedValueMethodArgumentResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
dekelpilli authored and rstoyanchev committed Oct 31, 2019
1 parent fd96788 commit 64f2beb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ public void resolveOptionalHeaderWithValue() throws Exception {
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();
Expand Down

0 comments on commit 64f2beb

Please sign in to comment.