Fix OutOfMemoryError when using TailTipWidget (fixes #974) #975
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.
Issue #974 (
OutOfMemoryError
when enabling aTailTipWidget
in a terminal of size0x0
) is caused by the newStatus.getBorderString
method, which tries to create a string that's'─'
repeated2_147_483_646
times.The underlying reason why we even get into that situation is
Display.resize
, which interprets a size of0x0
(which happens e.g. in a detached container) as1x(Integer.MAX_VALUE-1)
. I understand that zero values might be problematic, and an old issue that is linked to that change mentions some arithmetic exception due to a division by zero. I'm not sure, however, whyInteger.MAX_VALUE - 1
was chosen. My guess is that a value of1
(same as for the rows) is safer, and some unsystematic tests using existing applications didn't reveal any issues (e.g. when resizing).I also added an additional check in
Status.update
to check if we have more than one row before even starting to draw anything. If there is only one row, there is no space for a border and text below it. This change in and of itself would already be sufficient, I believe. So if thatInteger.MAX_VALUE - 1
serves a function, it can be restored.Finally, I added a small unit test reproducing the problem in issue #974, which passes now with the added fixes.