-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: UnexpectedTypeException: There are multiple validators ...
PostPosted: Thu Aug 20, 2009 5:39 am 
Newbie

Joined: Fri Oct 03, 2008 2:30 am
Posts: 16
Location: Neuchâtel, Switzerland
Hi,
consider the following constraint definition
Code:
@Min(1L)
Long number;
then the validation attempt Validator#validateValue(<type>, "number", "0") leads to
Code:
javax.validation.UnexpectedTypeException: There are multiple validators which could validate the type class java.lang.Long. The validator classes are: class java.lang.Number, class java.lang.String
   at org.hibernate.validation.engine.ConstraintTree.verifyResolveWasUnique(ConstraintTree.java:242)

The reason is in ConstraintTree#findMatchingValidatorClass(Object, Type). I'm really not sure, but maybe this implementation would be more suitable. If the value is not null, and a validator exists that is suitable for the values type, just use it.
But I've to admit, I don't know which side effects this may have...
Code:
if (value != null && validatorsTypes.containsKey(value.getClass()))
  return validatorsTypes.get(value.getClass());

resolveAssignableTypes(suitableTypes);
verifyResolveWasUnique( type, suitableTypes );
return validatorsTypes.get( suitableTypes.get( 0 ) );


Anyway, I'm unsure if this is a bug, an error in the constraint definition or something that was never supposed to work... But validating that a String is a valid Number seems to be a common task.

Thanks,
Ron

hibernate-validator-4.0.0.beta3


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.