title: JavaFX Abnormally Closing Alert Returns Incorrect Result
body: <p>I have created a JavaFX <code>Alert</code> object that returns unexpected results when calling <code>showAndWait</code>.  The code below illustrates the behavior I am observing:</p>
  
  <pre><code>package myPackage;
  
  import java.util.Optional;
  
  import javafx.application.Application;
  import javafx.scene.control.Alert;
  import javafx.scene.control.Alert.AlertType;
  import javafx.scene.control.ButtonBar.ButtonData;
  import javafx.scene.control.ButtonType;
  import javafx.stage.Stage;
  
  public class Main extends Application {
  
      public static void main(final String[] args) {
          launch();
      }
  
      private static boolean isYes(final Optional&lt;ButtonType&gt; result) {
          return (result.isPresent() &amp;&amp; result.get().getButtonData() == ButtonData.YES);
      }
  
      @Override
      public void start(Stage primaryStage) throws Exception {
          final Alert alert = new Alert(AlertType.CONFIRMATION,
              "This is a test", ButtonType.NO, ButtonType.YES);
          System.out.println(isYes(alert.showAndWait()) ? "Yes" : "No or Closed");
          System.out.println(isYes(alert.showAndWait()) ? "Yes" : "No or Closed");
      }
  
  }
  </code></pre>
  
  <p>When I run the above application, two dialogs are shown.  Click "Yes" on the first dialog, then close (by clicking the "x" in the upper right corner) the second.  By taking the above steps, I expect that the application would print the following:</p>
  
  <blockquote>
    <p>Yes<br />
    No or Closed</p>
  </blockquote>
  
  <p>However, what I am actually seeing printed is:</p>
  
  <blockquote>
    <p>Yes<br />
    Yes</p>
  </blockquote>
  
  <p>The <a href="http://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/Dialog.html" rel="nofollow noreferrer">Dialog documentation</a> states that an "abnormal closing condition" (such as clicking the small "x" in the upper-right corner) will "attempt to set the result property to whatever value is returned from calling the result converter with the first matching ButtonType."  Given the context of this statement, I interpreted "matching ButtonType" to mean a ButtonType that either (direct quote from the documentation):</p>
  
  <blockquote>
    <ol>
    <li>The button has a ButtonType whose ButtonBar.ButtonData is of type ButtonBar.ButtonData.CANCEL_CLOSE.</li>
    <li>The button has a ButtonType whose ButtonBar.ButtonData returns true when ButtonBar.ButtonData.isCancelButton() is called.</li>
    </ol>
  </blockquote>
  
  <p>Is my interpretation of the documentation incorrect, or is this a bug in JavaFX?  Regardless of why this is not working as I expect, is there any way I can force "abnormal closing conditions" to return <code>ButtonType.NO</code> in this case?</p>