summaryrefslogtreecommitdiffstats
path: root/dalvik
diff options
context:
space:
mode:
authorBrian Carlstrom <bdc@google.com>2010-11-08 10:42:15 -0800
committerAndroid Git Automerger <android-git-automerger@android.com>2010-11-08 10:42:15 -0800
commit7cf29130b51703f60cb498902f3dfa9622b0afe3 (patch)
treef37ec50abd4419750763a8d91261fad86c2b0c98 /dalvik
parentcc5fb4b5c651fe453d1319f8c47da91a65ee436c (diff)
parentb81e1d9da6a4b039ffa55618fcccb013d3116261 (diff)
downloadlibcore-7cf29130b51703f60cb498902f3dfa9622b0afe3.zip
libcore-7cf29130b51703f60cb498902f3dfa9622b0afe3.tar.gz
libcore-7cf29130b51703f60cb498902f3dfa9622b0afe3.tar.bz2
am b81e1d9d: Add CloseGuard.Reporter interface to allow customization of warnings
* commit 'b81e1d9da6a4b039ffa55618fcccb013d3116261': Add CloseGuard.Reporter interface to allow customization of warnings
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);
+ }
}
}