private void checkForCycles ( Class < ? > target , Class < ? > in , Stack < Class < ? > > trace ) { for ( Field field : in . getDeclaredFields ( ) ) { if ( field . getAnnotation ( Autowired . class ) != null ) { Class < ? > type = field . getType ( ) ; trace . push ( type ) ; if ( type . equals ( target ) ) { throw new DependencyCycleException ( trace ) ; } else { checkForCycles ( target , type , trace ) ; } trace . pop ( ) ; } } }
A simple recursive cycle - checker implementation that records the current stack trace as an argument parameter for the purpose of producing an accurate error message in the case of an error .