From 24af8af62c06cef59d2c82799f83da95643ef960 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Thu, 27 Jul 2023 20:32:16 +0800 Subject: [PATCH] Avoid crashes in some edge cases * java/org/gnu/emacs/EmacsActivity.java (onActivityResult): Avoid crashes in some edge cases. --- java/org/gnu/emacs/EmacsActivity.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/java/org/gnu/emacs/EmacsActivity.java b/java/org/gnu/emacs/EmacsActivity.java index 86fed5396d7..4ddf51fbb20 100644 --- a/java/org/gnu/emacs/EmacsActivity.java +++ b/java/org/gnu/emacs/EmacsActivity.java @@ -462,8 +462,17 @@ public class EmacsActivity extends Activity flags = (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); - if (uri != null) - resolver.takePersistableUriPermission (uri, flags); + try + { + if (uri != null) + resolver.takePersistableUriPermission (uri, flags); + } + catch (Exception exception) + { + /* Permission to access URI might've been revoked in + between selecting the file and this callback being + invoked. Don't crash in such cases. */ + } } break; -- 2.39.5