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

Adding children to wrong index leaves inconsistent state in Parent#childrenSet

XMLWordPrintable

    • b19
    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      Microsoft Windows [Version 10.0.17134.1040]
      openjdk version "13" 2019-09-17
      OpenJDK Runtime Environment AdoptOpenJDK (build 13+33)
      OpenJDK 64-Bit Server VM AdoptOpenJDK (build 13+33, mixed mode, sharing)

      A DESCRIPTION OF THE PROBLEM :
      Adding children to wrong index leaves inconsistent state in Parent#childrenSet, so the next call to remove throws exception. Run attached sources.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run provided test case.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Exception should not be thrown on removing the item.
      ACTUAL -
      Exception is thrown on removing the item.

      ---------- BEGIN SOURCE ----------
      import javafx.application.Application;
      import javafx.scene.control.Label;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class TestFx_collectionInconsistentState
      {

          public static void main( String[] args )
          {
              Application.launch( FxApp.class, args );
          }

          public static class FxApp extends Application
          {

              @Override
              public void start( final Stage primaryStage ) throws Exception
              {
                  System.err.println( System.getProperty( "javafx.version" ) );
                  final var pane = new VBox();
                  pane.getChildren().addAll( new Label( "1" ), new Label( "2" ) );
                  try
                  {
                      pane.getChildren().add( -1, new Label( "0" ) );
                  }
                  catch( IndexOutOfBoundsException aE )
                  {
                      // Exception is thrown, but the list state becomes corrupted
                  }
                  // But javafx.scene.Parent.childSet does not revert its state
                  pane.getChildren().remove( 0 );
              }
          }

      }

      ---------- END SOURCE ----------

      FREQUENCY : always


            lkostyra Lukasz Kostyra
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: