RFR: 8214699: Node.getPseudoClassStates must return the same instance on every call

Jeanette Winzenburg fastegal at openjdk.java.net
Mon Jun 22 12:04:00 UTC 2020

On Thu, 18 Jun 2020 16:30:42 GMT, Ambarish Rapte <arapte at openjdk.org> wrote:

> Node.getPseudoClassStates() returns a new UnmodifiableObservableSet of PseudoClassState on each call. So in order to
> listen to any changes in this set, user must call the method Node.getPseudoClassStates() only once and keep a strong
> reference to the returned UnmodifiableObservableSet.
> So the fix is that the method Node.getPseudoClassStates() should return the same UnmodifiableObservableSet on every
> call. As the returned set is an UnmodifiableObservableSet, it will not have any impact on it's usage.
> Added a small unit test. and,
> Altered(minor) a test which was modified in
> past(https://github.com/openjdk/jfx/commit/0ac98695a1b11443c342fad4f009d6e03a052522)
> (https://github.com/openjdk/jfx/commit/62323e0a9c5817b33daa262d6914eba0e8d274ff) along with this method and should be
> updated in view of this change.

Changes requested by fastegal (Committer).

modules/javafx.graphics/src/main/java/javafx/scene/Node.java line 9371:

> 9370:     final ObservableSet<PseudoClass> unmodifiablePseudoClassStates =
> 9371:             FXCollections.unmodifiableObservableSet(pseudoClassStates);
> 9372:     /**

the unmodifiable field can be private, or is there any reason for being package?

modules/javafx.graphics/src/main/java/javafx/scene/Node.java line 9375:

> 9374:     public final ObservableSet<PseudoClass> getPseudoClassStates() {
> 9375:
> 9376:         return FXCollections.unmodifiableObservableSet(pseudoClassStates);

missing override annotation (says my IDE :) - not entirely certain about guidelines here: it was missing before as
well, but now might be a good time to fix it (except if we generally leave such cleanup to a dedicated cleanup commit)


PR: https://git.openjdk.java.net/jfx/pull/253

More information about the openjfx-dev mailing list