question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Random crashes in GenericStyleArea.visibleParToAllParIndex

See original GitHub issue

Expected Behavior

Shouldn’t throw exception but return the index of the paragraph.

Actual Behavior

Sometimes when I call this method it reaches: throw new AssertionError("Unreachable code"); As much as I can tell the problem is that the element in the visibleParagraphs is the same as the one in the paragraphs but they are not the same reference therefore the search can’t find it. I have no idea how is this possible.

Reproducible Demo

Unfortunately I only have this rarely…

Environment info:

  • RichTextFX Version: 0.9.1
  • Operating System: Ubuntu 18.04 but happened in 16.04 too.
  • Java version: “1.8.0_181”

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
lhttjdrcommented, Dec 1, 2018

@Jugen Thank you for your great job at first. I write some test cases for this problem and make a pull request.

0reactions
JFormDesignercommented, Dec 21, 2018

@Jugen I have a fix for this issue in PR #795, which also fixes #788

Earlier today I had a look at #788 and later at this issue and noticed that both issues are related somehow to MaterializedListModification.trim(). It is in the stack of #788 and in Jugen’s comment in this issue. So used the tests from @lhttjdr in PR #790 to see what’s going on in trim() and why it may fail visibleParToAllParIndex.

The problem was that MaterializedListModification.trim(), which is invoked here, uses equals() to compare paragraphs and class Paragraph overrides equals() and returns true if paragraph text and styling is equal.

But this is not wanted because it keeps old outdated paragraphs and drops newly added paragraphs if the paragraph text and styling is equal.

The solution is to use a trim method that uses reference comparison instead of object comparison. Unfortunately there is no such method in ReactFX, so I copied the related methods to RichTextFX and modified them.

Below is some detailed information how I used println’s to see whats going on:

I’ve added println’s to the main constructor of class Paragraph:

System.out.println("PARA "+System.identityHashCode(this));

To GenericStyledArea.visibleParToAllParIndex():

System.out.println("vis  "+System.identityHashCode(visibleP));
for (int index = 0; index < getParagraphs().size(); index++) {
    System.out.println(" "+index+":  "+System.identityHashCode(getParagraph(index)));
}

and to GenericEditableStyledDocumentBase$ParagraphList.observeInputs():

for (...) {
    p(mod);
    mod = mod.trim();
    p(mod);
...
}

Here is p(mod):

private void p(MaterializedListModification<Paragraph<PS, SEG, S>> mod) {
    System.out.println("MOD from "+mod.getFrom());
    System.out.print("  added   "+mod.getAddedSize()+":");
    mod.getAdded().stream().forEach(p -> System.out.print("  "+System.identityHashCode(p)));
    System.out.println();
    System.out.print("  removed "+mod.getRemovedSize()+":");
    mod.getRemoved().stream().forEach(p -> System.out.print("  "+System.identityHashCode(p)));
    System.out.println();
}

When you run test get_first_visible_paragraph_index_with_all_blank_lines, which fails without the fix, you get following output:

PARA 1596606895
PARA 713924259
PARA 251759511
PARA 1764544288
MOD from 0
  added   3:  713924259  251759511  1764544288
  removed 1:  1596606895
MOD from 1
  added   2:  251759511  1764544288
  removed 0:
vis  1596606895
 0:  713924259
 1:  251759511
 2:  1764544288

You see that there are created four paragraphs. The first in the constructor of GenericEditableStyledDocumentBase. The other three are the three empty lines that the test adds to the text area.

Below is the modification before trim. 1596606895, which was created in the constructor, should be removed. Three new paragraphs should be added.

MOD from 0
  added   3:  713924259  251759511  1764544288
  removed 1:  1596606895

Below is the modification after “buggy” trim. So the first paragraphs from the “added” and from the “removed” lists was removed. IOW the paragraph 1596606895 stays in the list of paragraphs and is not replaced by 713924259, which causes the bugs in #777 and #788.

MOD from 1
  added   2:  251759511  1764544288
  removed 0:

And here is the output of visibleParToAllParIndex(). You see the visible paragraph is still at 1596606895, but 1596606895 is no longer in the list of paragraphs.

vis  1596606895
 0:  713924259
 1:  251759511
 2:  1764544288

And here is the output with fixed trim. The initial paragraph 1950984118 is removed and the visible paragraph is correctly at 1714800072.

PARA 1950984118
PARA 1714800072
PARA 2258300
PARA 1082323298
MOD from 0
  added   3:  1714800072  2258300  1082323298
  removed 1:  1950984118
MOD from 0
  added   3:  1714800072  2258300  1082323298
  removed 1:  1950984118
vis  1714800072
 0:  1714800072
 1:  2258300
 2:  1082323298

In the above case, the new trim does nothing and you might have the impression that we could remove it at all. This is not true. E.g. run JavaKeywordsDemo, and enter some text. You’ll notice modifications that change from e.g. 20 paragraphs to 0 paragraphs, which is caused by codeArea.setStyleSpans(...):

MOD from 0
  added   20:  847350689  785255895  7744232  2068574306  900904319  1479772899  293092209  790259324  503986205  1051951086  1858103546  311810776  1569772103  2021235220  353614425  695001401  1924467897  1177059777  1593099859  485837059
  removed 20:  847350689  785255895  7744232  2068574306  900904319  1479772899  293092209  790259324  503986205  1051951086  1858103546  311810776  1569772103  2021235220  353614425  695001401  1924467897  1177059777  1593099859  485837059
MOD from 20
  added   0:
  removed 0:
Read more comments on GitHub >

github_iconTop Results From Across the Web

Random crashes since April. - Microsoft Community
Getting random crashes at random times (sometimes minutes after windows loads) since around April on a windows 10 pc (installed on internal ...
Read more >
Modern Warfare 2 - How To Fix Random Crashes on PC
For more information, follow this guide:https://www.techy.how/tutorials/modern-warfare-2-fix- random - crash -pcA short tutorial on how to ...
Read more >
Fix Valorant Crashing | Launch, Random Crashes & Instability
Trying to play Valorant, but it keeps randomly crashing or crashing on launch? This video covers a few common issues that could be...
Read more >
Random crashes during gameplay - Support - Larian Studios
Try exiting out of the Steam client, if applicable, and starting the game directly from the '..\SteamApps\common\Baldurs Gate 3\bin' folder, by right clicking ......
Read more >
KNOWN ISSUE: Crashing at Random, Due to GPU-Related ...
Game crashing! Crash to desktop joining new and existing missions. Long load time or crash. Game keep crashing at random moment. Game Crashes...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found