JDK-8198549 : Desktop.setOpenURIHandler() only receives event if application is already launched
  • Type: Bug
  • Component: deploy
  • Sub-Component: packager
  • Affected Version: 9.0.4,10
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: os_x
  • CPU: x86
  • Submitted: 2018-02-20
  • Updated: 2018-09-05
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Description
FULL PRODUCT VERSION :
java version "9.0.4"
Java(TM) SE Runtime Environment (build 9.0.4+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
macOS  10.13.3

A DESCRIPTION OF THE PROBLEM :
When using a JavaFX application on macOS is configured to handle custom URI schemes (through Info.plist key CFBundleURLSchemes), the handler set via Desktop.setOpenURIHandler() only receives an OpenURIEvent if the application is already running when the URI is opened. If the URI open (triggered by a web browser or the 'open' command on the terminal) launches the application, no OpenURIEvent will be delivered.



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Build the sources

javac -d classes src/com/example/Main.java

2) Create JAR using javapackager
javapackager -createJar -appclass com.example.Main -outdir jar -outfile example -srcdir classes

3) Create self-contained Mac application, set CFBundleURLTypes in Info.plist

javapackager -deploy -verbose -native image -name "Open URI Example" -srcdir jar -appclass com.example.Main \
    -outdir dist -outfile Example \
    -Bmac.CFBundleIdentifier=com.example.openuri -Bmac.CFBundleVersion=1.0.0 \
    -Bmac.signing-key-developer-id-app="Developer ID Application: My Company Ltd GmbH (ABCDEFGHIJKL)" \
    -Bmac.signing-key-developer-id-installer="Developer ID Installer: My Company Ltd (ABCDEFGHIJKL)" \
    -BdropinResourcesRoot=.


4) Start application via shell $ open javafx-openuri://hello
--> Label is empty

5) Start application first, then on shell $ open javafx-openuri://hello
--> URI is set on Label



EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The application should receive an OpenURIEvent if it was launched by opening a URI
ACTUAL -
The application only receives an OpenURIEvent if it was already running.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
The application:

package com.example;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

import java.awt.Desktop;

public class Main extends Application {

    private Label uriLabel;

    @Override
    public void start(Stage primaryStage) throws Exception {
        primaryStage.setTitle("Open URI Example");

        VBox root = new VBox();
        root.setPadding(new Insets(20, 20, 20, 20));
        uriLabel = new Label();
        uriLabel.setText("No URI opened");
        root.getChildren().add(uriLabel);

        Scene scene = new Scene(root, 200, 60);
        primaryStage.setScene(scene);
        primaryStage.show();

        Desktop.getDesktop().setOpenURIHandler((event) -> {
            Platform.runLater(() -> {
                uriLabel.setText(event.getURI().toString());
            });
        });
    }

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

The Info.plist:

<?xml version="1.0" ?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
 <dict>
  <key>LSMinimumSystemVersion</key>
  <string>10.9</string>
  <key>CFBundleDevelopmentRegion</key>
  <string>English</string>
  <key>CFBundleAllowMixedLocalizations</key>
  <true/>
  <key>CFBundleExecutable</key>
  <string>Open URI Example</string>
  <key>CFBundleIconFile</key>
  <string>Open URI Example.icns</string>
  <key>CFBundleIdentifier</key>
  <string>com.example.openuri</string>
  <key>CFBundleInfoDictionaryVersion</key>
  <string>6.0</string>
  <key>CFBundleName</key>
  <string>Open URI Example</string>
  <key>CFBundlePackageType</key>
  <string>APPL</string>
  <key>CFBundleShortVersionString</key>
  <string>1.0</string>
  <key>CFBundleSignature</key>
  <string>????</string>
  <!-- See http://developer.apple.com/library/mac/#releasenotes/General/SubmittingToMacAppStore/_index.html
       for list of AppStore categories -->
  <key>LSApplicationCategoryType</key>
  <string>Unknown</string>
  <key>CFBundleVersion</key>
  <string>1.0.0</string>
  <key>NSHumanReadableCopyright</key>
  <string>Copyright (C) 2018</string>
  <key>NSHighResolutionCapable</key>
  <string>true</string>
  <!-- Open URIs with scheme javafx-openuri:// -->
  <key>CFBundleURLTypes</key>
  <array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>javafx-openuri</string>
        </array>
        <key>CFBundleURLName</key>
        <string></string>
    </dict>
  </array>
 </dict>
</plist>

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


Comments
I tested provided test case in macOS 10.13.3 with JDK 9.0.4+11 and 10+46. Behavior is same in both. The application receives an OpenURIEvent only if it is already running. 1. Started application from Terminal : $ open javafx-openuri://hello -> Label says "No URI opened". 2. Again executed same cmd, with app running from Step 1 : $ open javafx-openuri://hello - > Label changes to "javafx-openuri://hello"
22-03-2018

Submitter has confirmed again that this issue is present in the JDK 10 GA build also.
22-03-2018

Response from Submitter: ------------------------------------------------------- I have taken some extra time and created a public Github repository, which contains the sample code and a build script, as well as a README: https://github.com/suzukieng/javafx-mac-openuri I also checked with the JDK 10 EA build. The problem also exists there. To test it, you can just change -v9 to -v10 in the build.sh script. java version "10" 2018-03-20 Java(TM) SE Runtime Environment 18.3 (build 10+44) Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10+44, mixed mode) ------------------------------------------------------- Issue is reproducible in macOS 10.13.3 when ran with JDK 9. But according to Submitter its reproducible in JDK 10-ea+44 also. PFA attached ZIP file (javafx-mac-openuri-master.zip) of project provided by submitter.
01-03-2018

This is quite probably a javapackager bug.
22-02-2018

does it affect 10?
22-02-2018