Uploaded image for project: 'Hibernate Validator'
  1. HV-1032

Infinite Loop when validating custom type constraint under certain inheritance scheme

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 5.2.2.Final
    • Fix Version/s: 5.2.5.Final, 5.3.1.Final
    • Component/s: engine
    • Labels:
      None

      Description

      There is an infinite loop occurring in TypeHelper.normalize(). The issue seems to occur any time a parameterized supertype is passed into TypeHelper.isAssignable.

      I was able to see that in my test cases, ParameterizedType.getActualTypeArguments() is returning the same exact object as Class.getTypeParameters()... which causes TypeHelper to create a map with an entry where Key = Value. Given the logic in TypeHelper.normalize(), this in turn causes an infinite loop.

      	private static <K, V> Map<K, V> normalize(Map<K, V> map) {
      		// TODO: will this cause an infinite loop with recursive bounds?
      
      		for ( Entry<K, V> entry : map.entrySet() ) {
      			K key = entry.getKey();
      			V value = entry.getValue();
      
      			while ( map.containsKey( value ) ) {
      				value = map.get( value );
      			}
      
      			map.put( key, value );
      		}
      
      		return map;
      	}
      

      I've attached a couple of test cases which illustrate the issue, copied below.

      
      

        Attachments

          Issue links

            Activity

              People

              • Votes:
                2 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: