Fix a cursor not being closed

Still won't be the cause for #655
master
cpfeiffer 2017-04-23 12:44:03 +02:00
parent f06298a3c8
commit ed02a9781a
2 changed files with 23 additions and 16 deletions

View File

@ -79,6 +79,7 @@ public class UriHelper {
* Opens a stream to read the contents of the uri.
* Note: the caller has to close the stream after usage.
* Every invocation of this method will open a new stream.
* FIXME: make sure that every caller actually closes the returned stream!
* @throws FileNotFoundException
*/
@NonNull
@ -127,6 +128,7 @@ public class UriHelper {
if (cursor == null) {
throw new IOException("Unable to query metadata for: " + uri);
}
try {
if (cursor.moveToFirst()) {
int name_index = cursor.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME);
if (name_index == -1) {
@ -149,6 +151,9 @@ public class UriHelper {
throw new IOException("Unable to retrieve metadata for: " + uri + ": " + ex.getMessage());
}
}
} finally {
cursor.close();
}
} else if (ContentResolver.SCHEME_FILE.equals(uriScheme)) {
file = new File(uri.getPath());
if (!file.exists()) {

View File

@ -32,4 +32,6 @@ public class Tryout extends TestBase {
LOG.info("Calender: " + DateTimeUtils.formatDateTime(calendar.getTime()));
Logging.logBytes(LOG, bytes);
}
}