3.x: Workaround for FutureTask.toString + JDK 11 build #7173
+177
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Starting from JDK 10, the
FutureTask.toString
can now print the inner callable routine, which if somehow references the parentFutureTask
again, it leads toStackOverflowError
. This can happen in RxJava becauseAbstractDirectTask
andScheduledRunnable
store theFuture
object returned by the executor in a reference field that gets accessed by their defaulttoString
implementation.The fix is to define custom
toString
s that break this cycle. Note that we can't print the underlyingRunnable
either because that could also reference something in a circular manner. In addition, the release of therunner
Thread
marker has been moved closer to the exit of the wrappers which helps with the state determination and self-cancellation.To verify the fix works, a new GitHub Action has been added, targeting JDK 11 as the issue does not manifest itself under the main target JDK 8.
Resolves #7172