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

End greater than length error #61

Closed
ghost opened this issue Jun 3, 2014 · 3 comments
Closed

End greater than length error #61

ghost opened this issue Jun 3, 2014 · 3 comments

Comments

@ghost
Copy link

ghost commented Jun 3, 2014

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

@TomasMikula
Copy link
Member

Hi Maher,

I don't understand what you are suggesting me to do. If you are trying to assign style beyond the length of the text, which is illegal, you get an IllegalArgumentException, which I find appropriate. What else should RichTextFX do?

@ghost
Copy link
Author

ghost commented Jun 3, 2014

Hi Tomas, What I am suggesting is to probably make RichTextFX automatically applies the smallest of style end value or text length. now that I think of it. Yes, it does make sense that it is done this way. Otherwise, one would not know what code is doing if it fixes things on its own.

@TomasMikula
Copy link
Member

Exactly. If something is wrong, then fail as soon as possible.

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

No branches or pull requests

1 participant