MCPcopy Create free account
hub / github.com/antlr/codebuff / SuppressingSuppressor

Class SuppressingSuppressor

output/java_guava/1.4.19/Closer.java:275–306  ·  view source on GitHub ↗

Suppresses exceptions by adding them to the exception that will be thrown using JDK7's addSuppressed(Throwable) mechanism.

Source from the content-addressed store, hash-verified

273 */
274
275 @VisibleForTesting
276 static final class SuppressingSuppressor implements Suppressor {
277 static final SuppressingSuppressor INSTANCE = new SuppressingSuppressor();
278
279 static boolean isAvailable() {
280 return addSuppressed != null;
281 }
282
283
284 static final Method addSuppressed = getAddSuppressed();
285 private static Method getAddSuppressed() {
286 try {
287 return Throwable.class.getMethod("addSuppressed", Throwable.class);
288 } catch (Throwable e) {
289 return null;
290 }
291 }
292
293 @Override
294 public void suppress(Closeable closeable, Throwable thrown, Throwable suppressed) {
295 // ensure no exceptions from addSuppressed
296 if (thrown == suppressed) {
297 return;
298 }
299 try {
300 addSuppressed.invoke(thrown, suppressed);
301 } catch (Throwable e) {
302 // if, somehow, IllegalAccessException or another exception is thrown, fall back to logging
303 LoggingSuppressor.INSTANCE.suppress(closeable, thrown, suppressed);
304 }
305 }
306 }
307}

Callers

nothing calls this directly

Calls 1

getAddSuppressedMethod · 0.95

Tested by

no test coverage detected