vendredi 25 mai 2018

How to refactor a return of the same value in both catch and try?

I've been noted by Sonar that this is a smelly code. How could I fix it?

invokeFieldAccessor(property.getField(), this.instance, theValue,
    new FieldAccessorHandler() {
        @Override
        public synchronized Object accessField(
                final Field field, final Object objectInstance,
                final Object value) {
            try {
                field.set(objectInstance, value);
            } catch (Exception e) {
                return null;
            }
            return null;
        }
    });

Aucun commentaire:

Enregistrer un commentaire