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

TraceurException.appendTo crashes app #7

Open
kassim opened this issue Nov 27, 2017 · 0 comments
Open

TraceurException.appendTo crashes app #7

kassim opened this issue Nov 27, 2017 · 0 comments

Comments

@kassim
Copy link

kassim commented Nov 27, 2017

So your code in TraceurException is

    public Throwable appendTo(Throwable throwable) {
        Throwable t = throwable;
        while (t.getCause() != null) {
            t = t.getCause();

            // Won't be able to init the cause of this with self
            if (t == this) {
                return throwable;
            }

            if (logLevel == LogLevel.SHOW_ONLY_FIRST && t instanceof TraceurException) {
                return throwable;
            }
        }

        t.initCause(this);

        return throwable;
    }

but the code inside Throwable is

    public synchronized Throwable initCause(Throwable cause) {
        if (this.cause != this)
            throw new IllegalStateException("Can't overwrite cause with " +
                                            Objects.toString(cause, "a null"), this);
        if (cause == this)
            throw new IllegalArgumentException("Self-causation not permitted", this);
        this.cause = cause;
        return this;
    }

This means the appendTo function will cause an exception to be thrown if a Throwable's cause is ever found to be null.

Possible solution
while (t.getCause() != null) should be while (t.getCause() != null && t.getCause() != t) and wrap the t.initCause(this);with a check againstt.getCause()`'s nullability

I'll make a PR later with this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant