- Field existingField = profile.getFieldByName(name);
- if ((existingField == null) || (existingField.equals(field))) {
- field.setName(name);
+ Optional<Field> existingField = profile.getFieldByName(name);
+ if (!existingField.isPresent() || existingField.equals(field)) {
+ profile.renameField(field.get(), name);