public static Object get(Field field, Object target) throws Exception { try { return field.get(target); } catch (IllegalArgumentException iae) { String message = "Could not get field value by reflection: " + toString(field) + " on: " + target.getClass().getName(); throw new IllegalArgumentException(message, iae); } }
public static Object get(Field field, Object target) throws Exception { try { return field.get(target); } catch (IllegalArgumentException iae) { String message = "Could not get field value by reflection: " + toString(field) + " on: " + target.getClass().getName(); throw new IllegalArgumentException(message, iae); } }
public static void set(Field field, Object target, Object value) throws Exception { try { field.set(target, value); } catch (IllegalArgumentException iae) { // target may be null if field is static so use field.getDeclaringClass() instead String message = "Could not set field value by reflection: " + toString(field) + " on: " + field.getDeclaringClass().getName(); if (value==null) { message += " with null value"; } else { message += " with value: " + value.getClass(); } throw new IllegalArgumentException(message, iae); } }
public static void set(Field field, Object target, Object value) throws Exception { try { field.set(target, value); } catch (IllegalArgumentException iae) { // target may be null if field is static so use field.getDeclaringClass() instead String message = "Could not set field value by reflection: " + toString(field) + " on: " + field.getDeclaringClass().getName(); if (value==null) { message += " with null value"; } else { message += " with value: " + value.getClass(); } throw new IllegalArgumentException(message, iae); } }
public static Object invoke(Method method, Object target, Object... args) throws Exception { try { return method.invoke( target, args ); } catch (IllegalArgumentException iae) { String message = "Could not invoke method by reflection: " + toString(method); if (args!=null && args.length>0) { message += " with parameters: (" + Strings.toClassNameString(", ", args) + ')'; } message += " on: " + target.getClass().getName(); throw new IllegalArgumentException(message, iae); } catch (InvocationTargetException ite) { if ( ite.getCause() instanceof Exception ) { throw (Exception) ite.getCause(); } throw ite; } }
public static Object invoke(Method method, Object target, Object... args) throws Exception { try { return method.invoke( target, args ); } catch (IllegalArgumentException iae) { String message = "Could not invoke method by reflection: " + toString(method); if (args!=null && args.length>0) { message += " with parameters: (" + Strings.toClassNameString(", ", args) + ')'; } message += " on: " + target.getClass().getName(); throw new IllegalArgumentException(message, iae); } catch (InvocationTargetException ite) { if ( ite.getCause() instanceof Exception ) { throw (Exception) ite.getCause(); } throw ite; } }