Skip to content

End greater than length error #61

@ghost

Description

Hi Tomas, I am running into this error sometimes:

Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: end is greater than length: 108 > 78
at org.fxmisc.richtext.EditableStyledDocument.ensureValidRange(EditableStyledDocument.java:380)
at org.fxmisc.richtext.EditableStyledDocument.ensureValidRange(EditableStyledDocument.java:365)
at org.fxmisc.richtext.EditableStyledDocument.setStyle(EditableStyledDocument.java:189)
at org.fxmisc.richtext.StyledTextArea.setStyle(StyledTextArea.java:512)

Here is what is happening.
I save my content as an HTML file. which sometimes generated empty styles or styles ranges that are invalid. I think this is a result of working with the text area. When I save my text area content, I get the styles, and save where they start and end.

When reading my saved files, I fetch this information back and reconstruct the text by creating rich text area with plain text, then creating the styles, then applying the styles.

In this process, probably due to my not so robust code, some styles are fetched at zero start and end, etc.

The error says style end is greater than length. I assume it is saying the style being applied as an end range that is longer than the document.

to avoid this error I check if the end value is larger than the text length, and take the smaller of them.

I am reporting this I guess as a case which you might find important to address -- when people like me (doing bad code) use your awesome code! :D
Thanks,
Maher

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions