diff options
author | حسين <zidhussein@gmail.com> | 2019-01-01 16:29:05 +0000 |
---|---|---|
committer | حسين <zidhussein@gmail.com> | 2019-01-01 16:29:05 +0000 |
commit | 38cebb56be2bfd32aefe0458738a4fba247c0572 (patch) | |
tree | b9a37f6c827de450645a8c2443c87471de0459d7 /app/src/main/java/com | |
parent | e58a5e73d65cf86c1c4f0cdc30d3a66112b8ad61 (diff) |
fix potential NPE when getting last changed timestamp.
Diffstat (limited to 'app/src/main/java/com')
-rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/PasswordStore.java | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java index d7187749..632e966c 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java @@ -444,23 +444,32 @@ public class PasswordStore extends AppCompatActivity { Repository repository = PasswordRepository.getRepository(repoPath); if (repository == null) { + Log.e(TAG, "getLastChangedTimestamp: No git repository"); return -1; } Git git = new Git(repository); - String relativePath = getRelativePath(fullPath, repoPath.getAbsolutePath()).substring(1); - Iterable<RevCommit> iterable; + String relativePath = getRelativePath(fullPath, repoPath.getAbsolutePath()) + .substring(1); // Removes leading '/' + Iterator<RevCommit> iterator; try { - iterable = git.log().addPath(relativePath).call(); + iterator = git + .log() + .addPath(relativePath) + .call() + .iterator(); } catch (GitAPIException e) { - System.out.println("Exception caught :("); - e.printStackTrace(); + Log.e(TAG, "getLastChangedTimestamp: GITAPIException", e); + return -1; + } + + if (!iterator.hasNext()) { + Log.w(TAG, "getLastChangedTimestamp: No commits for file: " + relativePath); return -1; } - RevCommit latestCommit = iterable.iterator().next(); - return latestCommit.getCommitTime(); + return iterator.next().getCommitTime(); } public void decryptPassword(PasswordItem item) { |