private void throwTimeoutException(StatementThread thread) throws Exception { Exception exception = new Exception(String.format( "test timed out after %d milliseconds", fTimeout)); exception.setStackTrace(thread.getRecordedStackTrace()); throw exception; }
private static void truncateStackTrace(Exception exception, Class<?> callingClass) { StackTraceElement[] original = exception.getStackTrace(); int keep = 0; while (keep < original.length && !original[keep].getClassName().equals(callingClass.getName())) { keep++; } exception.setStackTrace(Arrays.copyOf(original, keep)); } }
private Exception newPlainException(Exception e) { String type = e.getClass().getName(); if(type.startsWith("java.") || type.startsWith("javax.")) { return e; } else { Exception result = new Exception(e.getMessage()); result.setStackTrace(e.getStackTrace()); return result; } }
@Override public final Exception componentInstanceNotAvailable(final InterceptorContext interceptorContext) { final Exception result = new Exception(String.format(getLoggingLocale(), componentInstanceNotAvailable$str(), interceptorContext)); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String failToObtainLock = "WFLYEJB0228: EJB 3.1 FR 4.3.14.1 concurrent access timeout on %s - could not obtain lock within %s %s";
@Override public final Exception iterationCountOutOfRange(final String iteration) { final Exception result = new Exception(String.format(getLoggingLocale(), iterationCountOutOfRange$str(), iteration)); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String saltWrongLength = "WFLYSEC0044: Salt has to be exactly 8 characters long.";
@Override public final Exception encryptionDirectoryDoesNotExist(final String directory) { final Exception result = new Exception(String.format(getLoggingLocale(), encryptionDirectoryDoesNotExist$str(), directory)); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String cannotCreateEncryptionDirectory = "WFLYSEC0042: Cannot create encryption directory %s";
@Override public final Exception keyStoreNotWritable(final String keystoreURL) { final Exception result = new Exception(String.format(getLoggingLocale(), keyStoreNotWritable$str(), keystoreURL)); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String keyStorePasswordNotSpecified = "WFLYSEC0039: Keystore password has to be specified.";
@Override public final Exception keyStoreDoesnotExistWithExample(final String keystoreURL, final String keystoreURLExample) { final Exception result = new Exception(String.format(getLoggingLocale(), keyStoreDoesnotExistWithExample$str(), keystoreURL, keystoreURLExample)); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String keyStoreNotWritable = "WFLYSEC0038: Keystore [%s] is not writable or not a file.";
@Override public final Exception keyStorePasswordNotSpecified() { final Exception result = new Exception(String.format(getLoggingLocale(), keyStorePasswordNotSpecified$str())); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String encryptionDirectoryDoesNotExist = "WFLYSEC0041: Encryption directory is not a directory or doesn't exist. (%s)";
@Override public final Exception cannotCreateEncryptionDirectory(final String directory) { final Exception result = new Exception(String.format(getLoggingLocale(), cannotCreateEncryptionDirectory$str(), directory)); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String iterationCountOutOfRange = "WFLYSEC0043: Iteration count has to be within 1 - 2147483647, but it is %s.";
@Override public final Exception saltWrongLength() { final Exception result = new Exception(String.format(getLoggingLocale(), saltWrongLength$str())); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String securityVaultException = "WFLYSEC0045: Exception encountered:";
@Override public final Exception securityVaultException(final SecurityVaultException cause) { final Exception result = new Exception(String.format(getLoggingLocale(), securityVaultException$str()), cause); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String vaultAliasNotSpecified = "WFLYSEC0046: Vault alias has to be specified.";
@Override public final Exception vaultAliasNotSpecified() { final Exception result = new Exception(String.format(getLoggingLocale(), vaultAliasNotSpecified$str())); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String vaultAttributeCreateDisplay = "WFLYSEC0047: Secured attribute value has been stored in Vault.\nPlease make note of the following:\n********************************************\nVault Block:%s\nAttribute Name:%s\nConfiguration should be done as follows:\n%s\n********************************************";
private Exception createTimeoutException(Thread thread) { StackTraceElement[] stackTrace = thread.getStackTrace(); final Thread stuckThread = lookForStuckThread ? getStuckThread(thread) : null; Exception currThreadException = new TestTimedOutException(timeout, timeUnit); if (stackTrace != null) { currThreadException.setStackTrace(stackTrace); thread.interrupt(); } if (stuckThread != null) { Exception stuckThreadException = new Exception("Appears to be stuck in thread " + stuckThread.getName()); stuckThreadException.setStackTrace(getStackTrace(stuckThread)); return new MultipleFailureException( Arrays.<Throwable>asList(currThreadException, stuckThreadException)); } else { return currThreadException; } }
@Nullable private Exception getStuckThreadException(Thread mainThread) { final Thread stuckThread = getStuckThread(mainThread); if (stuckThread == null) { return null; } Exception stuckThreadException = new Exception("Appears to be stuck in thread " + stuckThread.getName()); stuckThreadException.setStackTrace(getStackTrace(stuckThread)); return stuckThreadException; }
private static <T extends Exception> T setExceptionDetails(final T exception, final ForeignExceptionMessage eem) { final GenericExceptionMessage gem = eem.getGenericException(); final StackTraceElement[] trace = toStackTrace(gem.getTraceList()); exception.setStackTrace(trace); return exception; }
@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; }
@GwtIncompatible // lazyStackTrace private void doTestLazyStackTraceFallback() { assertFalse(lazyStackTraceIsLazy()); Exception e = new Exception(); assertThat(lazyStackTrace(e)).containsExactly((Object[]) e.getStackTrace()).inOrder(); try { lazyStackTrace(e).set(0, null); fail(); } catch (UnsupportedOperationException expected) { } e.setStackTrace(new StackTraceElement[0]); assertThat(lazyStackTrace(e)).isEmpty(); }
private Exception createTimeoutException(Thread thread) { StackTraceElement[] stackTrace = thread.getStackTrace(); Exception currThreadException = new TestTimedOutException(timeout, timeUnit); if (stackTrace != null) { currThreadException.setStackTrace(stackTrace); thread.interrupt(); } Exception stuckThreadException = getStuckThreadException(thread); Exception deadlockException = getDeadlockedThreadsException(); if (stuckThreadException != null || deadlockException != null) { List<Throwable> exceptions = Stream .of(currThreadException, stuckThreadException, deadlockException) .filter(Objects::nonNull) .collect(Collectors.toList()); return new MultipleFailureException(exceptions); } else { return currThreadException; } }
@GwtIncompatible // lazyStackTrace(Throwable) public void testLazyStackTrace() { Exception e = new Exception(); StackTraceElement[] originalStackTrace = e.getStackTrace(); assertThat(lazyStackTrace(e)).containsExactly((Object[]) originalStackTrace).inOrder(); try { lazyStackTrace(e).set(0, null); fail(); } catch (UnsupportedOperationException expected) { } // Now we test a property that holds only for the lazy implementation. if (!lazyStackTraceIsLazy()) { return; } e.setStackTrace(new StackTraceElement[0]); assertThat(lazyStackTrace(e)).containsExactly((Object[]) originalStackTrace).inOrder(); }