Source:
<code>private void validateChanges(Run before, Run changed) throws IOException { List<ValidationError> errors = new ArrayList<>(); if (!changed.getHealth().isDone()) { changed.setCompletionDate(null); } else if (changed.getCompletionDate() == null) { errors.add(new ValidationError("completionDate", "Completion date must be provided for finished run")); } if (before != null) { if (before.getCompletionDate() != null && changed.getCompletionDate() != null && !changed.getCompletionDate().equals(before.getCompletionDate()) && !authorizationManager.isAdminUser()) { errors.add(new ValidationError("completionDate", "Only admin may change completion date")); } if (before.getStartDate() != null && changed.getStartDate() != null && !changed.getStartDate().equals(before.getStartDate()) && !authorizationManager.isAdminUser()) { errors.add(new ValidationError("completionDate", "Only admin may change start date")); } } if (isSetAndChanged(Run::getAlias, changed, before)) { Run maybeDupe = getRunByAlias(changed.getAlias()); <START> if (changed.getId() == Run.UNSAVED_ID || changed.getId() != maybeDupe.getId()) { <END> errors.add(new ValidationError("alias", "A different run with this alias already exists. Run alias must be unique.")); } } InstrumentModel platform = changed.getSequencer().getInstrumentModel(); for (RunPosition position : changed.getRunPositions()) { if (position.getPosition() != null && !platform.getPositions().contains(position.getPosition())) { errors.add(new ValidationError( String.format("Platform %s does not have a position %s", platform.getAlias(), position.getPosition()))); } } if (!errors.isEmpty()) { throw new ValidationException(errors); } }</code><technical_language>This check is unnecessary checking alias is new changed</technical_language>

Target:
private void validateChanges(Run before, Run changed) throws IOException { List<ValidationError> errors = new ArrayList<>(); if (!changed.getHealth().isDone()) { changed.setCompletionDate(null); } else if (changed.getCompletionDate() == null) { errors.add(new ValidationError("completionDate", "Completion date must be provided for finished run")); } if (before != null) { if (before.getCompletionDate() != null && changed.getCompletionDate() != null && !changed.getCompletionDate().equals(before.getCompletionDate()) && !authorizationManager.isAdminUser()) { errors.add(new ValidationError("completionDate", "Only admin may change completion date")); } if (before.getStartDate() != null && changed.getStartDate() != null && !changed.getStartDate().equals(before.getStartDate()) && !authorizationManager.isAdminUser()) { errors.add(new ValidationError("completionDate", "Only admin may change start date")); } } if (isSetAndChanged(Run::getAlias, changed, before) && getRunByAlias(changed.getAlias()) != null) { errors.add(new ValidationError("alias", "A different run with this alias already exists. Run alias must be unique.")); } InstrumentModel platform = changed.getSequencer().getInstrumentModel(); for (RunPosition position : changed.getRunPositions()) { if (position.getPosition() != null && !platform.getPositions().contains(position.getPosition())) { errors.add(new ValidationError( String.format("Platform %s does not have a position %s", platform.getAlias(), position.getPosition()))); } } if (!errors.isEmpty()) { throw new ValidationException(errors); } }