Exceptions { public static String collapseText(Throwable t) { return collapseText(t, false); }  static boolean isPrefixBoring(Throwable t); static RuntimeException propagate(Throwable throwable); @Deprecated static RuntimeException propagate(String msg, Throwable throwable); static RuntimeException propagateAnnotateIfWrapping(String msg, Throwable throwable); static RuntimeException propagateAnnotated(String msg, Throwable throwable); static void propagateIfInterrupt(Throwable throwable); static void propagateIfFatal(Throwable throwable); static boolean isFatal(Throwable throwable); static Predicate<Throwable> isFatalPredicate(); @SuppressWarnings("unchecked") static T getFirstThrowableOfType(Throwable from, Class<T> clazz); static Throwable getFirstThrowableMatching(Throwable from, Predicate<? super Throwable> filter); static Throwable getFirstInteresting(Throwable throwable); static Throwable collapse(Throwable source); static Throwable collapseIncludingAllCausalMessages(Throwable source); static Throwable collapse(Throwable source, boolean collapseCausalChain); static List<Throwable> getCausalChain(Throwable t); static boolean isSkippableInContext(Throwable e, Object... contexts); static String collapseText(Throwable t); static String collapseTextInContext(Throwable t, Object ...contexts); static String collapseTextIncludingAllCausalMessages(Throwable t); static RuntimeException propagate(Iterable<? extends Throwable> exceptions); static RuntimeException propagate(String prefix, Iterable<? extends Throwable> exceptions); static Throwable create(Iterable<? extends Throwable> exceptions); static RuntimeException create(@Nullable String prefix, Iterable<? extends Throwable> exceptions); @Beta static boolean isPrefixRequiredForMessageToMakeSense(Throwable t); static String getMessageWithAppropriatePrefix(Throwable t); static boolean isRootBoringClassNotFound(Exception e, String clazz); static final int MAX_COLLAPSE_RECURSIVE_DEPTH; }
@Test public void testCollapseIncludesRootCause() throws Exception { NullPointerException npe = new NullPointerException("simulated2"); IllegalStateException ise = new IllegalStateException("simulated1", npe); assertEquals(Exceptions.collapseText(ise), "simulated1: NullPointerException: simulated2"); }
@Test public void testCollapseDoesNotIncludeRootCauseTwiceIfAppendedUncollapsed() throws Exception { NullPointerException npe = new NullPointerException("simulated2"); IllegalStateException ise = new IllegalStateException("simulated1: "+npe, npe); assertEquals(Exceptions.collapseText(ise), "simulated1: java.lang.NullPointerException: simulated2"); }
@Test public void testCollapseDoesNotIncludeRootCauseTwiceIfAppendedCollapsed() throws Exception { NullPointerException npe = new NullPointerException("simulated2"); IllegalStateException ise = new IllegalStateException("simulated1: "+Exceptions.collapseText(npe), npe); assertEquals(Exceptions.collapseText(ise), "simulated1: NullPointerException: simulated2"); }
@Test public void testCollapseTextWhenExceptionMessageEmpty() throws Exception { String text = Exceptions.collapseText(new ExecutionException(new IllegalStateException())); Assert.assertNotNull(text); }
@Test public void testPrefixModificationRequired() throws Exception { Throwable t = new NoClassDefFoundError("sample"); Assert.assertEquals(Exceptions.collapseText(t), "Invalid java type: sample"); }
@Test public void testNestedPropWithMessage() { Throwable t; t = new IOException("1"); t = new org.apache.brooklyn.util.exceptions.PropagatedRuntimeException(t); t = new org.apache.brooklyn.util.exceptions.PropagatedRuntimeException("A", t); Assert.assertEquals(Exceptions.collapseText(t), "A: IOException: 1"); }
@Test public void testExec() { Throwable t; t = new IOException("1"); t = new java.util.concurrent.ExecutionException(t); Assert.assertEquals(Exceptions.collapseText(t), "IOException: 1"); }
@Test public void testNestedExecAndProp() { Throwable t; t = new IOException("1"); t = new org.apache.brooklyn.util.exceptions.PropagatedRuntimeException(t); t = new java.util.concurrent.ExecutionException(t); Assert.assertEquals(Exceptions.collapseText(t), "IOException: 1"); }
@Test public void testComplexJcloudsExample() { Throwable t; t = new IOException("POST https: t = new IllegalStateException("Not authorized to access cloud JcloudsLocation[aws-ec2:foo/aws-ec2@SEk63t8T]", t); t = new java.util.concurrent.ExecutionException(t); t = new org.apache.brooklyn.util.exceptions.PropagatedRuntimeException(t); t = new org.apache.brooklyn.util.exceptions.PropagatedRuntimeException("Error invoking start at EmptySoftwareProcessImpl{id=GVYo7Cth}", t); t = new java.util.concurrent.ExecutionException(t); t = new org.apache.brooklyn.util.exceptions.PropagatedRuntimeException(t); t = new java.util.concurrent.ExecutionException(t); t = new org.apache.brooklyn.util.exceptions.PropagatedRuntimeException(t); t = new java.util.concurrent.ExecutionException(t); t = new org.apache.brooklyn.util.exceptions.PropagatedRuntimeException(t); t = new org.apache.brooklyn.util.exceptions.PropagatedRuntimeException("Error invoking start at BasicApplicationImpl{id=fbihp1mo}", t); t = new java.util.concurrent.ExecutionException(t); String collapsed = Exceptions.collapseText(t); Assert.assertTrue(collapsed.contains("IOException"), collapsed); Assert.assertTrue(collapsed.matches(".*POST.*"), collapsed); Assert.assertFalse(collapsed.contains("Propagated"), collapsed); Assert.assertFalse(collapsed.matches(".*POST.*POST.*"), collapsed); }