title: setOnFinished() infinite loop?
body: <pre><code>else {
      ScaleTransition st = new ScaleTransition(Duration.millis(1000), gameView[ex.row][ex.col]);
      st.setByX(-1f);
      st.setByY(-1f);
      System.out.println("Loop"); //loop signal
      st.play();
  
      st.setOnFinished(e-&gt; {
          pane.getChildren().remove(gameView[ex.row][ex.col]);
          gameView[ex.row][ex.col]=null;
          scores.addAndGet(1);
      });
  }
  </code></pre>
  
  <p>The code snippet above is part of my Match 3 game.The <code>gameView</code> is an <code>ArrayList</code> which stores the sprites to be removed from the pane, and outside of the <code>if-else</code> is a <code>foreach</code> loop. I want to make a scaling animation before removing the sprites, but it always runs into infinite loop.Why ?</p>
  
  <p>Edit: Before i add the animation , my game can run smoothly. And if i don't call <code>setOnFinished()</code> my game still runs smoothly but without animation.</p>
  
  <pre><code>public static void remove(Buttonp[][] gameView,ArrayList&lt;matrixLocator&gt; removableButtonGroup,Pane pane,AtomicInteger scores){
      for(matrixLocator ex:removableButtonGroup){
          if(gameView[ex.row][ex.col]!=null){
              if(gameView[ex.row][ex.col].verticalExplosion==true){
                  pane.getChildren().remove(gameView[ex.row][ex.col]);
                  gameView[ex.row][ex.col]=null;
                  scores.addAndGet(1);
                  ArrayList&lt;matrixLocator&gt; al1=new ArrayList&lt;matrixLocator&gt;();
                  for(int m=0;m&lt;8;m++){
                      if((gameView[m][ex.col]!=null)&amp;&amp;(m!=ex.row)){
                          al1.add(new matrixLocator(m,ex.col));
                      }
                      else;
                  }
                  remove(gameView,al1,pane,scores);
              }
          //verticalExplosion
              else if(gameView[ex.row][ex.col].horizontalExplosion==true){
                  pane.getChildren().remove(gameView[ex.row][ex.col]);
                  gameView[ex.row][ex.col]=null;
                  scores.addAndGet(1);
                  ArrayList&lt;matrixLocator&gt; al2=new ArrayList&lt;matrixLocator&gt;();
                  for(int m=0;m&lt;10;m++){
                      if((gameView[ex.row][m]!=null)&amp;&amp;(m!=ex.col)){
                          al2.add(new matrixLocator(ex.row,m));
                      }
                      else;
                  }
                  remove(gameView,al2,pane,scores);
              }
          //horizontalExplosion
              else if(gameView[ex.row][ex.col].aroundExplosion==true){
                  pane.getChildren().remove(gameView[ex.row][ex.col]);
                  gameView[ex.row][ex.col]=null;
                  scores.addAndGet(1);
                  ArrayList&lt;matrixLocator&gt; al3=new ArrayList&lt;matrixLocator&gt;();
                  for(int m=0;m&lt;8;m++){
                      for(int n=0;n&lt;10;n++){
                          if((Math.abs(m-ex.row)&lt;=1)&amp;&amp;(Math.abs(n-ex.col)&lt;=1)){
                              if((gameView[m][n]!=null)&amp;&amp;((m!=ex.row)||(n!=ex.col))){
                                  al3.add(new matrixLocator(m,n));
                                  }
                              else;
                          }
                          else;
                      }
                  }
                  remove(gameView,al3,pane,scores);
              }
          //aroundExplosion           
              else{
                  ScaleTransition st=new ScaleTransition(Duration.millis(2000),gameView[ex.row][ex.col]);
                  st.setByX(-1f);
                  st.setByY(-1f);
                  System.out.println("LOOP");
                  st.play();
  
                  st.setOnFinished(e-&gt;{
                  pane.getChildren().remove(gameView[ex.row][ex.col]);
                  gameView[ex.row ][ex.col]=null;
                  scores.addAndGet(1);});
                 }    
              }
          else;
      }
  }
  </code></pre>
  
  <p>this is the whole .
  <code>Buttonp</code> is subclass of button and is given some properties. So it's the button(the sprites i called) 2-dimension array of my game.
  <code>matrixLocator</code> is another class containing only two integers , row and column , to locate the button to be removed. 
  Pane is my game pane .</p>
  
  <p>Edit: I run a demo just now , and i found the problem shouldn't be the <code>setOnFinished()</code> but should be the <code>foreach</code> loop .But why the loop will go infinitely? 
  And sorry for explaining the question not correctly and clearly.</p>