Summary
Adds a thread check to a number of Platform
methods:
accessibilityActiveProperty()
getPreferences()
isAccessibilityActive()
These methods will throw an IllegalStateException
if called on a thread other than the JavaFX Application Thread.
Problem
JavaFX allows the Nodes and Scenes to be created and modified on any thread as long as they are not yet attached to a Window
that is showing.
This is allowed in an implicit assumption that the construction code only modifies the properties of the said Nodes and Scenes, but not other static or global entities. Concurrent multi-threaded access of such entities not only breaks the initialization of the properties, but also causes the failures down the road, if the change to the global properties happens while the Nodes and Scenes are still being constructed.
Even JavaFX platform developers did not avoid tripping over this issue, as can be illustrated by https://bugs.openjdk.org/browse/JDK-8348987 .
Solution
Fail each method fast with an IllegalStateException
if called from a background thread.
While this solution won't prevent other possible abuse, such as getting a reference to the property in the JavaFX Application Thread and later accessing it in a background thread, adding a check and allowing these methods to fail fast should prevent most likely scenarios.
Specification
javafx.graphics/src/main/java/javafx/application/Platform.java
* This property is typically set to true the first time an
* assistive technology, such as a screen reader, requests
* information about any JavaFX window or its children.
- *
- * <p>This method may be called from any thread.</p>
+ * <p>
+ * This property can be accessed only from the JavaFX Application Thread.
*
* @return the read-only boolean property indicating if accessibility is active
*
+ * @throws IllegalStateException if this method is called on a thread
+ * other than the JavaFX Application Thread.
* @since JavaFX 8u40
*/
public static ReadOnlyBooleanProperty accessibilityActiveProperty() {
+ * @throws IllegalStateException if this method is called on a thread
+ * other than the JavaFX Application Thread.
* @see <a href="Platform.Preferences.html#preferences-table-windows">Windows preferences</a>
* @see <a href="Platform.Preferences.html#preferences-table-macos">macOS preferences</a>
* @see <a href="Platform.Preferences.html#preferences-table-linux">Linux preferences</a>
* @since 22
*/
public static Preferences getPreferences() {
- csr of
-
JDK-8351067 Enforce Platform threading use
-
- In Progress
-