4

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?

Knossos
  • 15,802
  • 10
  • 54
  • 91
  • Probably not, particularly if `exists()` is returning the proper value. The document provider in question apparently is not expecting files to be deleted "behind its back", so to speak. – CommonsWare Mar 14 '16 at 11:01

1 Answers1

9

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.

Anthony
  • 7,638
  • 3
  • 38
  • 71
  • 2
    so... "Aug 18, 2020 11:22AM Status: Won't Fix (Obsolete)" Still a problem for me. What does obsolete mean? That I spent months fixing everything to use the new documentfile stuff and now they've replaced it AGAIN? – stu Oct 12 '20 at 21:18