Skip to content

AbstractMessageSource does not properly interact with DelegatingMessageSource parent [SPR-16047] #20596

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
spring-projects-issues opened this issue Oct 5, 2017 · 2 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: regression A bug that is also a regression
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Oct 5, 2017

Hans Desmet opened SPR-16047 and commented

Given following Initializer:

package be.vdab.web;

import javax.servlet.Filter;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
import be.vdab.test.TestConfig;


public class Initializer extends AbstractAnnotationConfigDispatcherServletInitializer {
	@Override
	protected String[] getServletMappings() {
		return new String[] { "/" };
	}

	@Override
	protected Class<?>[] getRootConfigClasses() {
		return new Class<?>[] { TestConfig.class };
		//return null;
	}

	@Override
	protected Class<?>[] getServletConfigClasses() {
		return new Class<?>[] { ControllersConfig.class };
	}

	@Override
	protected Filter[] getServletFilters() {
		return new Filter[] { new CharacterEncodingFilter("UTF-8") };
	}
}

and following Controllers config:

package be.vdab.web;

import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
@EnableWebMvc
@ComponentScan
public class ControllersConfig extends WebMvcConfigurerAdapter {

	@Bean
	MessageSource messageSource() {
		ReloadableResourceBundleMessageSource source = new ReloadableResourceBundleMessageSource();
		source.setBasename("classpath:messages");
		source.setFallbackToSystemLocale(false);
		return source;
	}
}

and following Java config

package be.vdab.test;

import org.springframework.context.annotation.Configuration;

@Configuration
public class TestConfig {

}

and following controller:

package be.vdab.web;

import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.DataBinder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/")
class IndexController {

	private static final String VIEW = "/WEB-INF/JSP/index.jsp";

	@GetMapping
	ModelAndView findByPostcodeReeks() {
		CommandObject reeks = new CommandObject();
		return new ModelAndView(VIEW).addObject(reeks);
	}

	@GetMapping(params = { "value" })
	ModelAndView findByPostcodeReeks(CommandObject reeks, BindingResult bindingResult) {
		ModelAndView modelAndView = new ModelAndView(VIEW);
		return modelAndView;
	}

	@InitBinder("commandObject")
	void initBinderPostcodeReeks(DataBinder dataBinder) {
		dataBinder.setRequiredFields("value");
	}
}

and following Command object class

package be.vdab.web;

public class CommandObject {
	private String value;
	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}
}

and following index.jsp

<%@page contentType='text/html' pageEncoding='UTF-8' session='false'%>
<%@taglib prefix='form' uri='http://www.springframework.org/tags/form'%> 
<!doctype html>
<html lang='nl'>
<head>
<title>
Test
</title>
</head>
<body>
<h1>Test</h1>
<form:form action='' modelAttribute='commandObject' method='get'>
<form:input path='value' autofocus='autofocus'/> 
<form:errors path='value'/> 
 <input type='submit' value='Zoeken'> 
</form:form>
</body>
</html>

when you run the webapp, leave the field empty and submit the form, you don't see the error message.
The problem is solved in three different ways:

  1. comment the MessageSource bean in ControllersConfig
  2. comment the line
    return new Class<?>[] { TestConfig.class }; in Initialzer and uncomment the line return null;
  3. Downgrade the webapp to Spring 4.3.11

A project to show the problem is at https://github.com/desmethans/formerrorstag.git


Affects: 5.0 GA

Reference URL: https://github.com/desmethans/formerrorstag.git

Issue Links:

Referenced from: commits c3378fd

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Oct 18, 2017

Juergen Hoeller commented

This comes down to our nullability revision (#20099) in AbstractMessageSource: getMessageFromParent does not properly interact with a DelegatingMessageSource parent anymore. We'll fix this for 5.0.1.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

This will be available in the upcoming 5.0.1.BUILD-SNAPSHOT. Feel free to give it a try...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

2 participants