Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,18 @@ private static String getRealThreadName() {

private static String getStackTraceAsString(final Throwable throwable) {
final StringWriter stringWriter = new StringWriter();
throwable.printStackTrace(new PrintWriter(stringWriter));
try {
throwable.printStackTrace(new PrintWriter(stringWriter));
} catch (RuntimeException e) {
if (stringWriter.getBuffer().length() == 0) {
stringWriter.append(throwable.getClass().getName());
}
stringWriter
.append(System.lineSeparator())
.append("[Unable to render the complete stack trace: ")
.append(e.getClass().getName())
.append(']');
}
return stringWriter.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.opentest4j.AssertionFailedError;
import org.opentest4j.ValueWrapper;

import java.io.IOException;
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.util.List;
Expand All @@ -48,6 +49,10 @@
import static io.qameta.allure.util.ResultsUtils.createTmsLink;
import static io.qameta.allure.util.ResultsUtils.getLinkTypePatternPropertyName;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

@ExtendWith(SystemPropertyExtension.class)
class ResultsUtilsTest {

Expand Down Expand Up @@ -399,6 +404,27 @@ void shouldExtractActualAndExpectedFromOpenTest4jAssertionFailedError() {
assertThat(details.getExpected()).startsWith("expected value (");
}

@Test
@Issue("1035")
void shouldCreateStatusDetailsWhenNestedStackTraceCannotBeRendered() {
final RuntimeException cause = mock(RuntimeException.class);
when(cause.getSuppressed()).thenReturn(null);
final AssertionFailedError error = assertThrows(
AssertionFailedError.class,
() -> assertThrows(IOException.class, () -> {
throw cause;
})
);

final StatusDetails details = getStatusDetailsFor("malformed nested throwable", error);

assertThat(details.getMessage()).startsWith("Unexpected exception type thrown");
assertThat(details.getTrace())
.contains(AssertionFailedError.class.getName())
.contains("Caused by:")
.contains("[Unable to render the complete stack trace: java.lang.NullPointerException]");
}

@Test
void shouldUseOpenTest4jValueWrapperToString() {
final AssertionFailedError error = new AssertionFailedError(
Expand Down
Loading