Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 302833

Summary: SWT.OPEN and SWT.SAVE prevent file access in the parent shell?
Product: [Eclipse Project] Platform Reporter: Mohsen Saboorian <mohsens>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: CLOSED WONTFIX QA Contact: Felipe Heidrich <eclipse.felipe>
Severity: normal    
Priority: P3 CC: lshanmug, remy.suen, Silenio_Quarti
Version: 3.5.1Keywords: triaged
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard: stalebug
Attachments:
Description Flags
Here is the full project with Java6 and SWT 3.6M5 none

Description Mohsen Saboorian CLA 2010-02-14 17:39:35 EST
There is a strange behavior when SWT.SAVE or SWT.OPEN dialogs are open and an active thread tries to change parent shell icons (within display.syncExec). In the following stacktrace, although the file player-play-rtl13.png exists, it fails to open it when either of SAVE or OPEN dialogs are open.

Does open/save dialogs prevent access to hard disk from other threads?


Here is the stack trace:
org.eclipse.swt.SWTException: Failed to execute runnable (org.eclipse.swt.SWTException: i/o error (java.io.FileNotFoundException: res\image\icon\audio\player-play-rtl13.png (The system cannot find the path specified)))
	at org.eclipse.swt.SWT.error(SWT.java:3884)
	at org.eclipse.swt.SWT.error(SWT.java:3799)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:137)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3855)
	at org.eclipse.swt.widgets.Display.messageProc(Display.java:2901)
	at org.eclipse.swt.internal.win32.OS.GetOpenFileNameW(Native Method)
	at org.eclipse.swt.internal.win32.OS.GetOpenFileName(OS.java:2652)
	at org.eclipse.swt.widgets.FileDialog.open(FileDialog.java:392)
	at net.sf.zekr.ui.MessageBoxUtils.importFileDialog(MessageBoxUtils.java:469)
	at net.sf.zekr.ui.MessageBoxUtils.importFileDialog(MessageBoxUtils.java:444)
	at net.sf.zekr.ui.QuranFormMenuFactory.importTrans(QuranFormMenuFactory.java:875)
	at net.sf.zekr.ui.QuranFormMenuFactory.access$14(QuranFormMenuFactory.java:868)
	at net.sf.zekr.ui.QuranFormMenuFactory$5.handleEvent(QuranFormMenuFactory.java:557)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3880)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3473)
	at net.sf.zekr.ui.BaseForm.loopEver(BaseForm.java:34)
	at net.sf.zekr.ZekrMain.startZekr(ZekrMain.java:63)
	at net.sf.zekr.ZekrMain.main(ZekrMain.java:91)
Caused by: org.eclipse.swt.SWTException: i/o error (java.io.FileNotFoundException: res\image\icon\audio\player-play-rtl13.png (The system cannot find the path specified))
	at org.eclipse.swt.SWT.error(SWT.java:3884)
	at org.eclipse.swt.SWT.error(SWT.java:3799)
	at org.eclipse.swt.graphics.ImageLoader.load(ImageLoader.java:159)
	at org.eclipse.swt.graphics.ImageDataLoader.load(ImageDataLoader.java:26)
	at org.eclipse.swt.graphics.ImageData.<init>(ImageData.java:377)
	at org.eclipse.swt.graphics.Image.<init>(Image.java:576)
	at net.sf.zekr.ui.QuranFormMenuFactory.changePlayerMenuState(QuranFormMenuFactory.java:1405)
	at net.sf.zekr.ui.QuranFormMenuFactory.pausePlayer(QuranFormMenuFactory.java:1392)
	at net.sf.zekr.ui.QuranFormMenuFactory.playerTogglePlayPause(QuranFormMenuFactory.java:1387)
	at net.sf.zekr.ui.AudioPlayerUiController.togglePlayPauseState(AudioPlayerUiController.java:277)
	at net.sf.zekr.engine.audio.ZekrPlayerListener$2.run(ZekrPlayerListener.java:81)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:134)
	... 17 more
Caused by: java.io.FileNotFoundException: res\image\icon\audio\player-play-rtl13.png (The system cannot find the path specified)
	at java.io.FileInputStream.open(Native Method)
	at java.io.FileInputStream.<init>(FileInputStream.java:106)
	at java.io.FileInputStream.<init>(FileInputStream.java:66)
	at org.eclipse.swt.internal.Compatibility.newFileInputStream(Compatibility.java:182)
	at org.eclipse.swt.graphics.ImageLoader.load(ImageLoader.java:156)
	... 27 more

I tested this behavior both with SWT 3.555 and 3.617 on Windows XP SP3.
Comment 1 Remy Suen CLA 2010-02-15 11:10:16 EST
Please attach code to reproduce the problem. The following works fine for me. I have the image 'test.jpg' directly in my project's root folder.

---------------

public static Image image;

public static void main(String[] args) {
	final Display display = new Display();
	final Shell shell = new Shell(display);
	shell.addDisposeListener(new DisposeListener() {
		@Override
		public void widgetDisposed(DisposeEvent e) {	
			if (image != null) {
				image.dispose();
			}
		}
	});
	shell.open();

	display.timerExec(3000, new Runnable() {

		@Override
		public void run() {

			FileDialog dialog = new FileDialog(shell);

			display.asyncExec(new Runnable() {
				@Override
				public void run() {
					image = new Image(display, "test.jpg");
					shell.setImage(image);
				}
			});
			dialog.open();
		}
	});

	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}
	display.dispose();
}
Comment 2 Mohsen Saboorian CLA 2010-02-15 13:32:30 EST
Remy, thanks for your test case. This causes again that FNFE. The parent shell can no longer re-paint when the dialog is open. So if I move the dialog, parent shell cannot redraw (seems that all event managers in that dialog are freezed). When I close the dialog the exception is thrown.

Here is the stack trace:

Exception in thread "main" org.eclipse.swt.SWTException: Failed to execute runnable (org.eclipse.swt.SWTException: i/o error (java.io.FileNotFoundException: test.jpg (The system cannot find the file specified)))
	at org.eclipse.swt.SWT.error(SWT.java:3777)
	at org.eclipse.swt.SWT.error(SWT.java:3695)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:136)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3800)
	at org.eclipse.swt.widgets.Shell.WM_ENTERIDLE(Shell.java:2100)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:3803)
	at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:337)
	at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1565)
	at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:1937)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4528)
	at org.eclipse.swt.internal.win32.OS.GetOpenFileNameW(Native Method)
	at org.eclipse.swt.internal.win32.OS.GetOpenFileName(OS.java:2612)
	at org.eclipse.swt.widgets.FileDialog.open(FileDialog.java:387)
	at test.LoadFailureTest$2.run(LoadFailureTest.java:37)
	at org.eclipse.swt.widgets.Display.runTimer(Display.java:3886)
	at org.eclipse.swt.widgets.Display.messageProc(Display.java:3091)
	at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
	at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2370)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3420)
	at test.LoadFailureTest.main(LoadFailureTest.java:42)
Caused by: org.eclipse.swt.SWTException: i/o error (java.io.FileNotFoundException: test.jpg (The system cannot find the file specified))
	at org.eclipse.swt.SWT.error(SWT.java:3777)
	at org.eclipse.swt.SWT.error(SWT.java:3695)
	at org.eclipse.swt.graphics.ImageLoader.load(ImageLoader.java:159)
	at org.eclipse.swt.graphics.ImageDataLoader.load(ImageDataLoader.java:26)
	at org.eclipse.swt.graphics.ImageData.<init>(ImageData.java:377)
	at org.eclipse.swt.graphics.Image.<init>(Image.java:735)
	at test.LoadFailureTest$2$1.run(LoadFailureTest.java:33)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:133)
	... 17 more
Caused by: java.io.FileNotFoundException: test.jpg (The system cannot find the file specified)
	at java.io.FileInputStream.open(Native Method)
	at java.io.FileInputStream.<init>(FileInputStream.java:106)
	at java.io.FileInputStream.<init>(FileInputStream.java:66)
	at org.eclipse.swt.internal.Compatibility.newFileInputStream(Compatibility.java:182)
	at org.eclipse.swt.graphics.ImageLoader.load(ImageLoader.java:156)
	... 23 more
Comment 3 Remy Suen CLA 2010-02-15 13:41:34 EST
(In reply to comment #2)
> This causes again that FNFE.

This is very strange. I do not have this problem on Windows 7.

Please zip your project and attach it to bugzilla.
Comment 4 Mohsen Saboorian CLA 2010-02-15 13:57:02 EST
Created attachment 159122 [details]
Here is the full project with Java6 and SWT 3.6M5
Comment 5 Remy Suen CLA 2010-02-15 14:18:16 EST
(In reply to comment #4)
> Created an attachment (id=159122) [details]
> Here is the full project with Java6 and SWT 3.6M5

The project you provided me works fine.

In this project the path you specify is "src/test.gif". However, your trace from comment 2 is looking for a "test.jpg" file?
Comment 6 Mohsen Saboorian CLA 2010-02-15 14:27:51 EST
> In this project the path you specify is "src/test.gif". However, your trace
> from comment 2 is looking for a "test.jpg" file?

In my previous stack trace I ran your test case in my [large] project. Since you asked to create a new project, I created one, and replaced that jpeg with a smaller gif file. I believe you can reproduce it on Windows XP, but it's so strange that such an issue is not reported yet. I search bugzilla and found nothing related. If you can run the project on an XP machine, I can be sure that I'm not the only one who see this problem :)

I'll run this code tomorrow at my office computer to check if my Laptop is not alone.
Comment 7 Remy Suen CLA 2010-02-16 07:45:06 EST
(In reply to comment #6)
> I believe you can reproduce it on Windows XP

I can reproduce this on XP SP2.
Comment 8 Mohsen Saboorian CLA 2010-02-16 23:15:18 EST
(In reply to comment #7)
> (In reply to comment #6)
> > I believe you can reproduce it on Windows XP
> 
> I can reproduce this on XP SP2.

Can you ask someone at Eclipse side if this is a dup or not?
Comment 9 Lakshmi P Shanmugam CLA 2010-02-17 07:54:02 EST
I couldn't find a duplicate of this bug.
Just tried to see where java is looking for the file, its trying to find it inside the folder containing the file selected by the File dialog. Specifying the absolute path of the file works fine.
Comment 10 Mohsen Saboorian CLA 2010-02-17 07:58:14 EST
(In reply to comment #9)
> I couldn't find a duplicate of this bug.
> Just tried to see where java is looking for the file, its trying to find it
> inside the folder containing the file selected by the File dialog. Specifying
> the absolute path of the file works fine.

Great workaround. Thank you very much.
Comment 11 Felipe Heidrich CLA 2010-02-17 15:58:15 EST
This is bug in Windows. When OPENFILENAME is up it changes the current working dir to the dir in the view. We set the flag OFN_NOCHANGEDIR but it has no effective.

The change of the working dir can not be verified by Java (calling System.getProperty("user.dir")) but it can be verified using win32 call GetCurrentDirectory().

Calls to java io (new File("relativepath/doc.txt")) also fail.
Comment 12 Leo Ufimtsev CLA 2017-08-03 12:30:15 EDT
This is a one-off bulk update. (The last one in the triage migration).

Moving bugs from swt-triaged@eclipse to platform-swt-inbox@eclipse.org and adding "triaged" keyword as per new triage process:
https://wiki.eclipse.org/SWT/Devel/Triage

See Bug 518478 for details.

Tag for notification/mail filters:
@TriageBulkUpdate
Comment 13 Eclipse Genie CLA 2019-10-20 04:11:09 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.