@Test public void testPropertyNotFound() throws Exception { expectedException.expect(ReflectiveOperationException.class); expectedException.expectMessage("Property not found: unknown"); ReflectionHelper.getAccessor(Base.class, "unknown"); }
public static PropertyAccessor getAccessor(Class<?> clazz, String propertyName) throws ReflectiveOperationException { if (propertyName == null || propertyName.length() == 0) { throw new IllegalArgumentException("Property name cannot be null or empty"); } if (propertyName.indexOf('.') != -1) { throw new IllegalArgumentException("The argument cannot be a nested property name"); } String propertyNameSuffix = Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1); Class<?> c = clazz; while (c != null) { PropertyAccessor m = getAccessor(c, propertyName, propertyNameSuffix); if (m != null) { return m; } c = c.getSuperclass(); } throw new ReflectiveOperationException("Property not found: " + propertyName); }
ReflectionHelper { public static PropertyAccessor getAccessor(Class<?> clazz, String propertyName) throws ReflectiveOperationException { if (propertyName == null || propertyName.length() == 0) { throw new IllegalArgumentException("Property name cannot be null or empty"); } if (propertyName.indexOf('.') != -1) { throw new IllegalArgumentException("The argument cannot be a nested property name"); } String propertyNameSuffix = Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1); Class<?> c = clazz; while (c != null) { PropertyAccessor m = getAccessor(c, propertyName, propertyNameSuffix); if (m != null) { return m; } c = c.getSuperclass(); } throw new ReflectiveOperationException("Property not found: " + propertyName); } }
ReflectionHelper { public static PropertyAccessor getAccessor(Class<?> clazz, String propertyName) throws ReflectiveOperationException { if (propertyName == null || propertyName.length() == 0) { throw new IllegalArgumentException("Property name cannot be null or empty"); } if (propertyName.indexOf('.') != -1) { throw new IllegalArgumentException("The argument cannot be a nested property name"); } String propertyNameSuffix = Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1); Class<?> c = clazz; while (c != null) { PropertyAccessor m = getAccessor(c, propertyName, propertyNameSuffix); if (m != null) { return m; } c = c.getSuperclass(); } throw new ReflectiveOperationException("Property not found: " + propertyName); } private  ReflectionHelper(); }
ReflectionHelper { public static PropertyAccessor getAccessor(Class<?> clazz, String propertyName) throws ReflectiveOperationException { if (propertyName == null || propertyName.length() == 0) { throw new IllegalArgumentException("Property name cannot be null or empty"); } if (propertyName.indexOf('.') != -1) { throw new IllegalArgumentException("The argument cannot be a nested property name"); } String propertyNameSuffix = Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1); Class<?> c = clazz; while (c != null) { PropertyAccessor m = getAccessor(c, propertyName, propertyNameSuffix); if (m != null) { return m; } c = c.getSuperclass(); } throw new ReflectiveOperationException("Property not found: " + propertyName); } private  ReflectionHelper(); static PropertyAccessor getAccessor(Class<?> clazz, String propertyName); }
ReflectionHelper { public static PropertyAccessor getAccessor(Class<?> clazz, String propertyName) throws ReflectiveOperationException { if (propertyName == null || propertyName.length() == 0) { throw new IllegalArgumentException("Property name cannot be null or empty"); } if (propertyName.indexOf('.') != -1) { throw new IllegalArgumentException("The argument cannot be a nested property name"); } String propertyNameSuffix = Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1); Class<?> c = clazz; while (c != null) { PropertyAccessor m = getAccessor(c, propertyName, propertyNameSuffix); if (m != null) { return m; } c = c.getSuperclass(); } throw new ReflectiveOperationException("Property not found: " + propertyName); } private  ReflectionHelper(); static PropertyAccessor getAccessor(Class<?> clazz, String propertyName);  }