Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8128407

NPE on showing a focused TextField

XMLWordPrintable

      Showing a TextField with its focused state set to true causes NPE. Here's the testcase:

      -----------------------------------------------------
      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.TextField;
      import javafx.scene.layout.Pane;
      import javafx.stage.Stage;

      public class Main extends Application {
          public void start(Stage stage) {
              TextField text = new TF();

              Pane pane = new Pane();
              pane.getChildren().addAll(text);

              stage.setScene(new Scene(pane));
              stage.show();
              stage.centerOnScreen();
          }

          public static void main(String[] args) {
              Application.launch(Main.class, args);
          }
      }

      class TF extends TextField {
          public TF() {
              setFocused(true);
          }
      }
      -----------------------------------------------------

      The exception:

      SEVERE: javafx.scene.control.Control loadSkinClass Failed to load skin 'com.sun.javafx.scene.control.skin.TextFieldSkin' for control TF@10045eb[styleClass=text-input text-field]
      java.lang.NullPointerException
              at com.sun.javafx.scene.control.behavior.TextFieldBehavior.setCaretAnimating(TextFieldBehavior.java:110)
              at com.sun.javafx.scene.control.behavior.TextFieldBehavior.<init>(TextFieldBehavior.java:89)
              at com.sun.javafx.scene.control.skin.TextFieldSkin.<init>(TextFieldSkin.java:125)
              at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
              at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
              at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
              at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
              at javafx.scene.control.Control.loadSkinClass(Control.java:857)
              at javafx.scene.control.Control.impl_cssSet(Control.java:935)
              at javafx.scene.Node.impl_cssSet(Node.java:6193)
              at com.sun.javafx.css.StyleHelper.transitionToState(StyleHelper.java:708)
              at javafx.scene.Node.impl_processCSS(Node.java:6067)
              at javafx.scene.Parent.impl_processCSS(Parent.java:951)
              at javafx.scene.control.Control.impl_processCSS(Control.java:962)
              at javafx.scene.Parent.impl_processCSS(Parent.java:958)
              at javafx.scene.Node.processCSS(Node.java:6046)
              at javafx.scene.Scene.doCSSPass(Scene.java:359)
              at javafx.scene.Scene.preferredSize(Scene.java:1132)
              at javafx.scene.Scene.impl_initPeer(Scene.java:568)
              at javafx.stage.Window$13.invalidated(Window.java:683)
              at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:85)
              at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:119)
              at javafx.stage.Window.setShowing(Window.java:741)
              at javafx.stage.Window.show(Window.java:753)
              at javafx.stage.Stage.show(Stage.java:106)
              at textfieldbug.Main.start(Main.java:17)
              at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:298)
              at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:136)
              at com.sun.javafx.application.PlatformImpl$3.run(PlatformImpl.java:108)
              at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
              at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
              at com.sun.glass.ui.win.WinApplication$2$1.run(WinApplication.java:62)
              at java.lang.Thread.run(Thread.java:662)


      The scenario came from WebView which initializes a control's state right after its creation but before first showing.
      So, the NPE is reproducible in WebView.

      $ cd apps/internal/Browser
      $ ant run -Drun.jvmargs=-DproxyHost=www-proxy.us.oracle.com -Dapplication.args=http://www.wikipedia.org

      It will bring up a Browser with wikipedia loaded. Due to the exception WebView fails to show the text field on the page.
      This is reproducible with any web page on which there's a text field focused by default. Looks like a stopper for WebView.

            rbair Richard Bair (Inactive)
            ant Anton Tarasov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: