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

NPE in TextAreaSkin.scrollCaretToVisible

XMLWordPrintable

    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      Win10, ADOPTIUM JDK21

      A DESCRIPTION OF THE PROBLEM :
      Showing TextArea with right conditions causes NPE.

      java.lang.NullPointerException: Cannot invoke "javafx.scene.control.TextArea.getScrollLeft()" because "<local1>" is null
      at javafx.scene.control.skin.TextAreaSkin.scrollCaretToVisible(TextAreaSkin.java:1081)
      at javafx.scene.control.skin.TextAreaSkin$ContentView.lambda$layoutChildren$3(TextAreaSkin.java:1495)
      at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:456)
      at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
      at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:455)
      at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
      at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
      at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
      at java.base/java.lang.Thread.run(Thread.java:1583)

      It has something to do with runLater in layoutChildren, which causes getSkinnable to return null. runlater is inherently unsafe here and any code inside must check ui object lifecycle (it may be uninitialized/disposed/etc)


                      // if only there was a way to force a layout from within the layout!
                      // runlater causes flicker
                      Platform.runLater(() -> {
                          scrollPane.layout();
                          scrollCaretToVisible();
                      });

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Opening Stage with TextArea. Unfortunately, I'm unable to provide reproducible example as this happens in a complex form in custom Stage window in complex application. The window showing code is something like this

      stage.show()
      scene.root = root
      stage.sizeToScene()
      stage.focus()

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      No NPE

      ---------- BEGIN SOURCE ----------
      Sry, this time unable to provide so far. Would take hours.
      ---------- END SOURCE ----------

      FREQUENCY : always


            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: