Skip to content

Fixing NPE in AbstractNamedValueMethodArgumentResolver #23882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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