Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Sep 8, 2017
1 parent fa2c377 commit 17f42fc
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 24 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -232,6 +232,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
/**
* Return whether this a <b>Prototype</b>, with an independent instance
* returned for each call.
* @since 3.0
* @see #SCOPE_PROTOTYPE
*/
boolean isPrototype();
Expand Down
Expand Up @@ -366,7 +366,7 @@ public Object getObject() throws BeansException {
}

// Check if required type matches the type of the actual bean instance.
if (requiredType != null && bean != null && !requiredType.isAssignableFrom(bean.getClass())) {
if (requiredType != null && bean != null && !requiredType.isInstance(bean)) {
try {
return getTypeConverter().convertIfNecessary(bean, requiredType);
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -66,7 +66,9 @@ protected static List<Class<? extends Throwable>> getExceptionsFromMethodSignatu
result.add((Class<? extends Throwable>) paramType);
}
}
Assert.notEmpty(result, "No exception types mapped to {" + method + "}");
if (result.isEmpty()) {
throw new IllegalStateException("No exception types mapped to " + method);
}
return result;
}

Expand All @@ -75,7 +77,7 @@ protected static List<Class<? extends Throwable>> getExceptionsFromMethodSignatu
* Whether the contained type has any exception mappings.
*/
public boolean hasExceptionMappings() {
return (this.mappedMethods.size() > 0);
return !this.mappedMethods.isEmpty();
}

/**
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -94,7 +94,7 @@ public void ambiguousExceptionMapping() {
new AnnotationExceptionHandlerMethodResolver(AmbiguousController.class);
}

@Test(expected = IllegalArgumentException.class)
@Test(expected = IllegalStateException.class)
public void noExceptionMapping() {
new AnnotationExceptionHandlerMethodResolver(NoExceptionController.class);
}
Expand Down
Expand Up @@ -201,8 +201,8 @@ protected void doBind(MutablePropertyValues mpvs) {
* @see #getFieldDefaultPrefix
*/
protected void checkFieldDefaults(MutablePropertyValues mpvs) {
if (getFieldDefaultPrefix() != null) {
String fieldDefaultPrefix = getFieldDefaultPrefix();
String fieldDefaultPrefix = getFieldDefaultPrefix();
if (fieldDefaultPrefix != null) {
PropertyValue[] pvArray = mpvs.getPropertyValues();
for (PropertyValue pv : pvArray) {
if (pv.getName().startsWith(fieldDefaultPrefix)) {
Expand All @@ -228,8 +228,8 @@ protected void checkFieldDefaults(MutablePropertyValues mpvs) {
* @see #getEmptyValue(String, Class)
*/
protected void checkFieldMarkers(MutablePropertyValues mpvs) {
if (getFieldMarkerPrefix() != null) {
String fieldMarkerPrefix = getFieldMarkerPrefix();
String fieldMarkerPrefix = getFieldMarkerPrefix();
if (fieldMarkerPrefix != null) {
PropertyValue[] pvArray = mpvs.getPropertyValues();
for (PropertyValue pv : pvArray) {
if (pv.getName().startsWith(fieldMarkerPrefix)) {
Expand All @@ -246,7 +246,7 @@ protected void checkFieldMarkers(MutablePropertyValues mpvs) {

/**
* Determine an empty value for the specified field.
* <p>Default implementation returns:
* <p>The default implementation returns:
* <ul>
* <li>{@code Boolean.FALSE} for boolean fields
* <li>an empty array for array types
Expand Down Expand Up @@ -275,17 +275,20 @@ else if (Collection.class.isAssignableFrom(fieldType)) {
else if (Map.class.isAssignableFrom(fieldType)) {
return CollectionFactory.createMap(fieldType, 0);
}
} catch (IllegalArgumentException exc) {
return null;
}
catch (IllegalArgumentException ex) {
if (logger.isDebugEnabled()) {
logger.debug("Failed to create default value - falling back to null: " + ex.getMessage());
}
}
}
// Default value: try null.
// Default value: null.
return null;
}

/**
* Bind all multipart files contained in the given request, if any
* (in case of a multipart request).
* (in case of a multipart request). To be called by subclasses.
* <p>Multipart files will only be added to the property values if they
* are not empty or if we're configured to bind empty multipart files too.
* @param multipartFiles Map of field name String to MultipartFile object
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,7 +36,7 @@
* the Exception instance as the concurrent result. Such exceptions will then
* be processed through the {@code HandlerExceptionResolver} mechanism.
*
* <p>The {@link #handleTimeout(NativeWebRequest, Callable) afterTimeout} method
* <p>The {@link #handleTimeout(NativeWebRequest, Callable) handleTimeout} method
* can select a value to be used to resume processing.
*
* @author Rossen Stoyanchev
Expand All @@ -45,9 +45,20 @@
*/
public interface CallableProcessingInterceptor {

static final Object RESULT_NONE = new Object();
/**
* Constant indicating that no result has been determined by this
* interceptor, giving subsequent interceptors a chance.
* @see #handleTimeout
*/
Object RESULT_NONE = new Object();

/**
* Constant indicating that the response has been handled by this interceptor
* without a result and that no further interceptors are to be invoked.
* @see #handleTimeout
*/
Object RESPONSE_HANDLED = new Object();

static final Object RESPONSE_HANDLED = new Object();

/**
* Invoked <em>before</em> the start of concurrent handling in the original
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -94,7 +94,9 @@ private List<Class<? extends Throwable>> detectExceptionMappings(Method method)
}
}
}
Assert.notEmpty(result, "No exception types mapped to {" + method + "}");
if (result.isEmpty()) {
throw new IllegalStateException("No exception types mapped to " + method);
}
return result;
}

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -88,11 +88,12 @@ public void ambiguousExceptionMapping() {
new ExceptionHandlerMethodResolver(AmbiguousController.class);
}

@Test(expected = IllegalArgumentException.class)
@Test(expected = IllegalStateException.class)
public void noExceptionMapping() {
new ExceptionHandlerMethodResolver(NoExceptionController.class);
}


@Controller
static class ExceptionController {

Expand All @@ -111,6 +112,7 @@ public void handleIllegalArgumentException(IllegalArgumentException exception) {
}
}


@Controller
static class InheritedController extends ExceptionController {

Expand All @@ -119,6 +121,7 @@ public void handleIOException() {
}
}


@Controller
static class AmbiguousController {

Expand All @@ -136,6 +139,7 @@ public String handle2(IllegalArgumentException ex) {
}
}


@Controller
static class NoExceptionController {

Expand Down

0 comments on commit 17f42fc

Please sign in to comment.