Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #20 from mindsnacks/fixing_null_zinc_repo_index_bug
Browse files Browse the repository at this point in the history
[Final] Fixing null zinc repo index bug.
  • Loading branch information
tonycosentini committed Nov 15, 2013
2 parents 87ba597 + aba248b commit 77fba63
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/main/java/com/mindsnacks/zinc/classes/ZincRepoIndexWriter.java
Expand Up @@ -6,6 +6,8 @@

import java.io.*;

import static com.google.common.base.Preconditions.checkNotNull;

/**
* User: NachoSoto
* Date: 9/3/13
Expand Down Expand Up @@ -45,16 +47,26 @@ public ZincRepoIndex getIndex() {

private ZincRepoIndex initializeIndex() {
try {
return mGson.fromJson(new FileReader(mIndexFile), ZincRepoIndex.class);
return checkNotNull(readRepoIndexFile());
} catch (FileNotFoundException fnfe) {
try {
mIndexFile.getParentFile().mkdirs();
mIndexFile.createNewFile();

return new ZincRepoIndex();
} catch (IOException ioe) {
throw new ZincRuntimeException("Error creating index file", ioe);
}
return createNewIndexFile();
} catch (NullPointerException npe) {
return createNewIndexFile();
}
}

private ZincRepoIndex readRepoIndexFile() throws FileNotFoundException {
return mGson.fromJson(new FileReader(mIndexFile), ZincRepoIndex.class);
}

private ZincRepoIndex createNewIndexFile() {
try {
mIndexFile.getParentFile().mkdirs();
mIndexFile.createNewFile();

return new ZincRepoIndex();
} catch (IOException ioe) {
throw new ZincRuntimeException("Error creating index file", ioe);
}
}

Expand Down

0 comments on commit 77fba63

Please sign in to comment.