Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Avoid NullPointerException when projectIter can't be found
Browse files Browse the repository at this point in the history
  • Loading branch information
seanf committed Oct 28, 2014
1 parent 240a396 commit ff9cb51
Showing 1 changed file with 10 additions and 9 deletions.
Expand Up @@ -35,6 +35,7 @@
import org.zanata.util.JPACopier;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.Future;
Expand Down Expand Up @@ -85,12 +86,18 @@ public class CopyVersionServiceImpl implements CopyVersionService {
@Override
public void copyVersion(@Nonnull String projectSlug,
@Nonnull String versionSlug, @Nonnull String newVersionSlug,
CopyVersionTaskHandle handle) {
@Nullable CopyVersionTaskHandle handle) {
Optional<CopyVersionTaskHandle> taskHandleOpt =
Optional.fromNullable(handle);
HProjectIteration version =
projectIterationDAO.getBySlug(projectSlug, versionSlug);

if (version == null) {
log.error("Cannot find project iteration of {}:{}", projectSlug,
versionSlug);
return;
}

if( taskHandleOpt.isPresent() ) {
prepareCopyVersionHandle(version, taskHandleOpt.get());
}
Expand All @@ -100,12 +107,6 @@ public void copyVersion(@Nonnull String projectSlug,
projectSlug + ":" + versionSlug, projectSlug + ":"
+ newVersionSlug);

if (version == null) {
log.error("Cannot find project iteration of {}:{}", projectSlug,
versionSlug);
return;
}

// Copy of HProjectIteration
HProjectIteration newVersion =
projectIterationDAO.getBySlug(projectSlug, newVersionSlug);
Expand Down Expand Up @@ -158,8 +159,8 @@ public Future<Void> startCopyVersion(@Nonnull String projectSlug,
return AsyncTaskResult.taskResult();
}

private void prepareCopyVersionHandle(HProjectIteration originalVersion,
CopyVersionTaskHandle handle) {
private void prepareCopyVersionHandle(@Nonnull HProjectIteration originalVersion,
@Nonnull CopyVersionTaskHandle handle) {
handle.setTriggeredBy(identity.getAccountUsername());
int totalDocCount =
getTotalDocCount(originalVersion.getProject().getSlug(),
Expand Down

0 comments on commit ff9cb51

Please sign in to comment.