queryRecentDocuments method of MyCloudProvider.java have a bug.
Closed this issue · 1 comments
lbtrace commented
- Code analysis
Code path: \Application\src\main\java\com\example\android\storageprovider\MyCloudProvider.java
public Cursor queryRecentDocuments(String rootId, String[] projection)
throws FileNotFoundException {
......
// Create a queue to store the most recent documents, which orders by last modified.
PriorityQueue<File> lastModifiedFiles = new PriorityQueue<File>(5, new Comparator<File>() {
public int compare(File i, File j) {
return Long.compare(i.lastModified(), j.lastModified());
}
});
......
// Add the most recent files to the cursor, not exceeding the max number of results.
for (int i = 0; i < Math.min(MAX_LAST_MODIFIED + 1, lastModifiedFiles.size()); i++) {
final File file = lastModifiedFiles.remove();
includeFile(result, null, file);
}
return result;
}
In for code segment, lastModifiedFiles.remove()
will modify PriorityQueue size, so lastModifiedFiles.size()
always change, this is logic error.
codingjeremy commented
I am closing this issue/PR, as it has been migrated to the new repo linked above. Thank you!