summaryrefslogtreecommitdiffstats
path: root/dalvik
diff options
context:
space:
mode:
authorBrian Carlstrom <bdc@google.com>2010-11-08 10:27:11 -0800
committerBrian Carlstrom <bdc@google.com>2010-11-08 10:27:11 -0800
commitb81e1d9da6a4b039ffa55618fcccb013d3116261 (patch)
tree368a5e42634c99d260489efd2b24567c6da46bfd /dalvik
parent30a77f316c03906ca59d6ebe5b6c7f0ff734aadb (diff)
downloadlibcore-b81e1d9da6a4b039ffa55618fcccb013d3116261.zip
libcore-b81e1d9da6a4b039ffa55618fcccb013d3116261.tar.gz
libcore-b81e1d9da6a4b039ffa55618fcccb013d3116261.tar.bz2
Add CloseGuard.Reporter interface to allow customization of warnings
This will be paired with a new implementation in StrictMode to allow more sophisticated reporting. Change-Id: I17668b5db333c4c9b7280ac0de5dc8d9ba1aab59
Diffstat (limited to 'dalvik')
-rw-r--r--dalvik/src/main/java/dalvik/system/CloseGuard.java44
1 files changed, 42 insertions, 2 deletions
diff --git a/dalvik/src/main/java/dalvik/system/CloseGuard.java b/dalvik/src/main/java/dalvik/system/CloseGuard.java
index b727f72..114bea1 100644
--- a/dalvik/src/main/java/dalvik/system/CloseGuard.java
+++ b/dalvik/src/main/java/dalvik/system/CloseGuard.java
@@ -118,6 +118,11 @@ public final class CloseGuard {
private static boolean ENABLED = true;
/**
+ * Hook for customing how CloseGuard issues are reported.
+ */
+ private static Reporter REPORTER = new DefaultReporter();
+
+ /**
* Returns a CloseGuard instance. If CloseGuard is enabled, {@code
* #open(String)} can be used to set up the instance to warn on
* failure to close. If CloseGuard is disabled, a non-null no-op
@@ -138,6 +143,24 @@ public final class CloseGuard {
ENABLED = enabled;
}
+ /**
+ * Used to replace default Reporter used to warn of CloseGuard
+ * violations. Must be non-null.
+ */
+ public static void setReporter(Reporter reporter) {
+ if (reporter == null) {
+ throw new NullPointerException("reporter == null");
+ }
+ REPORTER = reporter;
+ }
+
+ /**
+ * Returns non-null CloseGuard.Reporter.
+ */
+ public static Reporter getReporter() {
+ return REPORTER;
+ }
+
private CloseGuard() {}
/**
@@ -187,7 +210,24 @@ public final class CloseGuard {
("A resource was acquired at attached stack trace but never released. "
+ "See java.io.Closeable for information on avoiding resource leaks.");
- Logger.getLogger(CloseGuard.class.getName())
- .log(Level.WARNING, message, allocationSite);
+ REPORTER.report(message, allocationSite);
+ }
+
+ /**
+ * Interface to allow customization of reporting behavior.
+ */
+ public static interface Reporter {
+ public void report (String message, Throwable allocationSite);
+ }
+
+ /**
+ * Default Reporter which uses a Logger to report CloseGuard
+ * violations.
+ */
+ private static final class DefaultReporter implements Reporter {
+ public void report (String message, Throwable allocationSite) {
+ Logger.getLogger(CloseGuard.class.getName())
+ .log(Level.WARNING, message, allocationSite);
+ }
}
}