Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check that a DocumentFile exists

I check a files meta data and existence using DocumentFile. This is instanciated thusly:

DocumentFile df = DocumentFile.fromSingleUri(context, uri);
boolean exists = df.exists();

The uri to the file worked previously, until I purposefully deleted the file manually in the filesystem to see how the App would react. Now this stacktrace appears in the App:

03-14 11:33:08.559 27087-27097/? E/DatabaseUtils: Writing exception to parcel
  java.lang.IllegalArgumentException: Failed to determine if primary:Download/thefile.txt is child of primary:Download: java.io.FileNotFoundException: Missing file for primary:Download/thefile.txt at /storage/emulated/0/Download/thefile.txt
      at com.android.externalstorage.ExternalStorageProvider.isChildDocument(ExternalStorageProvider.java:326)
      at android.provider.DocumentsProvider.enforceTree(DocumentsProvider.java:198)
      at android.provider.DocumentsProvider.query(DocumentsProvider.java:489)
      at android.content.ContentProvider.query(ContentProvider.java:1017)
      at android.content.ContentProvider$Transport.query(ContentProvider.java:238)
      at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:112)
      at android.os.Binder.execTransact(Binder.java:453)
03-14 11:33:08.561 27046-27419/packagename W/DocumentFile: Failed query: java.lang.IllegalArgumentException: Failed to determine if primary:Download/thefile.txt is child of primary:Download: java.io.FileNotFoundException: Missing file for primary:Download/thefile.txt at /storage/emulated/0/Download/thefile.txt

It doesn't crash the App, it simply generates this stacktrace every time I attempt to use the DocumentFile. So at worst, this is simply an irritant in logcat.

I would expect to avoid this FileNotFoundException using .exists(). As I am checking whether it exists to avoid working with a file that isn't there.

Is there a different function to use that is recommended in this case?

like image 310
Knossos Avatar asked Jan 06 '23 11:01

Knossos


1 Answers

I've dealt with this annoyance for far too long; you can't even wrap it. I've submitted a bug report for this erroneous error:

https://code.google.com/p/android/issues/detail?id=241400&thanks=241400&ts=1489099169

Add support, things get fixed faster that way.

like image 166
Anthony Avatar answered Jan 28 '23 18:01

Anthony