BeanPropertyUtils { static Field readSafeField(Class sourceClass, String fieldName) { Class classToInspect = sourceClass; while (classToInspect != Object.class) { try { return classToInspect.getDeclaredField(fieldName); } catch (NoSuchFieldException ex) { classToInspect = classToInspect.getSuperclass(); continue; } } return null; }    }
@Test public void testReadSafeField() { String testFieldName = "myField"; Field field = BeanPropertyUtils.readSafeField(TBPUB.class, testFieldName); assertNotNull("Inherited field should be found anyway.", field); }