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

Null Decoration Crash #343

Closed
tonydroy opened this issue Jun 22, 2024 · 1 comment · Fixed by #346
Closed

Null Decoration Crash #343

tonydroy opened this issue Jun 22, 2024 · 1 comment · Fixed by #346

Comments

@tonydroy
Copy link

tonydroy commented Jun 22, 2024

If you delete the text of a simple document, save, and then get the document, the document's decoration list is empty. Then an attempt to open the document results in an exception,

Exception in thread "JavaFX Application Thread" java.lang.NullPointerException: Cannot invoke "com.gluonhq.richtextarea.model.ParagraphDecoration.hasTableDecoration()" because "prevDecoration" is null
        at com.gluonhq.richtextarea.model.PieceTable.getParagraphDecorationAtCaret(PieceTable.java:359)
        at com.gluonhq.richtextarea.RichTextAreaSkin.setup(RichTextAreaSkin.java:740)
        at com.gluonhq.richtextarea.RichTextAreaSkin.lambda$new$24(RichTextAreaSkin.java:418)
        at javafx.base@22/com.sun.javafx.binding.ExpressionHelper$SingleChange.fireValueChangedEvent(ExpressionHelper.java:192)
        at javafx.base@22/com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:91)
        at javafx.base@22/javafx.beans.property.ObjectPropertyBase.fireValueChangedEvent(ObjectPropertyBase.java:106)
        at javafx.base@22/javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:113)
        at javafx.base@22/javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:147)
        at com.gluonhq.richtextarea.viewmodel.RichTextAreaViewModel.setDocument(RichTextAreaViewModel.java:286)
        at com.gluonhq.richtextarea.viewmodel.RichTextAreaViewModel.lambda$open$8(RichTextAreaViewModel.java:777)
        at javafx.graphics@22/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:456)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
        at javafx.graphics@22/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:455)
        at javafx.graphics@22/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)

which originates from PieceTable.jave:359. I have attached a minimal file to exhibit the problem: Start the program; use the editor to delete the short text; press the buttons in order: save, get doc, open doc. The exception occurs at the last stage.

I believe this issue first arose after changes #322. This issue restates my #333, now as applied to the Rich Text Area as of 6/22/24, and ideally in a form that will be more useful to you!

NullDecorationTest.zip

@jperedadnr
Copy link
Collaborator

I can reproduce the issue:

initialDoc has a default decoration:

Document{text='this is a test', decorationList={
 - DecorationModel{start=0, length=14, decoration=TDec{fcolor=black, bcolor=transparent, font['System', 14.0, R, N], S:false, U:false, URL:null}, paragraphDecoration=PDec{s=0.0, a=LEFT, [0.0, 0.0, 0.0, 0.0], i=0, type=NONE, TabDec[0 x 0] - []}}
}, caretPosition=0}

but when removing the text and saving it doesn't have it anymore:

Document{text='', decorationList={

}, caretPosition=0}

which leads to potential NPEs everywhere the decoration is required.

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

Successfully merging a pull request may close this issue.

2 participants