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

Desktop.mail() method hangs when no mail client is installed

XMLWordPrintable

    • x86_64
    • linux_ubuntu

      FULL PRODUCT VERSION :
      java version "1.8.0_121"

      ADDITIONAL OS VERSION INFORMATION :
      Linux XPS-15-9560 4.8.0-49-generic #52~16.04.1-Ubuntu SMP Thu Apr 20 10:55:59 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      Calling Desktop.mail(new URI("mailto:" + ...) hangs. Nothing happens. There is no mail client installed on my system (Ubuntu 16.04).

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the code below

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Should get an Exception indicating that no mail client is installed on the system.
      ACTUAL -
      Application hangs.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package app;

      import java.awt.Desktop;
      import java.io.IOException;
      import java.net.URI;
      import java.net.URISyntaxException;

      import javafx.application.Application;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.TextField;
      import javafx.scene.layout.HBox;
      import javafx.stage.Stage;

      public class OpenDefaultBrowser extends Application {

      @Override
      public void start(Stage primaryStage) {
      final HBox root = new HBox(5);
      final TextField textField = new TextField("help@example.com");
      final Button goButton = new Button("Mail");

      EventHandler<ActionEvent> goHandler = new EventHandler<ActionEvent>() {

      public void handle(ActionEvent event) {

      if (Desktop.isDesktopSupported()) {
      try {
      Desktop desktop = Desktop.getDesktop();
      if (desktop.isSupported(Desktop.Action.MAIL)) {
      desktop.mail(new URI("mailto:" + textField.getText() + "?subject=Hello%20World"));
      } else {
      System.out.println("e-mail not supported");
      }
      } catch (IOException | URISyntaxException ioe) {
      ioe.printStackTrace();
      }
      } else {
      System.out.println("Desktop not supported");
      }

      }

      };

      textField.setOnAction(goHandler);
      goButton.setOnAction(goHandler);

      root.getChildren().addAll(textField, goButton);
      final Scene scene = new Scene(root, 250, 150);
      primaryStage.setScene(scene);
      primaryStage.show();
      }

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

            scfitch Stephen Fitch
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: