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

Thread-unsafe implementation of c.s.j.scene.control.skin.Utils

XMLWordPrintable

    • b04
    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      all methods in com.sun.javafx.scene.control.skin.Utils that use the static variable layout are not thread safe since they mutate a shared static object. This poisons all transitive calls of these methods. For example calling getBaselineOffset on controls that are not on the live scene graph can crash live UI controls; so does setting displayedYearMonth of a DatePickerContent object.

      A possible way this crashes is as follows:
      - Thread 1 control 1 (non scene graph) calls computeTextWidth with some string content
      - JavaFX thread control 2 renders some control, calling computeBaselineOffset -> Utils.getAscent
      - Thread 1 calls layout.setContent("some text"), which starts a computation and finally initializes layout.runs with some string array
      - Thread 2 calls layout.setContent(""), which resets layout.runs to null
      - Thread 1 crashes with NPE due to trying to access layout.runs

      A fix could be to instantiate per method invocation instances of TextLayout instead of using a shared static instance.

      If performance is the reason for the static single instance, please consider that creating multiple instances should have a negligible performance impact since the object does not instantiate a lot of fields and may even improve performance since no shared memory needs to be accessed.


      FREQUENCY : occasionally

      Root Cause:
      Some text layout utility methods access a static Text and TextLayout instances, a practice which is neither thread-safe nor reentrant.

            angorya Andy Goryachev
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: