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

3.x: Change how the cause of CompositeException is generated #6748

Merged
merged 3 commits into from
Dec 7, 2019

Conversation

akarnokd
Copy link
Member

@akarnokd akarnokd commented Dec 6, 2019

This PR changes how CompositeException.getCause creates a cause exception on demand. In 1.x and 2.x, the code tried to link up the various inner exceptions via their initCause, which was in on itself fishy as well as could lead to excessive memory usage.

Instead, the new code will present the inner exceptions as part of a formatted message, which in theory, should be still picked up by IDE exception listings and allow navigation:

Multiple exceptions (2)
|-- io.reactivex.rxjava3.exceptions.TestException: ex3
    at io.reactivex.rxjava3.exceptions.CompositeExceptionTest.nestedMultilineMessage(CompositeExceptionTest.java:341)
|-- io.reactivex.rxjava3.exceptions.TestException: ex4
    at io.reactivex.rxjava3.exceptions.CompositeExceptionTest.nestedMultilineMessage(CompositeExceptionTest.java:342)
  |-- io.reactivex.rxjava3.exceptions.CompositeException: 2 exceptions occurred. 
      at io.reactivex.rxjava3.exceptions.CompositeExceptionTest.nestedMultilineMessage(CompositeExceptionTest.java:337)
    |-- io.reactivex.rxjava3.exceptions.CompositeException.ExceptionOverview: 
        Multiple exceptions (2)
        |-- io.reactivex.rxjava3.exceptions.TestException: ex1
            at io.reactivex.rxjava3.exceptions.CompositeExceptionTest.nestedMultilineMessage(CompositeExceptionTest.java:335)
        |-- io.reactivex.rxjava3.exceptions.TestException: ex2
            at io.reactivex.rxjava3.exceptions.CompositeExceptionTest.nestedMultilineMessage(CompositeExceptionTest.java:336)

image

There are a few formatting conveniences:

  • If there is only one inner exception, the CompositeException's cause will be simply that exception. This can happen when the very same exception is aggregated into the composite and get deduplicated.
  • If an inner exception's message is multi-lined, the message and cause traces should be indented properly.
  • Reoccurring causes are not expanded over and over:
Multiple exceptions (2)
|-- io.reactivex.rxjava3.exceptions.TestException: ex1
    at io.reactivex.rxjava3.exceptions.CompositeExceptionTest.reoccurringException(CompositeExceptionTest.java:316)
  |-- io.reactivex.rxjava3.exceptions.TestException: ex0
      at io.reactivex.rxjava3.exceptions.CompositeExceptionTest.reoccurringException(CompositeExceptionTest.java:315)
|-- io.reactivex.rxjava3.exceptions.TestException: ex2
    at io.reactivex.rxjava3.exceptions.CompositeExceptionTest.reoccurringException(CompositeExceptionTest.java:319)
  |-- io.reactivex.rxjava3.exceptions.TestException: ex1
      at io.reactivex.rxjava3.exceptions.CompositeExceptionTest.reoccurringException(CompositeExceptionTest.java:316)
      |-- (cause not expanded again) io.reactivex.rxjava3.exceptions.TestException: ex0

Currently, only the first line of the stacktraces are shown because it can get quite long (and thus memory consuming) to list them all. Maybe a system parameter can be introduced to control the verbosity.

Fixes #6747

@akarnokd akarnokd added this to the 3.0 milestone Dec 6, 2019
@codecov
Copy link

codecov bot commented Dec 6, 2019

Codecov Report

Merging #6748 into 3.x will decrease coverage by 0.06%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##                3.x    #6748      +/-   ##
============================================
- Coverage     98.16%   98.09%   -0.07%     
  Complexity     6188     6188              
============================================
  Files           677      677              
  Lines         44619    44626       +7     
  Branches       6157     6161       +4     
============================================
- Hits          43800    43776      -24     
- Misses          292      309      +17     
- Partials        527      541      +14
Impacted Files Coverage Δ Complexity Δ
...activex/rxjava3/exceptions/CompositeException.java 100% <100%> (ø) 35 <0> (-1) ⬇️
...nternal/operators/observable/ObservableCreate.java 79.48% <0%> (-16.24%) 2% <0%> (ø)
...rnal/operators/flowable/FlowableFlatMapSingle.java 92.44% <0%> (-2.91%) 2% <0%> (ø)
...rnal/operators/observable/ObservableSwitchMap.java 91.57% <0%> (-2.11%) 3% <0%> (ø)
...ternal/operators/completable/CompletableMerge.java 95.94% <0%> (-1.36%) 2% <0%> (ø)
...rnal/operators/observable/ObservableObserveOn.java 98.69% <0%> (-1.31%) 3% <0%> (ø)
...perators/observable/ObservableMergeWithSingle.java 99.05% <0%> (-0.95%) 2% <0%> (ø)
.../operators/observable/ObservableCombineLatest.java 96.17% <0%> (-0.64%) 6% <0%> (ø)
...3/internal/operators/flowable/FlowableGroupBy.java 95.59% <0%> (-0.63%) 3% <0%> (ø)
...ternal/operators/observable/ObservableGroupBy.java 95.08% <0%> (-0.55%) 2% <0%> (ø)
... and 14 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1e29958...ae3c299. Read the comment docs.

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