Strange NullPointerException when I use a certain CSS.

Scott Palmer swpalmer at gmail.com
Wed May 8 07:10:14 PDT 2013


JavaFX 2.2.21-b11
I have a TextField where I have set the skin to the following:

    private static class MyEditorSkin extends TextFieldSkin {

        public MyEditorSkin (TextField tf) {
            super(tf);
        }

        public MyEditorSkin (TextField tf, TextFieldBehavior tfb) {
            super(tf, tfb);
        }

        public FontMetrics getFontMetrics() {
            return fontMetrics.getValue();
        }
    }

e.g. myTextField.setSkin(new MyEditorSkin(myTextField));

Elsewhere in my code I do:
        Skin<?> skin = tf.getSkin();
        if (skin instanceof MyEditorSkin) {
            FontMetrics fm = ((MyEditorSkin) skin).getFontMetrics();
            ...

This was the only way I could see to get at the Font metrics used in a
TextField.  (I need to position some popups near the caret and using the
public methods to get the caret position in characters combined with
finding the width of the preceding characters seemed to be the simplest
way.)

Anyway.. my code has been working fine, but I just got a new style-sheet
from our graphic designer and when I use the new CSS suddenly the TextField
is throwing the following exception and I can't move the caret with the
cursor keys or type properly in it.

Exception in thread "JavaFX Application Thread"
java.lang.NullPointerException
        at
com.sun.javafx.scene.control.skin.TextInputControlSkin.setCaretAnimating(TextInputControlSkin.java:585)
        at
com.sun.javafx.scene.control.behavior.TextFieldBehavior.setCaretAnimating(TextFieldBehavior.java:164)
        at
com.sun.javafx.scene.control.behavior.TextInputControlBehavior.callAction(TextInputControlBehavior.java:124)
        at
com.sun.javafx.scene.control.behavior.BehaviorBase.callActionForEvent(BehaviorBase.java:157)
        at
com.sun.javafx.scene.control.behavior.TextInputControlBehavior.callActionForEvent(TextInputControlBehavior.java:117)
        at
com.sun.javafx.scene.control.behavior.BehaviorBase$1.handle(BehaviorBase.java:121)
        at
com.sun.javafx.scene.control.behavior.BehaviorBase$1.handle(BehaviorBase.java:119)
        at
com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:64)
        at
com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:217)
        at
com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:170)
        at
com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:38)
        at
com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:37)
        at
com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
        at
com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
        at
com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
        at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:53)
        at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:28)
        at javafx.event.Event.fireEvent(Event.java:171)
        at javafx.scene.Scene$KeyHandler.process(Scene.java:3513)
        at javafx.scene.Scene$KeyHandler.access$2300(Scene.java:3472)
        at javafx.scene.Scene.impl_processKeyEvent(Scene.java:1904)
        at javafx.scene.Scene$ScenePeerListener.keyEvent(Scene.java:2270)
        ...
Also happens on focus gained.

Looking at that line of source it seems that the only thing that could be
null is the caretTimeline.  But the caret is blinking away happily.  I
search the code and it seems the only way the caretTimeline can become null
is if dispose() is called on the TextInputControlSkin.  I don't understand
when this would happen or how different CSS that does little more than set
colours and backgrounds and borders would affect it.

I'm not sure if I'm doing something wrong or if this warrants a bug report.

In JavaFX 8.0.0-ea-b87  it is worse.. I can't even show the Scene with my
control without getting the following:

Exception in thread "JavaFX Application Thread"
java.lang.NullPointerException
        at com.sun.javafx.css.StyleCacheEntry.put(StyleCacheEntry.java:82)
        at
javafx.scene.CssStyleHelper.transitionToState(CssStyleHelper.java:784)
        at javafx.scene.Node.impl_processCSS(Node.java:8541)
        at javafx.scene.Parent.impl_processCSS(Parent.java:1191)
        at javafx.scene.Parent.impl_processCSS(Parent.java:1191)
        at javafx.scene.control.Control.impl_processCSS(Control.java:861)
        at javafx.scene.Parent.impl_processCSS(Parent.java:1191)
        at javafx.scene.Parent.impl_processCSS(Parent.java:1191)
        at javafx.scene.Parent.impl_processCSS(Parent.java:1191)
        at javafx.scene.Node.processCSS(Node.java:8443)
        at javafx.scene.Scene.doCSSPass(Scene.java:512)
        at javafx.scene.Scene.preferredSize(Scene.java:1498)
        at javafx.scene.Scene.impl_preferredSize(Scene.java:1565)
        at javafx.stage.Window$9.invalidated(Window.java:761)
        at
javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:107)
        at
javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:141)
        at javafx.stage.Window.setShowing(Window.java:827)
        at javafx.stage.Window.show(Window.java:842)
        at javafx.stage.Stage.show(Stage.java:242)
        at javafx.stage.Stage.showAndWait(Stage.java:408)
        at
ca.digitalrapids.kayak.gui.javafx.exp.SimplifiedExpressionEditor.showExpressionEditor(SimplifiedExpressionEditor.java:179)
        at
ca.digitalrapids.kayak.gui.pluggable.impl.javafx.PropertyContextMenuFactory$8.handle(PropertyContextMenuFactory.java:200)
        at
ca.digitalrapids.kayak.gui.pluggable.impl.javafx.PropertyContextMenuFactory$8.handle(PropertyContextMenuFactory.java:194)
        at
com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
        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.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
        at
com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:113)
        at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
        at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
        at javafx.event.Event.fireEvent(Event.java:202)
        at javafx.scene.control.MenuItem.fire(MenuItem.java:460)
        at
com.sun.javafx.scene.control.skin.ContextMenuContent$MenuItemContainer.doSelect(ContextMenuContent.java:1341)
        at
com.sun.javafx.scene.control.skin.ContextMenuContent$MenuItemContainer.doSelect(ContextMenuContent.java:1316)
        at
com.sun.javafx.scene.control.skin.ContextMenuContent$MenuItemContainer$7.handle(ContextMenuContent.java:1284)
        at
com.sun.javafx.scene.control.skin.ContextMenuContent$MenuItemContainer$7.handle(ContextMenuContent.java:1282)
        at
com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
        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:113)
        at
com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
        at
com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:113)
        at
com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
        at
com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:113)
        at
com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
        at
com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:113)
        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:202)
        at javafx.scene.Scene$MouseHandler.process(Scene.java:3551)
        at javafx.scene.Scene$MouseHandler.process(Scene.java:3382)
        at javafx.scene.Scene$MouseHandler.access$1800(Scene.java:3334)
        at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1612)
        at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2402)
        at
com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:312)
        at
com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:237)
        at java.security.AccessController.doPrivileged(Native Method)
        at
com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:354)
        at com.sun.glass.ui.View.handleMouseEvent(View.java:519)
        at com.sun.glass.ui.View.notifyMouse(View.java:882)
        at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at
com.sun.glass.ui.win.WinApplication.access$300(WinApplication.java:39)
        at
com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:101)
        at java.lang.Thread.run(Thread.java:724)
java.lang.NullPointerException
        at
com.sun.javafx.scene.control.skin.TextFieldSkin.updateSelection(TextFieldSkin.java:404)
        at
com.sun.javafx.scene.control.skin.TextFieldSkin.access$200(TextFieldSkin.java:66)
        at
com.sun.javafx.scene.control.skin.TextFieldSkin$6.invalidated(TextFieldSkin.java:208)
        at
com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:339)
        at
com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:80)
        at
javafx.beans.property.ReadOnlyObjectWrapper$ReadOnlyPropertyImpl.fireValueChangedEvent(ReadOnlyObjectWrapper.java:175)
        at
javafx.beans.property.ReadOnlyObjectWrapper.fireValueChangedEvent(ReadOnlyObjectWrapper.java:141)
        at
javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:110)
        at
javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:143)
        at
javafx.scene.control.TextInputControl.selectRange(TextInputControl.java:870)
        at
com.sun.javafx.scene.control.behavior.TextFieldBehavior.handleFocusChange(TextFieldBehavior.java:128)
        at
com.sun.javafx.scene.control.behavior.TextFieldBehavior.access$000(TextFieldBehavior.java:65)
        at
com.sun.javafx.scene.control.behavior.TextFieldBehavior$1.changed(TextFieldBehavior.java:84)
        at
com.sun.javafx.scene.control.behavior.TextFieldBehavior$1.changed(TextFieldBehavior.java:81)
        at
com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:347)
        at
com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:80)
        at
javafx.beans.property.ReadOnlyBooleanPropertyBase.fireValueChangedEvent(ReadOnlyBooleanPropertyBase.java:71)
        at javafx.scene.Node$FocusedProperty.notifyListeners(Node.java:7233)
        at javafx.scene.Scene$13.invalidated(Scene.java:2004)
        at
javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:109)
        at
javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:143)
        at javafx.scene.Scene$KeyHandler.setFocusOwner(Scene.java:3700)
        at javafx.scene.Scene$KeyHandler.requestFocus(Scene.java:3746)
        at javafx.scene.Scene$KeyHandler.access$2200(Scene.java:3698)
        at javafx.scene.Scene.requestFocus(Scene.java:1973)
        at javafx.scene.Node.requestFocus(Node.java:7394)
        at
com.sun.javafx.scene.traversal.TraversalEngine.getTopLeftFocusableNode(TraversalEngine.java:156)
        at javafx.scene.Scene.focusInitial(Scene.java:1926)
        at javafx.scene.Scene.access$3400(Scene.java:187)
        at
javafx.scene.Scene$ScenePulseListener.focusCleanup(Scene.java:2278)
        at javafx.scene.Scene$ScenePulseListener.pulse(Scene.java:2351)
        at com.sun.javafx.tk.Toolkit.firePulse(Toolkit.java:358)
        at
com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:560)
        at
com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:540)
        at
com.sun.javafx.tk.quantum.QuantumToolkit$15.run(QuantumToolkit.java:425)
        at
com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:94)
        at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at
com.sun.glass.ui.win.WinApplication.access$300(WinApplication.java:39)
        at
com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:101)
        at java.lang.Thread.run(Thread.java:724)

(And the CSS isn't working properly for other things like the background of
menus)

But with the default CSS it does work perfectly.

Given that Skins are not really part of the public API, I don't know if I
should expect this to work or not.

Scott


More information about the openjfx-dev mailing list