public static Field findField(Class<?> type,String name) throws NoSuchFieldException {
  if (name == null) {
    throw new IllegalArgumentException("Field name is not set");
  }
  Field field=type.getField(name);
  if (!Modifier.isPublic(field.getModifiers())) {
    throw new NoSuchFieldException("Field '" + name + "' is not public");
  }
  type=field.getDeclaringClass();
  if (!Modifier.isPublic(type.getModifiers()) || !isPackageAccessible(type)) {
    throw new NoSuchFieldException("Field '" + name + "' is not accessible");
  }
  return field;
}

public static Field findField ( Class < ? > type , String name ) throws NoSuchFieldException { if ( name == null ) { throw new IllegalArgumentException ( "Field name is not set" ) ; } Field field = type . getField ( name ) ; if ( ! Modifier . isPublic ( field . getModifiers ( ) ) ) { throw new NoSuchFieldException ( "Field '" + name + "' is not public" ) ; } type = field . getDeclaringClass ( ) ; if ( ! Modifier . isPublic ( type . getModifiers ( ) ) || ! isPackageAccessible ( type ) ) { throw new NoSuchFieldException ( "Field '" + name + "' is not accessible" ) ; } return field ; }
finds public field ( static or non - static ) that is declared in public class .
