Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StackTraceCleaner does not handle infinite cause chains #747

Open
dsommerich opened this issue Aug 28, 2020 · 1 comment
Open

StackTraceCleaner does not handle infinite cause chains #747

dsommerich opened this issue Aug 28, 2020 · 1 comment
Labels
P4 not scheduled type=enhancement Make an existing feature better

Comments

@dsommerich
Copy link

Example

import com.google.common.truth.Truth;
import org.junit.jupiter.api.Test;

public class TruthTest {
    @Test
    void test() {
        Truth.assertThat(new EvilThrowable()).isSameInstanceAs(new RuntimeException());
    }

    static class EvilThrowable extends Throwable {
        @Override
        public synchronized Throwable getCause() {
            return new EvilThrowable();
        }
    }
}

This example does not terminate, it just spins forever.

I beleive this is because StackTraceCleaner does not implement any kind of hard limit (which is the only way I can think of of how to fix this).

I know this is a very specific edge case, it came up while trying to test code that does a similar thing (traverse a Throwable's causes) with a malicious/very broken implementation of a Throwable.

@cpovirk
Copy link
Member

cpovirk commented Aug 28, 2020

That is indeed pretty evil, thanks :)

As a workaround, you can pass -Dcom.google.common.truth.disable_stack_trace_cleaning=true to the JVM when running your test. However, I wonder if you'll then see a failure when your test runner tries to output the exception :) But maybe it will at least overflow the stack and terminate, rather than hanging?

We may try to have a look "eventually." I guess it's at least reasonably straightforward to set a hard limit, as you say.

@cpovirk cpovirk added P4 not scheduled type=enhancement Make an existing feature better labels Aug 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P4 not scheduled type=enhancement Make an existing feature better
Projects
None yet
Development

No branches or pull requests

2 participants