Issue Type: Bug Bug
Affects Versions: 4.2.0.Final
Assignee: Unassigned
Components: validators
Created: 24/Oct/12 9:22 AM
Description:

there is a difference in the processing of raw type and <?> type.
here is my use case :

@Target( { ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = SettingValueSettingTypeValidator.class)
@Documented
@Inherited
public @interface CheckSettingValueSettingType
{
String message() default "{com.XXX.settings.settingvaluesettingtype}";

Class<?>[] groups() default {};

Class<? extends Payload>[] payload() default {};
}

public class SettingValueSettingTypeValidator implements ConstraintValidator<CheckSettingValueSettingType, SettingValue>
{

@Override
public void initialize(CheckSettingValueSettingType constraint)

{ // nothing to initialize }

@Override
public boolean isValid(SettingValue settingValue, ConstraintValidatorContext context)
{
if (settingValue instanceof IntegerSettingValue)

{ return SettingTypes.isIntegerSettingType(settingValue.getSettingKey().getSettingTypeId()); }

if (settingValue instanceof StringSettingValue)

{ return SettingTypes.isStringSettingType(settingValue.getSettingKey().getSettingTypeId()); }

if (settingValue instanceof DateSettingValue)

{ return SettingTypes.isDateSettingType(settingValue.getSettingKey().getSettingTypeId()); }

return false;
}

}

@CheckSettingValueSettingType
public abstract class SettingValue<T> extends BaseEntity

{ ... }

public class IntegerSettingValue extends SettingValue<Integer>{ ... }

}

public class SettingValueSettingTypeValidator implements ConstraintValidator<CheckSettingValueSettingType, SettingValue>
everything works fine, though when,

public class SettingValueSettingTypeValidator implements ConstraintValidator<CheckSettingValueSettingType, SettingValue<?>>

I get the following exception :
javax.validation.UnexpectedTypeException: No validator could be found for type: com.XXX.settings.data.SettingValue

workaround :

  • do not use @Inherited annotation
  • use @SuppressWarnings("rawtypes") instead of inferring <?>
Project: Hibernate Validator
Priority: Major Major
Reporter: Mathieu Lachance
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira