private static Field findFieldOrThrowException ( Class < ? > fieldType , Class < ? > where ) { if ( fieldType == null || where == null ) { throw new IllegalArgumentException ( "fieldType and where cannot be null" ) ; } Field field = null ; for ( Field currentField : where . getDeclaredFields ( ) ) { currentField . setAccessible ( true ) ; if ( currentField . getType ( ) . equals ( fieldType ) ) { field = currentField ; break ; } } if ( field == null ) { throw new FieldNotFoundException ( "Cannot find a field of type " + fieldType + "in where." ) ; } return field ; }
Find field or throw exception .