@ -18,6 +18,7 @@ package org.springframework.boot.bind;
import java.net.InetAddress ;
import java.net.InetAddress ;
import java.util.ArrayList ;
import java.util.ArrayList ;
import java.util.Arrays ;
import java.util.Collection ;
import java.util.Collection ;
import java.util.Collections ;
import java.util.Collections ;
import java.util.HashSet ;
import java.util.HashSet ;
@ -35,6 +36,7 @@ import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.NotWritablePropertyException ;
import org.springframework.beans.NotWritablePropertyException ;
import org.springframework.beans.PropertyValue ;
import org.springframework.beans.PropertyValue ;
import org.springframework.core.convert.TypeDescriptor ;
import org.springframework.core.convert.TypeDescriptor ;
import org.springframework.core.env.StandardEnvironment ;
import org.springframework.util.LinkedMultiValueMap ;
import org.springframework.util.LinkedMultiValueMap ;
import org.springframework.util.MultiValueMap ;
import org.springframework.util.MultiValueMap ;
import org.springframework.util.StringUtils ;
import org.springframework.util.StringUtils ;
@ -54,6 +56,11 @@ import org.springframework.validation.DataBinder;
* /
* /
public class RelaxedDataBinder extends DataBinder {
public class RelaxedDataBinder extends DataBinder {
private static final Set < String > BENIGN_PROPERTY_SOURCE_NAMES = Collections
. unmodifiableSet ( new HashSet < String > ( Arrays . asList (
StandardEnvironment . SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME ,
StandardEnvironment . SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME ) ) ) ;
private static final Object BLANK = new Object ( ) ;
private static final Object BLANK = new Object ( ) ;
private String namePrefix ;
private String namePrefix ;
@ -254,13 +261,21 @@ public class RelaxedDataBinder extends DataBinder {
}
}
catch ( NotWritablePropertyException ex ) {
catch ( NotWritablePropertyException ex ) {
PropertyOrigin origin = findPropertyOrigin ( pv ) ;
PropertyOrigin origin = findPropertyOrigin ( pv ) ;
if ( isFatal ( origin ) ) {
if ( origin ! = null ) {
if ( origin ! = null ) {
throw new RelaxedBindingNotWritablePropertyException ( ex ,
throw new RelaxedBindingNotWritablePropertyException (
origin ) ;
ex , origin ) ;
}
}
else {
throw ex ;
throw ex ;
}
}
}
}
else {
logger . debug ( "Ignoring benign property binding failure" ,
ex ) ;
}
}
}
} ;
} ;
beanWrapper . setConversionService ( new RelaxedConversionService (
beanWrapper . setConversionService ( new RelaxedConversionService (
getConversionService ( ) ) ) ;
getConversionService ( ) ) ) ;
@ -271,6 +286,13 @@ public class RelaxedDataBinder extends DataBinder {
} ;
} ;
}
}
private boolean isFatal ( PropertyOrigin origin ) {
if ( origin = = null ) {
return true ;
}
return ! BENIGN_PROPERTY_SOURCE_NAMES . contains ( origin . getSource ( ) . getName ( ) ) ;
}
private PropertyOrigin findPropertyOrigin ( PropertyValue propertyValue ) {
private PropertyOrigin findPropertyOrigin ( PropertyValue propertyValue ) {
if ( propertyValue instanceof OriginCapablePropertyValue ) {
if ( propertyValue instanceof OriginCapablePropertyValue ) {
return ( ( OriginCapablePropertyValue ) propertyValue ) . getOrigin ( ) ;
return ( ( OriginCapablePropertyValue ) propertyValue ) . getOrigin ( ) ;