Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Final] Fixing null zinc repo index bug. #20

Merged
merged 7 commits into from Nov 15, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 java.io.*;


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

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


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

}
return new ZincRepoIndex(); }
} catch (IOException ioe) {
throw new ZincRuntimeException("Error creating index file", ioe); 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