JDK-8185831 : Pseudo selectors do not appear to work in Node.lookupAll()
  • Type: Bug
  • Component: javafx
  • Sub-Component: scenegraph
  • Affected Version: 8,9
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2017-08-02
  • Updated: 2023-11-20
  • Resolved: 2023-11-01
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
jfx22 b16Fixed
Description
FULL PRODUCT VERSION :
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Windows 7, 64 bit

A DESCRIPTION OF THE PROBLEM :
I'm tring to use pseudo classes in programmtic query using Node.lookupAll() however this seems to give unexpected results.

I've searched online and can't find anything to suggest Node.lookupAll() wouldn't support psuedo classes...

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See test case

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
lookupAll() should return nodes according to selectors containing psuedo selectors
ACTUAL -
lookupAll() appears to ignore pseudo selectors and returns all nodes

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javafx.application.Application;
import javafx.css.PseudoClass;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

public class Foo extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        PseudoClass pseudoClass = PseudoClass.getPseudoClass("custom");

        Label a = new Label();
        a.getStyleClass().add("foo");
        a.pseudoClassStateChanged(pseudoClass, false);

        Label b = new Label();
        b.getStyleClass().add("foo");
        a.pseudoClassStateChanged(pseudoClass, true);

        Label c = new Label();
        c.getStyleClass().add("foo");
        a.pseudoClassStateChanged(pseudoClass, true);


        HBox box = new HBox(a, b, c);
        primaryStage.setScene(new Scene(box));

        System.out.println(box.lookupAll(":custom").size()); // expected 2
        System.out.println(box.lookupAll(".foo:custom").size()); // expected 2
        System.out.println(box.lookupAll(".foo").size()); // expected 3, got 3
        System.out.println(box.lookupAll(":magichorse").size()); // expected 0 !!

    }

}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Don't use pseudo selectors in lookupAll(). Instead use getPseudoClassStates() 


Comments
Changeset: bb06b64c Author: Dandem, Sai Pradeep <saipradeep.dandem@gmail.com> Committer: Andy Goryachev <angorya@openjdk.org> Date: 2023-11-01 22:46:05 +0000 URL: https://git.openjdk.org/jfx/commit/bb06b64c9e1cda9390a84704a75b530c1d1d4577
01-11-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jfx/pull/1245 Date: 2023-09-19 12:17:16 +0000
19-09-2023

Issue reproducible in both JDK 8 and 9. JDK results (Windows 10) ========== 8 GA : Fail 8u152-b09 : Fail 9-ea+180 : Fail ========= According to submitter, 'lookupAll()' API doc also doesn't mention if this method will match Pseudo selector or not. It just says about CSS selector :: "Finds all Nodes, including this one and any children, which match the given CSS selector. If no matches are found, an empty unmodifiable set is returned. The set is explicitly unordered." https://docs.oracle.com/javase/8/javafx/api/javafx/scene/Node.html#lookupAll-java.lang.String- http://download.java.net/java/jdk9/jfxdocs/javafx/scene/Node.html#lookupAll-java.lang.String-
04-08-2017