From 589036056277cf290142556b564cc4f62d7c8d4c Mon Sep 17 00:00:00 2001 From: Makoto Onuki Date: Tue, 21 Apr 2020 13:17:57 -0700 Subject: [PATCH] Ignore exceptions when investigating failure reasons Fix: 154428500 Test: boot Test: code inspection Change-Id: I2a69a58aaa43617f40bc52fd06cba730faa93672 --- .../database/sqlite/SQLiteConnection.java | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/core/java/android/database/sqlite/SQLiteConnection.java b/core/java/android/database/sqlite/SQLiteConnection.java index f7c96a3a02c1c..2f67f6ddc0822 100644 --- a/core/java/android/database/sqlite/SQLiteConnection.java +++ b/core/java/android/database/sqlite/SQLiteConnection.java @@ -228,19 +228,26 @@ public final class SQLiteConnection implements CancellationSignal.OnCancelListen } catch (SQLiteCantOpenDatabaseException e) { String message = String.format("Cannot open database '%s'", file); - final Path path = FileSystems.getDefault().getPath(file); - final Path dir = path.getParent(); + try { + // Try to diagnose for common reasons. If something fails in here, that's fine; + // just swallow the exception. - if (!Files.isDirectory(dir)) { - message += ": Directory " + dir + " doesn't exist"; - } else if (!Files.exists(path)) { - message += ": File " + path + " doesn't exist"; - } else if (!Files.isReadable(path)) { - message += ": File " + path + " is not readable"; - } else if (Files.isDirectory(path)) { - message += ": Path " + path + " is a directory"; - } else { - message += ": Unknown reason"; + final Path path = FileSystems.getDefault().getPath(file); + final Path dir = path.getParent(); + + if (!Files.isDirectory(dir)) { + message += ": Directory " + dir + " doesn't exist"; + } else if (!Files.exists(path)) { + message += ": File " + path + " doesn't exist"; + } else if (!Files.isReadable(path)) { + message += ": File " + path + " is not readable"; + } else if (Files.isDirectory(path)) { + message += ": Path " + path + " is a directory"; + } else { + message += ": Unknown reason"; + } + } catch (Throwable th) { + message += ": Unknown reason; cannot examine filesystem: " + th.getMessage(); } throw new SQLiteCantOpenDatabaseException(message, e); } finally {