Skip to content

fix: read EXIF orientation directly for plain file paths - #156

Draft
dcalhoun wants to merge 1 commit into
trunkfrom
fix/skip-mediastore-orientation-query-for-file-paths
Draft

fix: read EXIF orientation directly for plain file paths#156
dcalhoun wants to merge 1 commit into
trunkfrom
fix/skip-mediastore-orientation-query-for-file-paths

Conversation

@dcalhoun

@dcalhoun dcalhoun commented Jul 23, 2026

Copy link
Copy Markdown
Member

Description

ImageUtils.getImageOrientation prefixes any non-content:// path with content://media and queries the MediaStore content provider first, only falling back to reading EXIF when that query returns nothing.

For a plain filesystem path pointing at an existing file (e.g. an app cache file), that constructed Uri is never resolvable through MediaStore, so the query always fails. On some devices it fails by throwing IllegalArgumentException: Volume data not found, which is caught but logged as an error with a full stack trace on every call:

E  Error reading orientation of the file: /data/user/0/<app>/cache/.../image.jpg
   java.lang.IllegalArgumentException: Volume data not found
       at android.database.DatabaseUtils.readExceptionFromParcel(...)
       ...
       at org.wordpress.android.util.ImageUtils.getImageOrientation(ImageUtils.java:100)
       at org.wordpress.android.util.ImageUtils.optimizeImage(ImageUtils.java:547)

The orientation was still resolved correctly (via the EXIF fallback), so this was benign but noisy — and increasingly common now that hosts optimize images staged in their own cache directories (e.g. GutenbergKit's native media upload processing).

Fix

When the path is a plain filesystem path that points at an existing file, read EXIF orientation directly and skip the doomed provider query. EXIF is the only orientation source such a file has, so this is behavior-preserving. MediaStore-style paths (which don't exist on the filesystem) keep the previous query-then-EXIF-fallback behavior.

Testing

Verified in a host app (wordpress-mobile/WordPress-Android#23142) that optimizes an image staged in its cache dir: before this change the error + stack trace logged on every upload; after, it's gone and orientation is still applied correctly.

Co-authored with Claude.

getImageOrientation prefixed non-content paths with "content://media"
and queried the MediaStore content provider first, falling back to EXIF
when that failed. For a plain filesystem path pointing at an existing
file (e.g. an app cache file), that constructed Uri is never resolvable
and the query always fails — on some devices by throwing
IllegalArgumentException ("Volume data not found"), which was logged
as an error with a stack trace on every call.

Such files carry their orientation only in EXIF, so read it directly
and skip the doomed provider query. MediaStore-style paths (which do
not exist on the filesystem) keep the previous behavior.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant