Package org.springframework.web.method.annotation

# Class HandlerMethodValidationException

java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
org.springframework.core.NestedRuntimeException
org.springframework.web.ErrorResponseException
org.springframework.web.server.ResponseStatusException
org.springframework.web.method.annotation.HandlerMethodValidationException

All Implemented Interfaces:
  `Serializable`, `org.springframework.validation.method.MethodValidationResult`, `ErrorResponse`

public class HandlerMethodValidationException extends ResponseStatusException implements org.springframework.validation.method.MethodValidationResult
`ResponseStatusException` that is also `MethodValidationResult`. Raised by `HandlerMethodValidator` in case of method validation errors on a web controller method.

The `ErrorResponseException.getStatusCode()` is 400 for input validation errors, and 500 for validation errors on a return value.

Since:
  6.1
Author:
  Rossen Stoyanchev
See Also:
  - Serialized Form

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static interface`
`HandlerMethodValidationException.Visitor`
Contract to handle validation results with callbacks by controller method parameter type, with `HandlerMethodValidationException.Visitor.other(org.springframework.validation.method.ParameterValidationResult)` serving as the fallthrough.

## Nested classes/interfaces inherited from interface org.springframework.web.ErrorResponse

`ErrorResponse.Builder, ErrorResponse.Interceptor`

## Constructor Summary

Constructors
Constructor
Description
`HandlerMethodValidationException(org.springframework.validation.method.MethodValidationResult validationResult)`
`HandlerMethodValidationException(org.springframework.validation.method.MethodValidationResult validationResult, Predicate<org.springframework.core.MethodParameter> modelAttributePredicate, Predicate<org.springframework.core.MethodParameter> requestParamPredicate)`

## Method Summary

Modifier and Type
Method
Description
`List<org.springframework.context.MessageSourceResolvable>`
`getCrossParameterValidationResults()`
`Object[]`
`getDetailMessageArguments()`
Return arguments to use along with a `message code` to resolve the problem "detail" for this exception through a `MessageSource`.
`Object[]`
`getDetailMessageArguments(org.springframework.context.MessageSource messageSource, Locale locale)`
Variant of `ErrorResponse.getDetailMessageArguments()` that uses the given `MessageSource` for resolving the message argument values.
`Method`
`getMethod()`
`List<org.springframework.validation.method.ParameterValidationResult>`
`getParameterValidationResults()`
`Object`
`getTarget()`
`boolean`
`isForReturnValue()`
`void`
`visitResults(HandlerMethodValidationException.Visitor visitor)`
Provide a `Visitor` to handle `ParameterValidationResult`s through callback methods organized by controller method parameter type.

### Methods inherited from class org.springframework.web.server.ResponseStatusException

`getHeaders, getMessage, getReason, getResponseHeaders, updateAndGetBody`

### Methods inherited from class org.springframework.web.ErrorResponseException

`getBody, getDetailMessageCode, getStatusCode, setDetail, setInstance, setTitle, setType`

### Methods inherited from class org.springframework.core.NestedRuntimeException

`contains, getMostSpecificCause, getRootCause`

### Methods inherited from class java.lang.Throwable

`addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface org.springframework.web.ErrorResponse

`getTitleMessageCode, getTypeMessageCode`

### Methods inherited from interface org.springframework.validation.method.MethodValidationResult

`getAllErrors, getAllValidationResults, getBeanResults, getValueResults, hasErrors`

## Constructor Details

### HandlerMethodValidationException

public HandlerMethodValidationException(org.springframework.validation.method.MethodValidationResult validationResult)

### HandlerMethodValidationException

public HandlerMethodValidationException(org.springframework.validation.method.MethodValidationResult validationResult, Predicate<org.springframework.core.MethodParameter> modelAttributePredicate, Predicate<org.springframework.core.MethodParameter> requestParamPredicate)

## Method Details

### getDetailMessageArguments

public Object[] getDetailMessageArguments(org.springframework.context.MessageSource messageSource, Locale locale)
Description copied from interface: `ErrorResponse`
Variant of `ErrorResponse.getDetailMessageArguments()` that uses the given `MessageSource` for resolving the message argument values.

This is useful for example to expand message codes from validation errors.

The default implementation delegates to `ErrorResponse.getDetailMessageArguments()`, ignoring the supplied `MessageSource` and `Locale`.

Specified by:
  `getDetailMessageArguments` in interface `ErrorResponse`
Parameters:
  `messageSource` - the `MessageSource` to use for the lookup
  `locale` - the `Locale` to use for the lookup

### getDetailMessageArguments

public Object[] getDetailMessageArguments()
Description copied from interface: `ErrorResponse`
Return arguments to use along with a `message code` to resolve the problem "detail" for this exception through a `MessageSource`. The arguments are expanded into placeholders of the message value, for example, "Invalid content type {0}".

Specified by:
  `getDetailMessageArguments` in interface `ErrorResponse`
Overrides:
  `getDetailMessageArguments` in class `ErrorResponseException`

### getTarget

public Object getTarget()

Specified by:
  `getTarget` in interface `org.springframework.validation.method.MethodValidationResult`

### getMethod

public Method getMethod()

Specified by:
  `getMethod` in interface `org.springframework.validation.method.MethodValidationResult`

### isForReturnValue

public boolean isForReturnValue()

Specified by:
  `isForReturnValue` in interface `org.springframework.validation.method.MethodValidationResult`

### getParameterValidationResults

public List<org.springframework.validation.method.ParameterValidationResult> getParameterValidationResults()

Specified by:
  `getParameterValidationResults` in interface `org.springframework.validation.method.MethodValidationResult`

### getCrossParameterValidationResults

public List<org.springframework.context.MessageSourceResolvable> getCrossParameterValidationResults()

Specified by:
  `getCrossParameterValidationResults` in interface `org.springframework.validation.method.MethodValidationResult`

### visitResults

public void visitResults(HandlerMethodValidationException.Visitor visitor)
Provide a `Visitor` to handle `ParameterValidationResult`s through callback methods organized by controller method parameter type.