Nullability fine-tuning around bean properties

Issue: SPR-15720
Issue: SPR-15792
This commit is contained in:
Juergen Hoeller
2017-07-19 11:43:58 +02:00
parent 06fc092be2
commit 9fc4fb10b0
31 changed files with 243 additions and 206 deletions

View File

@@ -54,6 +54,7 @@ public abstract class AbstractHttpMessageConverter<T> implements HttpMessageConv
private List<MediaType> supportedMediaTypes = Collections.emptyList();
@Nullable
private Charset defaultCharset;

View File

@@ -75,8 +75,10 @@ public class WebDataBinder extends DataBinder {
*/
public static final String DEFAULT_FIELD_DEFAULT_PREFIX = "!";
@Nullable
private String fieldMarkerPrefix = DEFAULT_FIELD_MARKER_PREFIX;
@Nullable
private String fieldDefaultPrefix = DEFAULT_FIELD_DEFAULT_PREFIX;
private boolean bindEmptyMultipartFiles = true;
@@ -124,13 +126,14 @@ public class WebDataBinder extends DataBinder {
* detect an empty field and automatically reset its value.
* @see #DEFAULT_FIELD_MARKER_PREFIX
*/
public void setFieldMarkerPrefix(String fieldMarkerPrefix) {
public void setFieldMarkerPrefix(@Nullable String fieldMarkerPrefix) {
this.fieldMarkerPrefix = fieldMarkerPrefix;
}
/**
* Return the prefix for parameters that mark potentially empty fields.
*/
@Nullable
public String getFieldMarkerPrefix() {
return this.fieldMarkerPrefix;
}
@@ -149,13 +152,14 @@ public class WebDataBinder extends DataBinder {
* marker for the given field.
* @see #DEFAULT_FIELD_DEFAULT_PREFIX
*/
public void setFieldDefaultPrefix(String fieldDefaultPrefix) {
public void setFieldDefaultPrefix(@Nullable String fieldDefaultPrefix) {
this.fieldDefaultPrefix = fieldDefaultPrefix;
}
/**
* Return the prefix for parameters that mark default fields.
*/
@Nullable
public String getFieldDefaultPrefix() {
return this.fieldDefaultPrefix;
}

View File

@@ -117,7 +117,7 @@ public abstract class AbstractRefreshableWebApplicationContext extends AbstractR
@Override
public void setServletConfig(@Nullable ServletConfig servletConfig) {
this.servletConfig = servletConfig;
if (this.servletContext == null) {
if (servletConfig != null && this.servletContext == null) {
setServletContext(servletConfig.getServletContext());
}
}
@@ -131,7 +131,9 @@ public abstract class AbstractRefreshableWebApplicationContext extends AbstractR
@Override
public void setNamespace(@Nullable String namespace) {
this.namespace = namespace;
setDisplayName(namespace != null ? "WebApplicationContext for namespace '" + namespace + "'" : null);
if (namespace != null) {
setDisplayName("WebApplicationContext for namespace '" + namespace + "'");
}
}
@Override

View File

@@ -93,7 +93,7 @@ public class StaticWebApplicationContext extends StaticApplicationContext
@Override
public void setServletConfig(@Nullable ServletConfig servletConfig) {
this.servletConfig = servletConfig;
if (this.servletContext == null) {
if (servletConfig != null && this.servletContext == null) {
this.servletContext = servletConfig.getServletContext();
}
}
@@ -107,7 +107,9 @@ public class StaticWebApplicationContext extends StaticApplicationContext
@Override
public void setNamespace(@Nullable String namespace) {
this.namespace = namespace;
setDisplayName(namespace != null ? "WebApplicationContext for namespace '" + namespace + "'" : null);
if (namespace != null) {
setDisplayName("WebApplicationContext for namespace '" + namespace + "'");
}
}
@Override