Skip to content

NPE in CompositeException when nested throws on initCause #3599

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

Closed
emilianogc opened this issue Jan 5, 2016 · 4 comments
Closed

NPE in CompositeException when nested throws on initCause #3599

emilianogc opened this issue Jan 5, 2016 · 4 comments
Labels

Comments

@emilianogc
Copy link

The following example throws a NPE

public class Test {
    public static class CustomException extends Throwable {
        public synchronized Throwable initCause(Throwable cause) {
            throw new UnsupportedOperationException();
        }
    }
    public static void main(String ... args) {
        new CompositeException(Arrays.asList(
                new CustomException(),
                new UnsupportedOperationException(),
                new IllegalStateException())).getCause();
    }
}

The stacktrace is the following:

Exception in thread "main" java.lang.NullPointerException
    at rx.exceptions.CompositeException.getCause(CompositeException.java:126)
    at Test.main(Test.java:18)
@akarnokd akarnokd added the Bug label Jan 5, 2016
@emilianogc
Copy link
Author

Also, when created with two exceptions with the first containing a cause, the second exception will not be present in the resulting chain.

Is there a plan to move to java7? In that case this same feature can be implemented using Throwable#addSupressed.

@akarnokd
Copy link
Member

akarnokd commented Jan 6, 2016

Hi. 1.x won't move beyond Java 6. I've looked at the crashing code but don't know how to fix it as I don't understand the logic in there exactly.

@emilianogc
Copy link
Author

Any help on what should be the expected behaviour for getCause so I can propose a fix? The test doesn't really show what's the contract for CompositeException#getCause.

@akarnokd
Copy link
Member

akarnokd commented Feb 9, 2016

Closing via #3620

@akarnokd akarnokd closed this as completed Feb 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants