Skip to content

NPE in clipboard copy #573

@JFormDesigner

Description

@JFormDesigner

I get an NPE when pressing Ctrl+C, but only if the selection includes a line separator and ends at the beginning of a line.

This is a regression. Used 0.7-M3 before where it worked. So I checked out various commits to find out the commit that broke it. It is commit a2aa881. It works when I checkout the previous commit.

To reproduce, run this little app and press Ctrl+C:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import org.fxmisc.flowless.VirtualizedScrollPane;
import org.fxmisc.richtext.CodeArea;

public class ClipboardCopyNPE extends Application {
    @Override
    public void start(Stage primaryStage) throws Exception {
        CodeArea area = new CodeArea("abc\ndef\nghi");
        VirtualizedScrollPane<CodeArea> vsPane = new VirtualizedScrollPane<>(area);

        area.selectRange(2, 4);
        
        Scene scene = new Scene(vsPane, 400, 400);
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}

The NPE is:

Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
	at org.fxmisc.richtext.model.SuperCodec$1.encodeSuper(SuperCodec.java:33)
	at org.fxmisc.richtext.model.SuperCodec$1.encodeSuper(SuperCodec.java:1)
	at org.fxmisc.richtext.model.SuperCodec.encode(SuperCodec.java:15)
	at org.fxmisc.richtext.model.StyledText$2.encode(StyledText.java:94)
	at org.fxmisc.richtext.model.StyledText$2.encode(StyledText.java:1)
	at org.fxmisc.richtext.model.SuperCodec$1.encodeSuper(SuperCodec.java:35)
	at org.fxmisc.richtext.model.SuperCodec$1.encodeSuper(SuperCodec.java:1)
	at org.fxmisc.richtext.model.SuperCodec.encode(SuperCodec.java:15)
	at org.fxmisc.richtext.model.ReadOnlyStyledDocument$3.encode(ReadOnlyStyledDocument.java:139)
	at org.fxmisc.richtext.model.ReadOnlyStyledDocument$3.encode(ReadOnlyStyledDocument.java:1)
	at org.fxmisc.richtext.model.SuperCodec$1.encodeSuper(SuperCodec.java:35)
	at org.fxmisc.richtext.model.SuperCodec$1.encodeSuper(SuperCodec.java:1)
	at org.fxmisc.richtext.model.SuperCodec.encode(SuperCodec.java:15)
	at org.fxmisc.richtext.model.ReadOnlyStyledDocument$2.encode(ReadOnlyStyledDocument.java:116)
	at org.fxmisc.richtext.model.ReadOnlyStyledDocument$2.encode(ReadOnlyStyledDocument.java:1)
	at org.fxmisc.richtext.ClipboardActions.lambda$0(ClipboardActions.java:67)
	at java.util.Optional.ifPresent(Optional.java:159)
	at org.fxmisc.richtext.ClipboardActions.copy(ClipboardActions.java:60)
	at org.fxmisc.richtext.GenericStyledAreaBehavior.lambda$28(GenericStyledAreaBehavior.java:149)
	at org.fxmisc.wellbehaved.event.template.InputMapTemplate.lambda$consume$32(InputMapTemplate.java:107)
	at org.fxmisc.wellbehaved.event.template.PatternActionTemplate.lambda$null$44(InputMapTemplate.java:242)
	at java.util.Optional.map(Optional.java:215)
	at org.fxmisc.wellbehaved.event.template.PatternActionTemplate.lambda$getInputHandlerTemplateMap$45(InputMapTemplate.java:242)
	at org.fxmisc.wellbehaved.event.template.InputHandlerTemplateMap.lambda$sequence$39(InputHandlerTemplateMap.java:25)
	at org.fxmisc.wellbehaved.event.template.InputMapTemplate$1.lambda$null$30(InputMapTemplate.java:92)
	at org.fxmisc.wellbehaved.event.template.InputHandlerTemplateMap.lambda$sequence$39(InputHandlerTemplateMap.java:24)
	at org.fxmisc.wellbehaved.event.template.InputMapTemplate$HandlerTemplateConsumer$1.lambda$accept$29(InputMapTemplate.java:36)
	at org.fxmisc.wellbehaved.event.InputHandler.handle(InputHandler.java:15)
	at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
	at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
	at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
	at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
	at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
	at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
	at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
	at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
	at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
	at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
	at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
	at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
	at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
	at javafx.event.Event.fireEvent(Event.java:198)
	at javafx.scene.Scene$KeyHandler.process(Scene.java:3964)
	at javafx.scene.Scene$KeyHandler.access$1800(Scene.java:3910)
	at javafx.scene.Scene.impl_processKeyEvent(Scene.java:2040)
	at javafx.scene.Scene$ScenePeerListener.keyEvent(Scene.java:2501)
	at com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:217)
	at com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:149)
	at java.security.AccessController.doPrivileged(Native Method)
	at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleKeyEvent$353(GlassViewEventHandler.java:248)
	at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
	at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(GlassViewEventHandler.java:247)
	at com.sun.glass.ui.View.handleKeyEvent(View.java:546)
	at com.sun.glass.ui.View.notifyKey(View.java:966)
	at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
	at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
	at java.lang.Thread.run(Thread.java:748)

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