Top Fields Constructors Methods
org.hibernate.validator.internal.engine

public Class ConstraintViolationImpl<T>

extends Object
implements HibernateConstraintViolation<T>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.hibernate.validator.engine.HibernateConstraintViolation, jakarta.validation.ConstraintViolation
Imports
java.io.Serializable, java.lang.invoke.MethodHandles, java.util.Map, jakarta.validation.ConstraintViolation, .Path, jakarta.validation.metadata.ConstraintDescriptor, org.hibernate.validator.constraintvalidation.HibernateConstraintValidatorContext, org.hibernate.validator.engine.HibernateConstraintViolation, org.hibernate.validator.internal.util.logging.Log, .LoggerFactory

Authors
Emmanuel Bernard, Hardy Ferentschik

Field Summary

Modifier and TypeField and Description
private final ConstraintDescriptor<?>
private final Object
private final Object[]
private final Object
private final Map<String, Object>
private final int
private final String
private final Object
private static final Log
private final Map<String, Object>
private final String
private final Path
private final T
private final Class<T>
private static final long
private final Object

Constructor Summary

AccessConstructor and Description
private
ConstraintViolationImpl(String messageTemplate, Map<String, Object> messageParameters, Map<String, Object> expressionVariables, String interpolatedMessage, Class<T> rootBeanClass, T rootBean, Object leafBeanInstance, Object value, Path propertyPath, ConstraintDescriptor<?> constraintDescriptor, Object[] executableParameters, Object executableReturnValue, Object dynamicPayload)

Method Summary

Modifier and TypeMethod and Description
private int
public boolean

Returns:

true if the two ConstraintViolation's are considered equals; false otherwise
equals
(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

IMPORTANT - some behaviour of Validator depends on the correct implementation of this equals method!
public static <T> ConstraintViolation<T>
forBeanValidation(String messageTemplate, Map<String, Object> messageParameters, Map<String, Object> expressionVariables, String interpolatedMessage, Class<T> rootBeanClass, T rootBean, Object leafBeanInstance, Object value, Path propertyPath, ConstraintDescriptor<?> constraintDescriptor, Object dynamicPayload)

public static <T> ConstraintViolation<T>
forParameterValidation(String messageTemplate, Map<String, Object> messageParameters, Map<String, Object> expressionVariables, String interpolatedMessage, Class<T> rootBeanClass, T rootBean, Object leafBeanInstance, Object value, Path propertyPath, ConstraintDescriptor<?> constraintDescriptor, Object[] executableParameters, Object dynamicPayload)

public static <T> ConstraintViolation<T>
forReturnValueValidation(String messageTemplate, Map<String, Object> messageParameters, Map<String, Object> expressionVariables, String interpolatedMessage, Class<T> rootBeanClass, T rootBean, Object leafBeanInstance, Object value, Path propertyPath, ConstraintDescriptor<?> constraintDescriptor, Object executableReturnValue, Object dynamicPayload)

public final ConstraintDescriptor<?>
getConstraintDescriptor()

Implements jakarta.validation.ConstraintViolation.getConstraintDescriptor.

Returns the constraint metadata reported to fail.
public <C> C
public Object[]
getExecutableParameters()

Implements jakarta.validation.ConstraintViolation.getExecutableParameters.

Returns an Object[] representing the constructor or method invocation arguments if the ConstraintViolation is returned after validating the method or constructor parameters.
public Object
getExecutableReturnValue()

Implements jakarta.validation.ConstraintViolation.getExecutableReturnValue.

Returns the return value of the constructor or method invocation if the ConstraintViolation is returned after validating the method or constructor return value.
public Map<String, Object>
public final Object
getInvalidValue()

Implements jakarta.validation.ConstraintViolation.getInvalidValue.

Returns the value failing to pass the constraint.
public final Object
getLeafBean()

Implements jakarta.validation.ConstraintViolation.getLeafBean.

Returns:
  • the bean instance the constraint is applied on if it is a bean constraint
  • the bean instance hosting the property the constraint is applied on if it is a property constraint or a container element constraint hosted on a property
  • null when the ConstraintViolation is returned after calling Validator#validateValue(Class, String, Object, Class[])
  • the object the method is executed on if it is a method parameter, cross-parameter or return value constraint or a container element constraint hosted on a method parameter or return value
  • null if it is a constructor parameter or cross-parameter constraint or a container element constraint hosted on a constructor parameter
  • the object the constructor has created if it is a constructor return value constraint
public final String
public Map<String, Object>
public final String
public final Path
public final T
getRootBean()

Implements jakarta.validation.ConstraintViolation.getRootBean.

Returns the root bean being validated.
public final Class<T>
getRootBeanClass()

Implements jakarta.validation.ConstraintViolation.getRootBeanClass.

Returns the class of the root bean being validated.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public <C> C
unwrap(Class<C>
the class of the object to be returned
type
)

Implements jakarta.validation.ConstraintViolation.unwrap.

Returns an instance of the specified type allowing access to provider-specific APIs.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

constraintDescriptorback to summary
private final ConstraintDescriptor<?> constraintDescriptor
dynamicPayloadback to summary
private final Object dynamicPayload
executableParametersback to summary
private final Object[] executableParameters
executableReturnValueback to summary
private final Object executableReturnValue
expressionVariablesback to summary
private final Map<String, Object> expressionVariables
hashCodeback to summary
private final int hashCode
interpolatedMessageback to summary
private final String interpolatedMessage
leafBeanInstanceback to summary
private final Object leafBeanInstance
LOGback to summary
private static final Log LOG
messageParametersback to summary
private final Map<String, Object> messageParameters
messageTemplateback to summary
private final String messageTemplate
propertyPathback to summary
private final Path propertyPath
rootBeanback to summary
private final T rootBean
rootBeanClassback to summary
private final Class<T> rootBeanClass
serialVersionUIDback to summary
private static final long serialVersionUID
valueback to summary
private final Object value

Constructor Detail

ConstraintViolationImplback to summary
private ConstraintViolationImpl(String messageTemplate, Map<String, Object> messageParameters, Map<String, Object> expressionVariables, String interpolatedMessage, Class<T> rootBeanClass, T rootBean, Object leafBeanInstance, Object value, Path propertyPath, ConstraintDescriptor<?> constraintDescriptor, Object[] executableParameters, Object executableReturnValue, Object dynamicPayload)

Method Detail

createHashCodeback to summary
private int createHashCode()
See Also
on which fields are taken into account
equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

IMPORTANT - some behaviour of Validator depends on the correct implementation of this equals method! (HF)

messageParameters, expressionVariables and dynamicPayload are not taken into account for equality. These variables solely enrich the actual Constraint Violation with additional information e.g how we actually got to this CV.

Parameters
o:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

true if the two ConstraintViolation's are considered equals; false otherwise

Annotations
@Override
forBeanValidationback to summary
public static <T> ConstraintViolation<T> forBeanValidation(String messageTemplate, Map<String, Object> messageParameters, Map<String, Object> expressionVariables, String interpolatedMessage, Class<T> rootBeanClass, T rootBean, Object leafBeanInstance, Object value, Path propertyPath, ConstraintDescriptor<?> constraintDescriptor, Object dynamicPayload)
forParameterValidationback to summary
public static <T> ConstraintViolation<T> forParameterValidation(String messageTemplate, Map<String, Object> messageParameters, Map<String, Object> expressionVariables, String interpolatedMessage, Class<T> rootBeanClass, T rootBean, Object leafBeanInstance, Object value, Path propertyPath, ConstraintDescriptor<?> constraintDescriptor, Object[] executableParameters, Object dynamicPayload)
forReturnValueValidationback to summary
public static <T> ConstraintViolation<T> forReturnValueValidation(String messageTemplate, Map<String, Object> messageParameters, Map<String, Object> expressionVariables, String interpolatedMessage, Class<T> rootBeanClass, T rootBean, Object leafBeanInstance, Object value, Path propertyPath, ConstraintDescriptor<?> constraintDescriptor, Object executableReturnValue, Object dynamicPayload)
getConstraintDescriptorback to summary
public final ConstraintDescriptor<?> getConstraintDescriptor()

Implements jakarta.validation.ConstraintViolation.getConstraintDescriptor.

Doc from jakarta.validation.ConstraintViolation.getConstraintDescriptor.

Returns the constraint metadata reported to fail. The returned instance is immutable.

Returns:ConstraintDescriptor<?>

constraint metadata

Annotations
@Override
getDynamicPayloadback to summary
public <C> C getDynamicPayload(Class<C> type)

Implements org.hibernate.validator.engine.HibernateConstraintViolation.getDynamicPayload.

Parameters
type:Class<C>

Doc from org.hibernate.validator.engine.HibernateConstraintViolation.getDynamicPayload.

The type of payload to retrieve

Returns:C

Doc from org.hibernate.validator.engine.HibernateConstraintViolation.getDynamicPayload.

an instance of the specified type set by the user via HibernateConstraintValidatorContext#withDynamicPayload(Object) or null if no constraint payload if the given type has been set.

Annotations
@Override
getExecutableParametersback to summary
public Object[] getExecutableParameters()

Implements jakarta.validation.ConstraintViolation.getExecutableParameters.

Doc from jakarta.validation.ConstraintViolation.getExecutableParameters.

Returns an Object[] representing the constructor or method invocation arguments if the ConstraintViolation is returned after validating the method or constructor parameters. Returns null otherwise.

Returns:Object[]

parameters of the method or constructor invocation or null

Annotations
@Override
getExecutableReturnValueback to summary
public Object getExecutableReturnValue()

Implements jakarta.validation.ConstraintViolation.getExecutableReturnValue.

Doc from jakarta.validation.ConstraintViolation.getExecutableReturnValue.

Returns the return value of the constructor or method invocation if the ConstraintViolation is returned after validating the method or constructor return value.

Returns null if the method has no return value. Returns null otherwise.

Returns:Object

the method or constructor return value or null

Annotations
@Override
getExpressionVariablesback to summary
public Map<String, Object> getExpressionVariables()
Returns:Map<String, Object>

the expression variables added using HibernateConstraintValidatorContext#addExpressionVariable(String, Object)

getInvalidValueback to summary
public final Object getInvalidValue()

Implements jakarta.validation.ConstraintViolation.getInvalidValue.

Doc from jakarta.validation.ConstraintViolation.getInvalidValue.

Returns the value failing to pass the constraint. For cross-parameter constraints, an Object[] representing the method invocation arguments is returned.

Returns:Object

the value failing to pass the constraint

Annotations
@Override
getLeafBeanback to summary
public final Object getLeafBean()

Implements jakarta.validation.ConstraintViolation.getLeafBean.

Doc from jakarta.validation.ConstraintViolation.getLeafBean.

Returns:

  • the bean instance the constraint is applied on if it is a bean constraint
  • the bean instance hosting the property the constraint is applied on if it is a property constraint or a container element constraint hosted on a property
  • null when the ConstraintViolation is returned after calling Validator#validateValue(Class, String, Object, Class[])
  • the object the method is executed on if it is a method parameter, cross-parameter or return value constraint or a container element constraint hosted on a method parameter or return value
  • null if it is a constructor parameter or cross-parameter constraint or a container element constraint hosted on a constructor parameter
  • the object the constructor has created if it is a constructor return value constraint
Returns:Object

the leaf bean

Annotations
@Override
getMessageback to summary
public final String getMessage()

Implements jakarta.validation.ConstraintViolation.getMessage.

Returns:String

Doc from jakarta.validation.ConstraintViolation.getMessage.

the interpolated error message for this constraint violation

Annotations
@Override
getMessageParametersback to summary
public Map<String, Object> getMessageParameters()
Returns:Map<String, Object>

the message parameters added using HibernateConstraintValidatorContext#addMessageParameter(String, Object)

getMessageTemplateback to summary
public final String getMessageTemplate()

Implements jakarta.validation.ConstraintViolation.getMessageTemplate.

Returns:String

Doc from jakarta.validation.ConstraintViolation.getMessageTemplate.

the non-interpolated error message for this constraint violation

Annotations
@Override
getPropertyPathback to summary
public final Path getPropertyPath()

Implements jakarta.validation.ConstraintViolation.getPropertyPath.

Returns:Path

Doc from jakarta.validation.ConstraintViolation.getPropertyPath.

the property path to the value from rootBean

Annotations
@Override
getRootBeanback to summary
public final T getRootBean()

Implements jakarta.validation.ConstraintViolation.getRootBean.

Doc from jakarta.validation.ConstraintViolation.getRootBean.

Returns the root bean being validated. For method validation, returns the object the method is executed on.

Returns null when:

Returns:T

the validated object, the object hosting the validated element or null

Annotations
@Override
getRootBeanClassback to summary
public final Class<T> getRootBeanClass()

Implements jakarta.validation.ConstraintViolation.getRootBeanClass.

Doc from jakarta.validation.ConstraintViolation.getRootBeanClass.

Returns the class of the root bean being validated. For method validation, this is the object class the method is executed on. For constructor validation, this is the class the constructor is declared on.

Returns:Class<T>

the class of the root bean or of the object hosting the validated element

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
unwrapback to summary
public <C> C unwrap(Class<C> type)

Implements jakarta.validation.ConstraintViolation.unwrap.

Doc from jakarta.validation.ConstraintViolation.unwrap.

Returns an instance of the specified type allowing access to provider-specific APIs. If the Jakarta Bean Validation provider implementation does not support the specified class, ValidationException is thrown.

Parameters
<C>
the type of the object to be returned
type:Class<C>

the class of the object to be returned

Returns:C

an instance of the specified class

Annotations
@Override