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

Class SuppressingSuppressor

output/java_guava/1.4.17/Closer.java:276–307  ·  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

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

Callers

nothing calls this directly

Calls 1

getAddSuppressedMethod · 0.95

Tested by

no test coverage detected