fix potential NPE when getting last changed timestamp.
This commit is contained in:
parent
e58a5e73d6
commit
38cebb56be
1 changed files with 16 additions and 7 deletions
|
@ -444,23 +444,32 @@ public class PasswordStore extends AppCompatActivity {
|
||||||
Repository repository = PasswordRepository.getRepository(repoPath);
|
Repository repository = PasswordRepository.getRepository(repoPath);
|
||||||
|
|
||||||
if (repository == null) {
|
if (repository == null) {
|
||||||
|
Log.e(TAG, "getLastChangedTimestamp: No git repository");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Git git = new Git(repository);
|
Git git = new Git(repository);
|
||||||
String relativePath = getRelativePath(fullPath, repoPath.getAbsolutePath()).substring(1);
|
String relativePath = getRelativePath(fullPath, repoPath.getAbsolutePath())
|
||||||
Iterable<RevCommit> iterable;
|
.substring(1); // Removes leading '/'
|
||||||
|
|
||||||
|
Iterator<RevCommit> iterator;
|
||||||
try {
|
try {
|
||||||
iterable = git.log().addPath(relativePath).call();
|
iterator = git
|
||||||
|
.log()
|
||||||
|
.addPath(relativePath)
|
||||||
|
.call()
|
||||||
|
.iterator();
|
||||||
} catch (GitAPIException e) {
|
} catch (GitAPIException e) {
|
||||||
System.out.println("Exception caught :(");
|
Log.e(TAG, "getLastChangedTimestamp: GITAPIException", e);
|
||||||
e.printStackTrace();
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
RevCommit latestCommit = iterable.iterator().next();
|
if (!iterator.hasNext()) {
|
||||||
return latestCommit.getCommitTime();
|
Log.w(TAG, "getLastChangedTimestamp: No commits for file: " + relativePath);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return iterator.next().getCommitTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void decryptPassword(PasswordItem item) {
|
public void decryptPassword(PasswordItem item) {
|
||||||
|
|
Loading…
Reference in a new issue