private static void addSuppressed(Exception exception, List<Throwable> suppressedExceptions) { for (Throwable suppressedException : suppressedExceptions) { if (exception != suppressedException) { exception.addSuppressed(suppressedException); } } } }
private static void addSuppressed(Exception exception, List<Throwable> suppressedExceptions) { for (Throwable suppressedException : suppressedExceptions) { if (exception != suppressedException) { exception.addSuppressed(suppressedException); } } } }
public void addSuppressed(Throwable throwable) { checkState(exception != null, "exception is null"); checkArgument(throwable != null, "throwable is null"); exception.addSuppressed(throwable); } }
@SuppressWarnings("unchecked") void addRollbackExceptions(Exception ex) { List<Throwable> list = (List<Throwable>) getResource(RB_EX_KEY); if (list != null) { for (Throwable throwable : list) { ex.addSuppressed(throwable); } } }
/** * @param err Error. */ private void addError(Throwable err) { Exception ex = errCollector.get(); if (ex == null) { Exception compound = new IgniteCheckedException("Compound exception for CountDownFuture."); ex = errCollector.compareAndSet(null, compound) ? compound : errCollector.get(); } assert ex != null; ex.addSuppressed(err); } }
private RuntimeException handleSqlException(Exception e) { try { close(); } catch (Exception closeException) { // Self-suppression not permitted if (e != closeException) { e.addSuppressed(closeException); } } return new PrestoException(JDBC_ERROR, e); } }
private void delegateToAllChildren(RequestLogLine requestLogLine, RequestLogLineConsumer consumer) throws IOException { Exception exception = null; for (RequestLogger logger : loggers) { try { consumer.accept(logger, requestLogLine); } catch (Exception e) { if (exception == null) { exception = e; } else { exception.addSuppressed(e); } } } if (exception != null) { Throwables.propagateIfInstanceOf(exception, IOException.class); throw Throwables.propagate(exception); } }
private void closeAndThrow( Exception e ) { if ( pagedFile != null ) { try { closeStoreFile(); } catch ( IOException failureToClose ) { // Not really a suppressed exception, but we still want to throw the real exception, e, // but perhaps also throw this in there or convenience. e.addSuppressed( failureToClose ); } } throwIfUnchecked( e ); throw new RuntimeException( e ); }
/** * @param ex Exception holder. * @param e Exception. */ private void onException(AtomicReference<Exception> ex, Exception e) { if (!ex.compareAndSet(null, e)) ex.get().addSuppressed(e); } }
/** * @param exHldr Exception holder. * @param ex Exception. */ private void addException(AtomicReference<Exception> exHldr, Exception ex) { if (exHldr.get() != null || !exHldr.compareAndSet(null, ex)) exHldr.get().addSuppressed(ex); }
/** * Helper method that encapsulate logic in trying to close output generator * in case of failure; useful mostly in forcing flush()ing as otherwise * error conditions tend to be hard to diagnose. However, it is often the * case that output state may be corrupt so we need to be prepared for * secondary exception without masking original one. * * @since 2.8 */ public static void closeOnFailAndThrowAsIOE(JsonGenerator g, Exception fail) throws IOException { /* 04-Mar-2014, tatu: Let's try to prevent auto-closing of * structures, which typically causes more damage. */ g.disable(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT); try { g.close(); } catch (Exception e) { fail.addSuppressed(e); } throwIfIOE(fail); throwIfRTE(fail); throw new RuntimeException(fail); }
/** * Tests LOG4J2-934. */ @Test public void testCircularSuppressedNestedException() { final Exception e1 = new Exception(); final Exception e2 = new Exception(e1); e2.addSuppressed(e1); e1.addSuppressed(e2); LogManager.getLogger().error("Error", e1); }
/** * Tests LOG4J2-934. */ @Test public void testCircularSuppressedExceptions() { final Exception e1 = new Exception(); final Exception e2 = new Exception(); e2.addSuppressed(e1); e1.addSuppressed(e2); LogManager.getLogger().error("Error", e1); }
private void finalizeTask(CeTask task, Profiler ceProfiler, CeActivityDto.Status status, @Nullable CeTaskResult taskResult, @Nullable Throwable error) { try { queue.remove(task, status, taskResult, error); } catch (Exception e) { if (error != null) { e.addSuppressed(error); } LOG.error(format("Failed to finalize task with uuid '%s' and persist its state to db", task.getUuid()), e); } finally { // finalize stopLogProfiler(ceProfiler, status); callListeners(t -> t.onEnd(task, status, taskResult, error)); } }
/** * Helper method that encapsulate logic in trying to close output generator * in case of failure; useful mostly in forcing flush()ing as otherwise * error conditions tend to be hard to diagnose. However, it is often the * case that output state may be corrupt so we need to be prepared for * secondary exception without masking original one. * * @since 2.8 */ public static void closeOnFailAndThrowAsIOE(JsonGenerator g, Exception fail) throws IOException { /* 04-Mar-2014, tatu: Let's try to prevent auto-closing of * structures, which typically causes more damage. */ g.disable(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT); try { g.close(); } catch (Exception e) { fail.addSuppressed(e); } throwIfIOE(fail); throwIfRTE(fail); throw new RuntimeException(fail); }
@Test public void testCauseSuppressedExceptions() { final Exception cause = new Exception("Nested exception"); cause.addSuppressed(new IOException("Suppressed #1")); cause.addSuppressed(new IOException("Suppressed #2")); LogManager.getLogger().error("Error", new Exception(cause)); final ThrowableProxy proxy = new ThrowableProxy(new Exception("Root exception", cause)); final String extendedStackTraceAsString = proxy.getExtendedStackTraceAsString("same suffix"); assertTrue(extendedStackTraceAsString.contains("\tSuppressed: java.io.IOException: Suppressed #1")); assertTrue(extendedStackTraceAsString.contains("\tSuppressed: java.io.IOException: Suppressed #1")); }
@Nullable private Exception getDeadlockedThreadsException() { final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); final long[] deadlockedThreadIds = threadMXBean.findDeadlockedThreads(); if (deadlockedThreadIds == null) { return null; } Exception deadlockException = new Exception("Deadlocked threads:"); for (long deadlockedThreadId : deadlockedThreadIds) { ThreadInfo threadInfo = threadMXBean.getThreadInfo(deadlockedThreadId); Exception threadException = new Exception(threadInfo.getThreadName() + " at " + threadInfo.getLockName()); threadException.setStackTrace(threadInfo.getStackTrace()); deadlockException.addSuppressed(threadException); } return deadlockException; }
@Test public void testSuppressedExceptions() { final Exception e = new Exception("Root exception"); e.addSuppressed(new IOException("Suppressed #1")); e.addSuppressed(new IOException("Suppressed #2")); LogManager.getLogger().error("Error", e); final ThrowableProxy proxy = new ThrowableProxy(e); final String extendedStackTraceAsString = proxy.getExtendedStackTraceAsString("same suffix"); assertTrue(extendedStackTraceAsString.contains("\tSuppressed: java.io.IOException: Suppressed #1")); assertTrue(extendedStackTraceAsString.contains("\tSuppressed: java.io.IOException: Suppressed #1")); }
private StoreLocker tryLockStore( FileSystemAbstraction fileSystem ) { StoreLocker storeLocker = new GlobalStoreLocker( fileSystem, this.databaseLayout.getStoreLayout() ); try { storeLocker.checkLock(); } catch ( Exception e ) { try { storeLocker.close(); } catch ( IOException ce ) { e.addSuppressed( ce ); } throw e; } return storeLocker; }
public static class TaskNotRunnableException extends RuntimeException { public TaskNotRunnableException(String message) { super(message); } }