Extended the definition of database-already-closed
This is to handle a scenario where a thread's database operation is
blocked by another thread holding a transaction on the database object.
When the blocking thread subsequently closes the database, an exception
is thrown, which we want to correctly report in the metrics.
Bug: 154416935
Bug: 143216096
Test: ./gradlew :sqlite:sqlite-inspection:cC
Change-Id: I611bf85522fa7aa93b2afea24a8a2ba486602bdf
diff --git a/sqlite/sqlite-inspection/src/main/java/androidx/sqlite/inspection/DatabaseExtensions.java b/sqlite/sqlite-inspection/src/main/java/androidx/sqlite/inspection/DatabaseExtensions.java
index 61c2c60..d3d98b9 100644
--- a/sqlite/sqlite-inspection/src/main/java/androidx/sqlite/inspection/DatabaseExtensions.java
+++ b/sqlite/sqlite-inspection/src/main/java/androidx/sqlite/inspection/DatabaseExtensions.java
@@ -67,9 +67,17 @@
}
}
+ /**
+ * Note that this is best-effort as relies on Exception message parsing, which could break in
+ * the future.
+ * Use in the context where false negatives (more likely) and false positives (less likely
+ * due to the specificity of the message) are tolerable, e.g. to assign error codes where if
+ * it fails we will just send an 'unknown' error.
+ */
static boolean isAttemptAtUsingClosedDatabase(IllegalStateException exception) {
String message = exception.getMessage();
- return message != null
- && message.contains("attempt to re-open an already-closed object");
+ return message != null && (message.contains("attempt to re-open an already-closed object")
+ || message.contains(
+ "Cannot perform this operation because the connection pool has been closed"));
}
}