JDK-8204537 : java.awt.Desktop.open(File) does not throw IOException if no app is registered
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 8,9,10,11
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2018-06-06
  • Updated: 2021-01-24
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
Related Reports
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
Windows 10. Tested with other Java version like 1.6 and also there it is reproducible.

A DESCRIPTION OF THE PROBLEM :
On Windows 10: When the method is invoked with a file like "exmaple.car" and there is no application registered for the file extension ".car", the OS displays the "Choose app to open file" dialog and the method returns silently without any exception.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See example source code below.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
According to the javadoc "@throws IOException if the specified file has no associatedapplication or the associated application fails to be launched"
ACTUAL -
No exception is thrown.

---------- BEGIN SOURCE ----------
import java.io.File;

public class Example {

	public static void main(String[] args) {
		try {
			File file = new File("example.extension");
			file.createNewFile();
			java.awt.Desktop.getDesktop().open(file);
		} catch (Exception ex) {
			ex.printStackTrace();
			return;
		}
		System.out.println("No exception");
	}
}

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

FREQUENCY : always



Comments
[~aivanov] > If the exception is not thrown, the test could use Robot to click somewhere at a corner of the screen to force-close the Windows dialog. IMHO it would be better to press e.g. ESC using Robot because the click to somewhere may cause opening some other windows.
24-01-2021

[~vprovodin] I guess you meant to add the comment above to JDK-8064934. However, I can see how it's related. Running test/jdk/java/awt/Desktop/8064934 leaves the Windows dialog ���How do you want to open this file?��� open. Clicking anywhere on the desktop outside of the dialog, closes it. I would expect the bug8064934.java test to fail: it expects an exception but the exception is not thrown. Yet the test passes. I suggest to problem-list bug8064934.java with reference to this bug. In addition to that, it could be updated to fail if the exception is not thrown. If the exception is not thrown, the test could use Robot to click somewhere at a corner of the screen to force-close the Windows dialog.
22-01-2021

Please note : after execution of the test java/awt/Desktop/8064934/bug8064934.java the dialog remains opened that may affects tests running in a bunch E.g. try to run the following $ jtreg -testjdk:[jdk] test/jdk/java/awt/Desktop/8064934 test/jdk/java/awt/Desktop/OpenByUNCPathNameTest The dialog and notepad remain opened after tests execution If to launch every test separately like follows $ jtreg -testjdk:[jdk] test/jdk/java/awt/Desktop/8064934 $ jtreg -testjdk:[jdk] test/jdk/java/awt/Desktop/OpenByUNCPathNameTest then all windows are closed at the end of test runs
22-01-2021

OpenByUNCPathNameTest is a manual test. One has to close Notepad window manually. This step should be added to the test instructions.
22-01-2021

I am fine.
27-04-2020

I am not sure that "the system dialog box which allows selecting a new app" is not a default associated app since it is always active we never get an exception.
31-03-2020

Well, from user's point of view, there's no associated app. Yet from technical point of view, this dialog is kinda an associated app. Yet if you look at the registry or look at the file types in Settings apps, there will be no association. Even some ���registered��� types have no default app. I remember even Windows 95 showed a dialog which allowed selecting an app if you double-clicked a file that has no associated app. Anyway, I think we should update documentation so that it allows for this kind of flexibility. Does it sound good?
31-03-2020

The behaviour in Windows OS has changed. If an extension has no associated app, Windows 10 shows a dialog prompting the user to select an application or search for an app in Microsoft Store. If you use Windows 10 regularly, you may have noticed that Windows 10 occasionally shows such a dialog even for registered types, for example when a new application that accepts the file type is installed; it allows the user to confirm their preferred application or select a new one. The implementation of Desktop.open in Java uses ShellExecute function. It does not allow passing any flags to suppress UI. ShellExecuteEx function has a flag SEE_MASK_FLAG_NO_UI (���Do not display an error message box if an error occurs.���) but it has no effect in this case. The dialog prompting to select an application still appears. I confirmed this by writing a simple Win32 app which uses either ShellExecute or ShellExecuteEx to open a file ("example.car"), when using ShellExecuteEx, I included the SEE_MASK_FLAG_NO_UI flag. So Java does not receive an error from the OS when opening a file type that has no associated application, the operation completes successfully and the OS shows a dialog box which allows selecting a new app. Therefore we should clarify the documentation: ���throws IOException if the associated application fails to launch or another error occurs.���
30-03-2020

IOException is raised for .386(virtual device driver files). Below is the exception that got raised while opening a file with an extention of .386. java.io.IOException: Failed to open example.386. Error message: No application is associated with the specified file for this operation. at java.desktop/sun.awt.windows.WDesktopPeer.ShellExecute(WDesktopPeer.java:114) at java.desktop/sun.awt.windows.WDesktopPeer.open(WDesktopPeer.java:88) at java.desktop/java.awt.Desktop.open(Desktop.java:434) at DesktopOpenTest.main(DesktopOpenTest.java:9) There may be a default program set for any kind of unknown file types by the OS or by the user which is causing not to cause the IOException. This exception is raised for a known file type but without any installed app for that type or for that category of types. Hence I see it as a non-issue. I do get an error code of 42 greater than 32 which is considered valid while opening a file(like the sample one attached with this bug). Please see the documentation at https://msdn.microsoft.com/en-us/library/windows/desktop/bb762153(v=vs.85).aspx. I do get an error code of 31 for the .386 extention file opening which is SE_ERR_NOASSOC.
12-06-2018

IOException is not thrown when an un-associated file is opened via the Desktop.Open() function which is against the java doc behavior documentation. This is observed on Windows 10 with 11-ea+17.
12-06-2018

When Desktop.open() is called with a file which has no associated application, java program exits and OS opens a dialog "How do you want to open this file" . There is no exception thrown from Java which is against what doc says: https://docs.oracle.com/javase/8/docs/api/java/awt/Desktop.html#open-java.io.File- "Throws: IOException - if the specified file has no associated application or the associated application fails to be launched" This behavior is same in all JDK - 8b132, 8u172, 9, 10+46, 11-ea+13.
07-06-2018