本文整理了Java中java.lang.Throwable.getSuppressed()
方法的一些代码示例,展示了Throwable.getSuppressed()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Throwable.getSuppressed()
方法的具体详情如下:
包路径:java.lang.Throwable
类名称:Throwable
方法名:getSuppressed
[英]Returns the throwables suppressed by this.
[中]返回被此项抑制的可丢弃项。
代码示例来源:origin: org.assertj/assertj-core
private ShouldHaveSuppressedException(Throwable actual, Throwable expectedSuppressedException) {
super("%n" +
"Expecting:%n" +
" <%s>%n" +
"to have a suppressed exception with the following type and message:%n" +
" <%s> / <%s>%n" +
"but could not find any in actual's suppressed exceptions:%n" +
" <%s>.",
actual, expectedSuppressedException.getClass().getName(), expectedSuppressedException.getMessage(),
actual.getSuppressed());
}
代码示例来源:origin: joel-costigliola/assertj-core
private ShouldHaveSuppressedException(Throwable actual, Throwable expectedSuppressedException) {
super("%n" +
"Expecting:%n" +
" <%s>%n" +
"to have a suppressed exception with the following type and message:%n" +
" <%s> / <%s>%n" +
"but could not find any in actual's suppressed exceptions:%n" +
" <%s>.",
actual, expectedSuppressedException.getClass().getName(), expectedSuppressedException.getMessage(),
actual.getSuppressed());
}
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override public void serialize(Throwable e, JsonGenerator gen, SerializerProvider ser) throws IOException {
gen.writeStartObject();
writeException(e, gen);
if (e.getCause() != null)
gen.writeObjectField("cause", e.getCause());
if (!F.isEmpty(e.getSuppressed())) {
gen.writeArrayFieldStart("suppressed");
for (Throwable sup : e.getSuppressed())
gen.writeObject(sup);
gen.writeEndArray();
}
gen.writeEndObject();
}
};
代码示例来源:origin: apache/hive
@VisibleForTesting
static RuntimeException convertToSerializableSparkException(Throwable error) {
RuntimeException serializableThrowable = new RuntimeException(
error.getClass().getName() + ": " + Objects.toString(error.getMessage(), ""),
error.getCause() == null ? null : convertToSerializableSparkException(
error.getCause()));
serializableThrowable.setStackTrace(error.getStackTrace());
Arrays.stream(error.getSuppressed())
.map(JobResultSerializer::convertToSerializableSparkException)
.forEach(serializableThrowable::addSuppressed);
return serializableThrowable;
}
}
代码示例来源:origin: neo4j/neo4j
@Override
protected boolean matchesSafely( Throwable item )
{
return Arrays.equals( item.getSuppressed(), expectedSuppressedErrors );
}
代码示例来源:origin: apache/ignite
/**
* Collects suppressed exceptions from throwable and all it causes.
*
* @param t Throwable.
* @return List of suppressed throwables.
*/
public static List<Throwable> getSuppressedList(@Nullable Throwable t) {
List<Throwable> result = new ArrayList<>();
if (t == null)
return result;
do {
for (Throwable suppressed : t.getSuppressed()) {
result.add(suppressed);
result.addAll(getSuppressedList(suppressed));
}
} while ((t = t.getCause()) != null);
return result;
}
代码示例来源:origin: apache/ignite
/**
* Checks if passed throwable has given class in one of the suppressed exceptions.
*
* @param t Throwable to check (if {@code null}, {@code false} is returned).
* @param cls Class to check.
* @return {@code True} if one of the suppressed exceptions is an instance of passed class,
* {@code false} otherwise.
*/
public static boolean hasSuppressed(@Nullable Throwable t, @Nullable Class<? extends Throwable> cls) {
if (t == null || cls == null)
return false;
for (Throwable th : t.getSuppressed()) {
if (cls.isAssignableFrom(th.getClass()))
return true;
if (hasSuppressed(th, cls))
return true;
}
return false;
}
代码示例来源:origin: jenkinsci/jenkins
doPrintStackTrace(s, lower, t, prefix, encountered);
for (Throwable suppressed : t.getSuppressed()) {
s.append(prefix).append("Also: ");
doPrintStackTrace(s, suppressed, t, prefix + "\t", encountered);
代码示例来源:origin: org.assertj/assertj-core
public void assertHasNoSuppressedExceptions(AssertionInfo info, Throwable actual) {
assertNotNull(info, actual);
Throwable[] suppressed = actual.getSuppressed();
if (suppressed.length != 0) throw failures.failure(info, shouldHaveNoSuppressedExceptions(suppressed));
}
代码示例来源:origin: RuedigerMoeller/fast-serialization
@Override
public void writeObject(FSTObjectOutput out, Object toWrite, FSTClazzInfo clzInfo,
FSTClazzInfo.FSTFieldInfo referencedBy, int streamPosition) throws IOException {
Throwable t = (Throwable)toWrite;
out.writeStringUTF(t.getMessage());
StackTraceElement[] ste = t.getStackTrace();
out.writeObject(ste);
out.writeObject(t.getCause());
out.writeObject(t.getSuppressed());
}
代码示例来源:origin: joel-costigliola/assertj-core
public void assertHasNoSuppressedExceptions(AssertionInfo info, Throwable actual) {
assertNotNull(info, actual);
Throwable[] suppressed = actual.getSuppressed();
if (suppressed.length != 0) throw failures.failure(info, shouldHaveNoSuppressedExceptions(suppressed));
}
代码示例来源:origin: org.assertj/assertj-core
public void assertHasSuppressedException(AssertionInfo info, Throwable actual,
Throwable expectedSuppressedException) {
assertNotNull(info, actual);
checkNotNull(expectedSuppressedException, "The expected suppressed exception should not be null");
Throwable[] suppressed = actual.getSuppressed();
for (int i = 0; i < suppressed.length; i++) {
if (compareThrowable(suppressed[i], expectedSuppressedException)) return;
}
throw failures.failure(info, shouldHaveSuppressedException(actual, expectedSuppressedException));
}
代码示例来源:origin: reactor/reactor-core
@Test
public void whenIterableDelayErrorPublishersVoidCombinesErrors() {
Exception boom1 = new NullPointerException("boom1");
Exception boom2 = new IllegalArgumentException("boom2");
Iterable<Publisher<Void>> voidPublishers = Arrays.asList(
Mono.<Void>empty(),
Mono.<Void>error(boom1),
Mono.<Void>error(boom2));
StepVerifier.create(Mono.whenDelayError(voidPublishers))
.verifyErrorMatches(e -> e.getMessage().equals("Multiple exceptions") &&
e.getSuppressed()[0] == boom1 &&
e.getSuppressed()[1] == boom2);
}
代码示例来源:origin: reactor/reactor-core
private void printAndAssert(Throwable t, boolean checkForAssemblySuppressed) {
t.printStackTrace();
assertThat(t)
.isInstanceOf(IndexOutOfBoundsException.class)
.hasMessage("Source emitted more than one item");
if (!checkForAssemblySuppressed) {
assertThat(t).hasNoSuppressedExceptions();
}
else {
assertThat(t).satisfies(withSuppressed -> {
assertThat(withSuppressed.getSuppressed()).hasSize(1);
assertThat(withSuppressed.getSuppressed()[0])
.hasMessageStartingWith("\nAssembly trace from producer [reactor.core.publisher.MonoSingle] :")
.hasMessageEndingWith("Flux.single ⇢ reactor.guide.GuideTests.scatterAndGather(GuideTests.java:944)\n");
});
}
}
代码示例来源:origin: reactor/reactor-core
@Test
public void whenIterableDelayErrorCombinesErrors() {
Exception boom1 = new NullPointerException("boom1");
Exception boom2 = new IllegalArgumentException("boom2");
StepVerifier.create(Mono.zipDelayError(
Arrays.asList(Mono.just("foo"), Mono.<String>error(boom1), Mono.<String>error(boom2)),
Tuples.fn3()))
.verifyErrorMatches(e -> e.getMessage().equals("Multiple exceptions") &&
e.getSuppressed()[0] == boom1 &&
e.getSuppressed()[1] == boom2);
}
代码示例来源:origin: joel-costigliola/assertj-core
public void assertHasSuppressedException(AssertionInfo info, Throwable actual,
Throwable expectedSuppressedException) {
assertNotNull(info, actual);
checkNotNull(expectedSuppressedException, "The expected suppressed exception should not be null");
Throwable[] suppressed = actual.getSuppressed();
for (int i = 0; i < suppressed.length; i++) {
if (compareThrowable(suppressed[i], expectedSuppressedException)) return;
}
throw failures.failure(info, shouldHaveSuppressedException(actual, expectedSuppressedException));
}
代码示例来源:origin: reactor/reactor-core
@Test
public void addThrowableRace() throws Exception {
for (int i = 0; i < 10; i++) {
final int idx = i;
RaceTestUtils.race(
() -> Exceptions.addThrowable(ADD_THROWABLE, ExceptionsTest.this, new IllegalStateException("boomState" + idx)),
() -> Exceptions.addThrowable(ADD_THROWABLE, ExceptionsTest.this, new IllegalArgumentException("boomArg" + idx))
);
}
assertThat(addThrowable.getSuppressed())
.hasSize(20);
}
代码示例来源:origin: reactor/reactor-core
@Test
public void errorCallbackError() {
IllegalStateException err = new IllegalStateException("test");
FluxPeekFuseable<String> flux = new FluxPeekFuseable<>(
Flux.error(new IllegalArgumentException("bar")), null, null,
e -> { throw err; },
null, null, null, null);
AssertSubscriber<String> ts = AssertSubscriber.create();
flux.subscribe(ts);
ts.assertNoValues();
ts.assertError(IllegalStateException.class);
ts.assertErrorWith(e -> e.getSuppressed()[0].getMessage().equals("bar"));
}
代码示例来源:origin: reactor/reactor-core
@Test
public void sourceFactoryAndResourceCleanupThrow() {
RuntimeException sourceEx = new IllegalStateException("sourceFactory");
RuntimeException cleanupEx = new IllegalStateException("resourceCleanup");
Condition<? super Throwable> suppressingFactory = new Condition<>(
e -> {
Throwable[] suppressed = e.getSuppressed();
return suppressed != null && suppressed.length == 1 && suppressed[0] == sourceEx;
}, "suppressing <%s>", sourceEx);
Flux<String> test = new FluxUsing<>(() -> "foo",
o -> { throw sourceEx; },
s -> { throw cleanupEx; },
false);
StepVerifier.create(test)
.verifyErrorSatisfies(e -> assertThat(e)
.hasMessage("resourceCleanup")
.is(suppressingFactory));
}
代码示例来源:origin: prestodb/presto
@Test
public void testSuppressedException()
{
RuntimeException runtimeException = new RuntimeException();
Exception exception = new Exception();
Error error = new Error();
AutoCloseableCloser closer = AutoCloseableCloser.create();
// add twice to test self suppression handling
closer.register(failingCloseable(error));
closer.register(failingCloseable(error));
closer.register(failingCloseable(exception));
closer.register(failingCloseable(exception));
closer.register(failingCloseable(runtimeException));
closer.register(failingCloseable(runtimeException));
try {
closer.close();
fail("expected to fail");
}
catch (Throwable t) {
assertSame(t, runtimeException);
assertSame(t.getSuppressed()[0], exception);
assertSame(t.getSuppressed()[1], exception);
assertSame(t.getSuppressed()[2], error);
assertSame(t.getSuppressed()[3], error);
}
}
内容来源于网络,如有侵权,请联系作者删除!