@SuppressWarnings("unused")
final String conMethodName = conClassName + "::setObjectFieldsFrom";
Field[] fields;
Class<?> origClass = origObj.getClass();
if (!origClass.isAssignableFrom(this.getClass())) {
throw new JobSchedulerException(String.format("%1$s must be a subclass of %2$s", this.getClass().getName(), origClass.getName()));
}
fields = origClass.getDeclaredFields();
for (Field field : fields) {
try {
// to see private and protected fields too
field.setAccessible(true);
if (field.isAccessible()) {
//final fields couldn't set and throws IllegalAccessException
//but that's ok because we don't want set final fields
field.set(this, field.get(origObj));
}
}
catch (IllegalArgumentException e) {
logger.error("", new JobSchedulerException("IllegalArgumentException", e));
}
catch (IllegalAccessException e) {
// this catch block is reached for final fields (that's ok)
}
}