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

PickResult.toString() is missing the closing square bracket

    XMLWordPrintable

Details

    • generic
    • generic

    Description

      ADDITIONAL SYSTEM INFORMATION :
      Any system, latest JFX 15 or 16

      A DESCRIPTION OF THE PROBLEM :
      String representation of javafx.scene.input.PickResult always gives incorrect result, because it lacks one closing square bracket(']') in the end of method.

      I found this bug implementing beautify(String) method, that was "moving" every new javafx.scene.input.MouseEvent on tab further. I couldn't find bug in my code, so i just counted amount of opening and closing square brackets: number of opening was one more than closing. I digged in source code of toString and MouseEvent's toString() looked ok to me, so i noticed that problem might be in PickResult.toString(). So there was. Comparison of toString methods and place of bug:
      https://prnt.sc/10rh7dp
      https://prnt.sc/10rh8bh

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create new JavaFx application, add MouseEvent handler to pane/scene and print it when MouseEvent occurs.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
        beautified:
        MouseEvent [
            source = javafx.scene.Scene@1fb3f629,
            target = Rectangle[
                x=0.0,
                y=0.0,
                width=101.0,
                height=101.0,
                fill=0x808080ff
            ],
            eventType = MOUSE_MOVED,
            consumed = false,
            x = 1203.0,
            y = 474.0,
            z = 0.0,
            button = NONE,
            pickResult = PickResult [
                node = Rectangle[
                    x=0.0,
                    y=0.0,
                    width=101.0,
                    height=101.0,
                    fill=0x808080ff
                ],
                point = Point3D [
                    x = 84.0,
                    y = 38.0,
                    z = 0.0
                ],
                distance = 2644.1579971625497
            ]
        ]
      plain text:
      MouseEvent [source = javafx.scene.Scene@874f0c1, target = Rectangle[x=0.0, y=0.0, width=101.0, height=101.0, fill=0x808080ff], eventType = MOUSE_MOVED, consumed = false, x = 1425.0, y = 358.0, z = 0.0, button = NONE, pickResult = PickResult [node = Rectangle[x=0.0, y=0.0, width=101.0, height=101.0, fill=0x808080ff], point = Point3D [x = 84.0, y = 33.0, z = 0.0], distance = 2644.1579971625497]]

      ACTUAL -
        beautified:
        MouseEvent [
            source = javafx.scene.Scene@1fb3f629,
            target = Rectangle[
                x=0.0,
                y=0.0,
                width=101.0,
                height=101.0,
                fill=0x808080ff
            ],
            eventType = MOUSE_MOVED,
            consumed = false,
            x = 1203.0,
            y = 474.0,
            z = 0.0,
            button = NONE,
            pickResult = PickResult [
                node = Rectangle[
                    x=0.0,
                    y=0.0,
                    width=101.0,
                    height=101.0,
                    fill=0x808080ff
                ],
                point = Point3D [
                    x = 84.0,
                    y = 38.0,
                    z = 0.0
                ],
                distance = 2644.1579971625497
            ]
      plain text:
      MouseEvent [source = javafx.scene.Scene@874f0c1, target = Rectangle[x=0.0, y=0.0, width=101.0, height=101.0, fill=0x808080ff], eventType = MOUSE_MOVED, consumed = false, x = 1425.0, y = 358.0, z = 0.0, button = NONE, pickResult = PickResult [node = Rectangle[x=0.0, y=0.0, width=101.0, height=101.0, fill=0x808080ff], point = Point3D [x = 84.0, y = 33.0, z = 0.0], distance = 2644.1579971625497]

      ---------- BEGIN SOURCE ----------
      import javafx.application.Application;
      import javafx.event.Event;
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.scene.input.MouseEvent;
      import javafx.scene.layout.StackPane;
      import javafx.stage.Stage;

      public class App extends Application {

          @Override
          public void start(Stage stage) {
              var javaVersion = SystemInfo.javaVersion();
              var javafxVersion = SystemInfo.javafxVersion();

              var label = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + ".");
              var pane = new StackPane(label);
              
              pane.addEventHandler(MouseEvent.ANY, this::handleMouse);
              
              var scene = new Scene(pane, 640, 480);
              stage.setScene(scene);
              stage.show();
          }

          private void handleMouse(MouseEvent t){
              System.out.println(beautify(t.toString()));
              //notice there is no closing bracket with zero tabs, that's the problem
              System.out.println();
              System.out.println(t.toString());
              System.exit(0);
          }
          public static String beautify(String startingString){
              final int tabLength = 4;
              int tabs = 0;
              StringBuilder sb = new StringBuilder(startingString.length());
              sb.append('\n');

              for(int i = 0; i < startingString.length(); i++){
                  char c = startingString.charAt(i);
                  if(c == '{' || c == '['){
                      tabs++;
                      sb.append(c);
                      sb.append('\n');
                      sb.append(" ".repeat(tabs*tabLength));
                  }else if(c == '}' || c == ']'){
                      tabs--;
                      sb.append('\n');
                      sb.append(" ".repeat(tabs*tabLength));
                      sb.append(c);
                  }else if(c == ','){
                      sb.append(c);
                      sb.append('\n');
                      sb.append(" ".repeat(tabs*tabLength -1));
                  }else
                      sb.append(c);
              }
              return sb.toString();
          }

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

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

      CUSTOMER SUBMITTED WORKAROUND :
      just add .append(']') in the end of PickResult.toString() method.

      FREQUENCY : always


      Attachments

        Issue Links

          Activity

            People

              kcr Kevin Rushforth
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: