RFR: 8351067: Enforce Platform threading use [v5]

Andy Goryachev angorya at openjdk.org
Thu Mar 13 15:42:36 UTC 2025


> 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.

Andy Goryachev has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains seven additional commits since the last revision:

 - renamed
 - Merge remote-tracking branch 'origin/master' into 8351067.accessibility
 - get preferences
 - enforce
 - Merge remote-tracking branch 'origin/master' into 8351067.accessibility
 - review comments
 - javadoc

-------------

Changes:
  - all: https://git.openjdk.org/jfx/pull/1728/files
  - new: https://git.openjdk.org/jfx/pull/1728/files/e9bb3403..2fc3f9db

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jfx&pr=1728&range=04
 - incr: https://webrevs.openjdk.org/?repo=jfx&pr=1728&range=03-04

  Stats: 485 lines in 15 files changed: 425 ins; 28 del; 32 mod
  Patch: https://git.openjdk.org/jfx/pull/1728.diff
  Fetch: git fetch https://git.openjdk.org/jfx.git pull/1728/head:pull/1728

PR: https://git.openjdk.org/jfx/pull/1728


More information about the openjfx-dev mailing list