Issue 1:
Oleg Soloviov opened SPR-5528 and commented

You do some entries into the HTML form

submits the form

you do some changes to the form's entries on the server side

the changes are not displayed to the user, old entries remind in the form

Probably the bug is here:

in the Constructor of the org.springframework.web.servlet.support.BindStatus

it is

=>

...

this.errors = requestContext.getErrors(beanName, false);

if (this.errors != null) {

...

} else {

...

}

=>

the requestContext.getErrors returns errors Object that is not null but empty so (this.errors.hasErrors() is false)

the else block is NEVER EXECUTED !!!

The solution could be:

=>

if (this.errors != null && this.errors.hasErrors()) {

...

} else {

...

}

=>

Affects: 2.5.6

Issue Links:

#10212 MVC BindStatus does not interact with Web Flow's BindingModel ("duplicates")

Issue 2:
Magnus Heino opened SPR-1047 and commented

Bean definitions are required to provide a value for bean attributes defined as required using jdk1.5 annotation.

This provides a check to validate that values are not "forgotten" when creating new bean definitions. Values that are not properly set in the bean definition and are not be used immediately after bean instantiation will not be found otherwise.

package se.lantmateriet.jollen.bryggan.support;

import java.lang.annotation.Documented;

import java.lang.annotation.ElementType;

import java.lang.annotation.Retention;

import java.lang.annotation.RetentionPolicy;

import java.lang.annotation.Target;

/**

JDK 1.5+ method-level annotation that indicates that the value

is required to be non-null.

@author Magnus Heino

*/

@Target(ElementType.FIELD)

@Retention(RetentionPolicy.RUNTIME)

@Documented

public @interface RequiredAttribute {

}

/**

*

*/

package se.lantmateriet.jollen.bryggan.support;

import java.lang.reflect.Field;

import org.springframework.beans.BeansException;

import org.springframework.beans.MutablePropertyValues;

import org.springframework.beans.factory.config.BeanDefinition;

import org.springframework.beans.factory.config.BeanFactoryPostProcessor;

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;

import org.springframework.beans.factory.support.BeanDefinitionValidationException;

/**

@author maghei

*/

public class RequiredAttributeValidator implements BeanFactoryPostProcessor {

/* (non-Javadoc)
* @see org.springframework.beans.factory.config.BeanFactoryPostProcessor#postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)
*/
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

for(String beanName: beanFactory.getBeanDefinitionNames()) {
BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);

if(beanDefinition.isAbstract()) {
continue;
}

MutablePropertyValues beanProperties = beanDefinition.getPropertyValues();

for(Field field: beanFactory.getType(beanName).getDeclaredFields()) {
RequiredAttribute requiredAttribute = field.getAnnotation(RequiredAttribute.class);
if(requiredAttribute != null) {
Object value = beanProperties.getPropertyValue(field.getName());
if(value == null) {
throw new BeanDefinitionValidationException("Required attribute '" + field.getName() + "' of class '" + beanDefinition.getClass().getName() + "' defined in bean '" + beanName + "' in file '" + beanDefinition.getResourceDescription() + "' is null.");
}
}
}

}

}

}

Attachments:

RequiredPropertyValidator.java (9.67 kB)

RequiredPropertyValidator.java (8.82 kB)

Issue Links:

#6119 Annotations for dependency checking ("is duplicated by")