Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 326174 - WebSite.createTempStorage() fails with STG_E_INVALIDNAME
Summary: WebSite.createTempStorage() fails with STG_E_INVALIDNAME
Status: RESOLVED NOT_ECLIPSE
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.6.1   Edit
Hardware: PC Windows 7
: P3 blocker with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Grant Gayed CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-24 12:29 EDT by Gabriel Petrovay CLA
Modified: 2010-11-09 14:08 EST (History)
1 user (show)

See Also:


Attachments
Instructions to reproduce (15.74 KB, application/octet-stream)
2010-09-26 09:09 EDT, Gabriel Petrovay CLA
no flags Details
New Instructions to reproduce (15.91 KB, application/octet-stream)
2010-11-01 18:24 EDT, Gabriel Petrovay CLA
no flags Details
The wrongly displayed Eclipse Wellcome page (112.22 KB, image/png)
2010-11-09 05:40 EST, Gabriel Petrovay CLA
no flags Details
The Internal browser is missing (180.47 KB, image/png)
2010-11-09 05:44 EST, Gabriel Petrovay CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Gabriel Petrovay CLA 2010-09-24 12:29:32 EDT
Hi,

There must be a bug somewhere in there on Windows 7 at least. This happens only when running SWTBot in headless mode. The effect is that the internal web browser is not available. The code below shows why this is not available: because of WebSite.createTempStorage() -> COM.StgCreateDocfile(...) fails with STG_E_INVALIDNAME.

I also ran it "as Administrator" to make sure there are no permission problems. But the behaviour is the same.

I have one test containing the lines below. I run this test with SWTBot in headless mode:

public void test_InternalBrowser() throws Exception {
  final StringBuffer sb = new StringBuffer();

  PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
    public void run() {
      sb.append("canUseInternalWebBrowser: " + WebBrowserUtil.canUseInternalWebBrowser() + "\n");
    }
  });

  try {
    Class.forName("org.eclipse.swt.browser.Browser");
    sb.append("class \"org.eclipse.swt.browser.Browser\" found.\n");
  } catch (ClassNotFoundException e) {
    sb.append("class \"org.eclipse.swt.browser.Browser\" not found.\n");
  }
  assertTrue(sb.toString(), false);
}


The output is:
canUseInternalWebBrowser: false
class "org.eclipse.swt.browser.Browser" found


The problem is that WebBrowserUtil.canUseInternalWebBrowser() tries to construct a Browser object. The call goes down to org.eclipse.swt.browser.WebSite.createTempStorage() method inherited from org.eclipse.swt.ole.win32.OleClientSite:

protected IStorage createTempStorage() {
  int /*long*/[] tempStorage = new int /*long*/[1];
  int grfMode = COM.STGM_READWRITE | COM.STGM_SHARE_EXCLUSIVE | COM.STGM_DELETEONRELEASE;
  int result = COM.StgCreateDocfile(null, grfMode, 0, tempStorage);
  if (result != COM.S_OK) OLE.error(OLE.ERROR_CANNOT_CREATE_FILE, result);
    return new IStorage(tempStorage[0]);
}


After the call to the native method COM.StgCreateDocfile(...) result has the value -2147286788. This translates to 0x800300FC which is STG_E_INVALIDNAME
http://msdn.microsoft.com/en-us/library/aa380323(VS.85).aspx

1. Why is the name not valid if NULL is also a valid input value as the page above describes? Was there missing in the initialization of Eclipse/SWT (reponsability of SWTBot I guess)?

2. Eclipse calls this function many times and it always succeeds called in the same way (providing NULL as the first parameter). Is also succeeds when SWTBot is hosted in Eclipse (the framework/SWT/environment/etc. is already set up by the Eclipse host. But in headless mode, when SWTBot starts Eclipse (using the application: org.eclipse.swtbot.eclipse.junit4.headless.swtbottestapplication), something is missing.

Any idea what is going wrong here?

Thanks!
Gabriel
Comment 1 Gabriel Petrovay CLA 2010-09-24 13:06:57 EDT
If this can help, Eclipse was started like this:

     [echo] SWTBot tests
fileset: Setup scanner in dir D:\s\plugins with patternSet{ includes: [org.eclipse.equinox.launcher_*.jar] excludes: [] }
     [java] Executing 'C:\Program Files\Java\jre6\bin\java.exe' with arguments:
     [java] '-Xms256M'
     [java] '-Xmx768M'
     [java] '-XX:MaxPermSize=512M'
     [java] '-Xdebug'
     [java] '-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1044'
     [java] '-classpath'
     [java] 'D:\s\plugins\org.eclipse.equinox.launcher_1.1.0.v20100507.jar'
     [java] 'org.eclipse.core.launcher.Main'
     [java] '-application'
     [java] 'org.eclipse.swtbot.eclipse.junit4.headless.swtbottestapplication'
     [java] '-data'
     [java] 'D:\s/test-workspace'
     [java] 'formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,D:\s/result.xml'
     [java] 'formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter'
     [java] '-testPluginName'
     [java] 'mt.plugin.to.test'
     [java] '-className'
     [java] 'my.test.plugin.AllTests'
     [java] '-os'
     [java] 'win32'
     [java] '-ws'
     [java] 'win32'
     [java] '-arch'
     [java] 'x86'
     [java] '-consoleLog'
     [java] '-debug'


And my.test.plugin.AllTests contains:


public static Test suite() {
  TestSuite suite = new TestSuite();

  suite.addTestSuite(InitTestCase.class);

  return suite;
}

and InitTestCase contains the test shown in the previous comment:

public void test_InternalBrowser() throws Exception {
  // from previous comment
}
Comment 2 Gabriel Petrovay CLA 2010-09-24 13:19:17 EDT
More links:

if you wonder what "org.eclipse.swtbot.eclipse.junit4.headless.swtbottestapplication" is doing, here is the code:

http://dev.eclipse.org/viewcvs/index.cgi/trunk/org.eclipse.swtbot.eclipse.junit4.headless/src/org/eclipse/swtbot/eclipse/junit4/headless/UITestApplication.java?view=markup&root=Technology_SWTBot
Comment 3 Gabriel Petrovay CLA 2010-09-25 14:07:17 EDT
This happens also in 3.6.1
Comment 4 Gabriel Petrovay CLA 2010-09-26 09:09:28 EDT
Created attachment 179585 [details]
Instructions to reproduce

I have attached a zip file to reproduce the problem on Windows 7 with Eclipse 3.6.1
Comment 5 Gabriel Petrovay CLA 2010-09-26 09:14:51 EDT
Added Ketan from SWTBot to this bug CC.
Comment 6 Grant Gayed CLA 2010-09-28 11:32:59 EDT
On XP this seems to work for me as expected.  On Windows 7 the launch.bat runs to completion but eclipse is never launched, so perhaps something's a bit wrong with my setup on that machine.  Regardless, the success on XP indicates that the problem you see on Windows 7 is likely an swt issue.
Comment 7 Gabriel Petrovay CLA 2010-09-28 18:17:35 EDT
Make sure to pick the ant in the org.apache.ant plug-in to make sure we have the same scenarios.
Comment 8 Gabriel Petrovay CLA 2010-09-28 18:59:45 EDT
(In reply to comment #6)
> On XP this seems to work for me as expected.  On Windows 7 the launch.bat runs
> to completion but eclipse is never launched, so perhaps something's a bit wrong
> with my setup on that machine.  Regardless, the success on XP indicates that
> the problem you see on Windows 7 is likely an swt issue.

Or maybe you have jre6_21 installed? (Known problem on Windows)
http://wiki.eclipse.org/FAQ_How_do_I_run_Eclipse%3F (Notice the note in the first section)

In this case you have to revert to jre6_20
Comment 9 Gabriel Petrovay CLA 2010-11-01 18:24:25 EDT
Created attachment 182180 [details]
New Instructions to reproduce

Added a slightly updated sample code. Just follow the steps in the README file. This happens only in Windows 7. I removed the debugging JVM and ant flags.

I tested it in Windows Vista and Windows XP. Everything works just fine. But in Windows 7 you must get in the console the failed assertion below. I have tested this with Eclipse 3.6 and 3.6.1 on two different Windows 7 machines. Every time the same:

default:
     [java] Exception in thread "WorkbenchTestable" org.eclipse.core.runtime.AssertionFailedException: assertion failed: Cannot use internal Web browser.
     [java]     at org.eclipse.core.runtime.Assert.isTrue(Assert.java:110)
     [java]     at my.test.app.MyApp.runTests(MyApp.java:72)
     [java]     at org.eclipse.ui.internal.testing.WorkbenchTestable$1.run(WorkbenchTestable.java:71)
     [java]     at java.lang.Thread.run(Unknown Source)


Anyone, any news on this?
Comment 10 Gabriel Petrovay CLA 2010-11-03 19:15:19 EDT
Can someone give this a try on a Windows 7 machine? It should be easy:

launch.bat path\to\eclipse

wait about 5-10 seconds until eclipse starts.

1. Does the Wellcome page look ok?
   if white and all icons aligned in a central line, than that's the problem
2. Ctrl-3 -> Web Broser -> enter
   if you see an error in the browser view, that's the problem again
3. Preferences -> search for Browser
   if "Use internal web browser" is disabled, that's the problem once again

everything happens because of OleClientSite:543:
int result = COM.StgCreateDocfile(null, grfMode, 0, tempStorage);
result has a big weird value instead of 0 (COM.S_OK)

:( we are pretty much blocked on this

Thanks for help!
Comment 11 Grant Gayed CLA 2010-11-04 17:50:12 EDT
I got your scenario to run on our Windows 7 machine (your plug-in was previously not resolving because the installed jre was 1.5.0).  However I do not see the problem.  Eclipse now comes up for me, but Welcome page shows its HTML content fine (not the white screen), and the internal web browser view works as well.  So there's presumably a difference between our machines.

If the Browser works for you when not in headless mode, then as you say there could be some initialization missing.  createTempStorage() is one of the first calls made on the site, so it may just happen to be the first place where a bad state shows through.

I assume that test_InternalBrowser() is run in a non-UI thread, hence the syncExec() it contains.  OleInitialize(0) is called when a Display is created, but I wonder if the Display may have been created on the wrong thread (OleInitialize(0) needs to be called on each COM apartment).  I'm going to ask SSQ about this tomorrow, but as a quick experiment in the meantime, can you add "OS.OleInitialize(0)" to your snippet just before the call to canUseInternalWebBrowser() ?  I'm not sure if it will help, but it may at least rule out one possibility.
Comment 12 Gabriel Petrovay CLA 2010-11-09 05:40:03 EST
(In reply to comment #11)
> I assume that test_InternalBrowser() is run in a non-UI thread, hence the
> syncExec() it contains.  OleInitialize(0) is called when a Display is created,
> but I wonder if the Display may have been created on the wrong thread
> (OleInitialize(0) needs to be called on each COM apartment).  I'm going to ask
> SSQ about this tomorrow, but as a quick experiment in the meantime, can you add
> "OS.OleInitialize(0)" to your snippet just before the call to
> canUseInternalWebBrowser() ?  I'm not sure if it will help, but it may at least
> rule out one possibility.

A call to OleInitialize(0) does not help. The welcome page still messed-up (see the attached png). Internal web browser not available.
Comment 13 Gabriel Petrovay CLA 2010-11-09 05:40:50 EST
Created attachment 182693 [details]
The wrongly displayed Eclipse Wellcome page
Comment 14 Gabriel Petrovay CLA 2010-11-09 05:44:09 EST
Created attachment 182695 [details]
The Internal browser is missing
Comment 15 Gabriel Petrovay CLA 2010-11-09 08:13:17 EST
Finally, I found the problem (not the solution):

Execute this before calling launch.bat

SET TMP=non_existing_directory_or_empty


If TMP is not pointing to an existing directory you will get the behaviour described. If this is a bug or not, I don't know.

Can you please confirm that this is the case also for you? And is this a bug?

Thanks!
Comment 16 Grant Gayed CLA 2010-11-09 14:08:07 EST
Yes, I can confirm that I see this as well (thanks for figuring this out).  I guess it makes sense given where the failure is occuring.

I've talked to SSQ about this, and it's not an eclipse/swt bug since it's caused by a user setting that's not valid.  Closing.