Bug 63306 - Web Start: Invalid thread access
Summary: Web Start: Invalid thread access
Status: RESOLVED NOT_ECLIPSE
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.0   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 normal with 3 votes (vote)
Target Milestone: ---   Edit
Assignee: Scott Kovatch CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 98553 (view as bug list)
Depends on: 67384
Blocks:
  Show dependency tree
 
Reported: 2004-05-20 16:02 EDT by Irwin CLA
Modified: 2011-04-13 09:07 EDT (History)
30 users (show)

See Also:


Attachments
Mac OS X invalid thread access (102.62 KB, image/gif)
2004-05-20 16:03 EDT, Irwin CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Irwin CLA 2004-05-20 16:02:25 EDT
I m getting an invalid thread access error when starting my app with Mac OS X.
It works fine under windows and Linux.
That s what makes me think it s a SWT Mac OS X bug...

Attached is a screenshot of the error /app .
Comment 1 Irwin CLA 2004-05-20 16:03:33 EDT
Created attachment 10916 [details]
Mac OS X invalid thread access

I know this bug is going to be difficult to fix with only that info. But such a
general error makes me think : 1) either I miss something  2) or we are in big
trouble :)
Comment 2 Grant Gayed CLA 2004-05-21 09:54:42 EDT
SSQ should we ever receive events in a non-UI thread?
Comment 3 Silenio Quarti CLA 2004-05-21 14:41:50 EDT
How do you start your app? Do you run the "java_swt" executable?
Comment 4 Irwin CLA 2004-05-21 20:48:52 EDT
My app is started directly from Java Web Start, from the browser.

I also started it directly command line under mac os X, with Java\ Web\ Start .

In both cases I have the same exceptions.
Comment 5 Andre Weinand CLA 2004-05-24 11:17:29 EDT
Java Web Start is not supported with SWT based applications.
Comment 6 Tomas Nord CLA 2004-05-24 12:57:24 EDT
Ouch... Will it ever be?
Comment 7 Irwin CLA 2004-05-24 15:53:32 EDT
Java web start not supported ? This is weird.
1) many articles from IBM show how to use JWS & SWT. And it works like a charm
under Linux & Windows.
2) I don t think there is a need for JWS support. Everything Java is supposed to
run with JWS, and I m very confident on that point. If SWT does not support JWS,
it looks like SWT does not support Java somewhere.

I d like more clarifications on that point.... should it be the answer of that bug.
Comment 8 Irwin CLA 2004-06-01 08:59:43 EDT
I was able to run the application from command Line instead of Java web start,
at my surprise.
I am used to run JWS & SWT under windows & linux. Is there any specific reason
why  it does not work with Mac. ? Shall we take the windows & linux
compatibility as a lucky fact ? 
Comment 9 Silenio Quarti CLA 2004-06-01 11:39:25 EDT
Andre,

You know more about this problem than me. Please could you explain why we need 
the java_swt executable?  For a short answer, we need to run main() in the 
carbon UI thread.
Comment 10 Andre Weinand CLA 2004-06-01 11:51:22 EDT
You find the full story why we need java_swt in comment 3 of bug #40003.

> I was able to run the application from command Line instead of Java web start,
at my surprise.
In MacOS X? If yes, what exactly did you do?
Comment 11 Irwin CLA 2004-06-01 12:27:09 EDT
Yes under Mac OS X. I just run from command line using java , not java_swt.
So it appears to be a well known 'bug' of javaswt / mac OS X. I think we can
close this bug, unless you have other comments.
Comment 12 Andre Weinand CLA 2004-06-01 15:32:23 EDT
And your app uses SWT ?
Comment 13 Irwin CLA 2004-06-01 15:42:41 EDT
yes it does. This is the app described above, which when launched from javaws
gives the invalid thread access. When run from command line, it works fine.
Both tries under mac OS X.
Comment 14 Veronika Irvine CLA 2005-06-07 09:18:04 EDT
*** Bug 98553 has been marked as a duplicate of this bug. ***
Comment 15 Andre Weinand CLA 2005-06-24 07:21:02 EDT
I've debugged webstart with SWT on MacOS X and here is the result:
- the attribute java-vm-args="-XstartOnFirstThread" doesn't have an effect.
   As a consequence the Java VM runs in the wrong thread and SWT apps appear,
   but don't react to user input.
- I replaced /usr/bin/java with a shell script that passes a -XstartOnFirstThread
   to the original java VM. In this case webstarts aborts because it tries to launch AWT which fails
   because it runs in the wrong thread. This scenario shows that even if 
   java-vm-args="- XstartOnFirstThread" would be passed to the VM,
   running SWT would still not work.

This Catch-22 can only be solved by either fixing the SWT/AWT interoperability issues,
or by running a fresh Java VM for the application being launched via webstart (so that AWT and SWT
are not used within the same Java VM).
Comment 16 Andre Weinand CLA 2005-07-20 06:34:32 EDT
Since I cannot solve the SWT/AWT interoperability issues, I'm reassigning bug to SWT inbox.
Comment 17 Steve Northover CLA 2005-07-20 17:20:12 EDT
Todd, is there anything we can do on the Mac to have JWS start on the *right* 
thread?  

NOTE: If JWS uses AWT, then this is bug is another instance of bug 67384 and 
can possibly be closed as a dup.  When multiple operating system GUI threads 
work in the same process on a Mac, then JWS should work the same way it does 
on Windows and Linux.
Comment 18 Steve Northover CLA 2006-06-05 10:46:57 EDT
Scott, now that we can interoperate with AWT/Swing, working with WebStart would be great.  Any ideas?
Comment 19 Scott Kovatch CLA 2006-06-05 11:22:48 EDT
This will need some work on our part. I can make -XstartOnFirstThread a 'safe' VM option, so that it gets passed to the JVM, but the problem is that a lot of AWT code is executed long before the SWT's event loop starts. My current thinking is that we need the runloop running on thread 0, much like we do in the AWT.

Another possibility is to start up the AWT as we do now, but when the actual application is about to launch, shut down the NSApplication and let the SWT event handling take over.
Comment 20 Brant Hahn CLA 2006-07-31 11:00:18 EDT
adding myself to the CC list
Comment 21 Brant Hahn CLA 2006-07-31 11:12:47 EDT
Does this bug depend on bug #145890? (which was spawned from bug #67384)
Comment 22 Scott Kovatch CLA 2006-07-31 11:18:08 EDT
Completely unrelated. 145890 involves embedding an SWT shell into an AWT window. This bug deals with the fact that Web Start on Mac OS X is starting up in such a way that the SWT cannot be used.
Comment 23 Steve Northover CLA 2006-09-25 19:48:53 EDT
Any progress on this?  It would be nice for Webstart to work on the Mac.
Comment 24 Scott Kovatch CLA 2006-09-25 20:05:31 EDT
Nothing new to report right now. We have some core problems with SWT and AWT running together that I need to address first. Once that happens I can look at having the SWT start after the AWT which is the root problem here.
Comment 25 Patrick _ CLA 2006-11-06 14:32:59 EST
added myself to cc
Comment 26 Dimitry E Voytenko CLA 2006-12-01 14:24:17 EST
added myself to cc

This is critical for us as well. Is there any dirty fixes at all?
Comment 27 Brant Hahn CLA 2006-12-06 13:22:28 EST
Do we have any updates on this issue?  Just curious here...

thx
Comment 28 Scott Kovatch CLA 2006-12-06 13:43:30 EST
See comment 24. This may not get fixed until the AWT can do work on the main thread.
Comment 29 Remi Nodet CLA 2007-02-21 01:18:33 EST
It seems that the latest version of java 1.5.0 released by apple fixes some SWT-AWT problems. Does this mean we will be able to start SWT applications from java web start soon ? ;-)

http://developer.apple.com/releasenotes/Java/Java104R5RN/ResolvedIssues/chapter_3_section_10.html#//apple_ref/doc/uid/TP40005278-CH3-DontLinkElementID_26
Comment 30 Brant Hahn CLA 2007-02-21 09:10:00 EST
We've been running 1.5 since the summer, and this bug still exists.  1.6 is the latest 'stable' version... I haven't seen if 1.6 fixes the issue yet or not since we are holding off from upgrading.
Comment 31 Johannes Rudolph CLA 2007-03-14 18:00:52 EDT
added myself to cc
Comment 32 Scott Kovatch CLA 2007-05-23 20:15:38 EDT
Lots of progress here, but unfortunately it requires a change to the JVM and Web Start, not the SWT. Look for an update in the next day or so.
Comment 33 Scott Kovatch CLA 2007-05-25 11:20:41 EDT
Checked this in last night for our Java 1.5 in Leopard. To use this, you will need to let the JVM know you're going to use the SWT:

  <resources os="Mac OS X">
    <j2se version="1.5*" java-vm-args="-XstartOnFirstThread"/>
    <jar href="SWTWebStart.jar"/>
  </resources>

I will move to resolved/fixed when a public build with this fix is available.
Comment 34 Steve Northover CLA 2007-05-25 12:06:19 EDT
We need to remember to update http://www.eclipse.org/swt/jws/ to include a Mac example and get rid of the warning.
Comment 35 Brant Hahn CLA 2007-06-01 10:06:24 EDT
Ok, so let me understand this (correct me if I'm wrong here): the next public build for Java 1.5/1.6 on Leopard will contain this fix and when it's out there, we just need the reference to the SWTWebStart.jar in the JNLP?
Comment 36 Scott Kovatch CLA 2007-06-01 23:11:48 EDT
Sorry, my previous comment wasn't clear:

  <resources os="Mac OS X">
    ....
    <j2se version="1.5*" java-vm-args="-XstartOnFirstThread"/>
    ....
  </resources>

The 'java-vm-args="-XstartOnFirstThread"' is the important part. The next public build of Leopard 1.5 will have this support, which is why I wrote the resources section this way. The JAR file was from a local test, and not relevant here.

I still need to merge it into 1.6, but I'm also not commenting when that will be released. I'll update here when that happens.
Comment 37 Ivan Mising name CLA 2007-06-01 23:16:02 EDT
Hi, will this "features" available in Tiger ?

Thanks
Comment 38 Scott Kovatch CLA 2007-06-04 12:02:13 EDT
I should be able to put this back into a Tiger update, but I make no promises as to when that will be right now.
Comment 39 Laurent Jourdren CLA 2007-06-05 10:02:47 EDT
(In reply to comment #36)
> Sorry, my previous comment wasn't clear:
> 
>   <resources os="Mac OS X">
>     ....
>     <j2se version="1.5*" java-vm-args="-XstartOnFirstThread"/>
>     ....
>   </resources>
> 
> The 'java-vm-args="-XstartOnFirstThread"' is the important part. The next
> public build of Leopard 1.5 will have this support, which is why I wrote the
> resources section this way. The JAR file was from a local test, and not
> relevant here.
> 
> I still need to merge it into 1.6, but I'm also not commenting when that will
> be released. I'll update here when that happens.
 
  Does your fix works also with others java graphical toolkits that need "-XstartOnFirstThread" JVM argument on start like QtJambi ?

  Thread about the issue between JWS and Jambi under OSX:
  http://lists.trolltech.com/qt-jambi-interest/2007-03/thread00073-0.html

  How build native QtJambi jar for Mac OS X:
  http://lists.trolltech.com/qt-jambi-interest/2007-06/thread00003-0.html


Comment 40 Scott Kovatch CLA 2007-06-05 11:47:23 EDT
Does QT-Jambi run its own event loop like the SWT does? Looking at QApplication's javadoc page, it looks like it does, so then, yes, this change is probably useful for QTJambi as well.
Comment 41 Scott Kovatch CLA 2007-06-18 17:07:04 EDT
Fixed in the Leopard seed distributed at WWDC. If you have this build, you can verify that the fix is there.
Comment 42 James Kenny CLA 2008-03-17 07:06:48 EDT
I noticed this bug is marked as fixed so does that close the book for Tiger compatibility? :(
Comment 43 Scott Kovatch CLA 2008-03-17 13:29:27 EDT
(In reply to comment #42)
> I noticed this bug is marked as fixed so does that close the book for Tiger
> compatibility? :(

I can't recall right now if we back-ported this into the last Tiger update released at the end of 2007. I have this vague recollection that I did, but I'm not sure now.

I no longer work for Apple, but please file a bug at bugreport.apple.com to remind  someone that this can and should go back into Tiger.
Comment 44 Rafael Chaves CLA 2009-06-17 21:25:15 EDT
Shouldn't this issue have a target milestone? That is usually the field used for reporting when an issue was fixed, whereas the Version field describes what version it was reported against.
Comment 45 Silenio Quarti CLA 2009-06-18 10:47:43 EDT
This was fixed in the JRE, not in SWT. So there is no eclipse target milestone we can set.

Scott, do you call what java update fixed this?
Comment 46 Rafael Chaves CLA 2009-06-18 10:50:09 EDT
Thanks for clarifying, Silenio. I guess the FIXED resolution is misleading.
Comment 47 Silenio Quarti CLA 2009-06-18 11:02:24 EDT
Yes, it should have been NOT_ECLIPSE.
Comment 48 Scott Kovatch CLA 2009-06-18 16:21:03 EDT
This was fixed in the released Mac OS X 10.5 (see comment #41) -- no additional updates needed. I'm changing the resolution to NOT_ECLIPSE since it was a Mac JVM fix that took care of it.

I'm almost certain it was not back-ported to 10.4, since it's not security-related.
Comment 49 Hendy Irawan CLA 2010-03-31 18:10:06 EDT
Please update http://www.eclipse.org/swt/jws/ noting that this bug no longer applies with recent Mac OS X versions.
Comment 50 Scott Kovatch CLA 2010-03-31 18:59:14 EDT
(In reply to comment #49)
> Please update http://www.eclipse.org/swt/jws/ noting that this bug no longer
> applies with recent Mac OS X versions.

Good catch -- the comment at the bottom of that page is indeed no longer valid.

I believe Carolyn owns the web pages, so I'll ask her to update it.
Comment 51 Carolyn MacLeod CLA 2010-04-01 10:06:23 EDT
Done. I took it out of the SWT FAQ also.
Comment 52 Heiko Roth CLA 2011-02-09 08:19:42 EST
Please reopen this bug because of Mac OS X 10.6.6 this bug exists.
I think, javaws ignores parameter -XstartOnFirstThread. This problem only occurs on launching application with Java Webstart.

Starting on shell only with java and parameter -XstartOnFirstThread does well.
Without this parameter, the same error occurs.

javaws -J-XstartOnFirstThread

doesn't work, too.
Comment 53 Felipe Heidrich CLA 2011-04-11 15:09:16 EDT
Mike, Scott

Do you guys know anything about -XstartOnFirstThread being broken for web start with 10.6.6 ?
Comment 54 Mike Swingler CLA 2011-04-11 16:05:33 EDT
(In reply to comment #53)
> Do you guys know anything about -XstartOnFirstThread being broken for web start
> with 10.6.6 ?

I do not believe we have changed the -XstartOnFirstThread code path at all in any of the Java updates for Mac OS X 10.6.

If you have specific steps to reproduce, I would suggest that you file a new bug.
Comment 55 Silenio Quarti CLA 2011-04-11 16:23:35 EDT
I just tried the latest SWT code on 10.6.7 and found this bug#342488 which was caused by the changes released for bug#329456 on March 3th, 2011 (which is after the date of comment#52).

Other than bug#342488 everything seems to be working fine. I do not get an Invalid
thread access exception if the jnlp file specifies -XstartOnFirstThread properly. 

Heiko Roth, please try the test case attached to bug#342488 (note that you need to update the path in the jnlp file) and let me know if it works for you. I do not think this bug is back.
Comment 56 Heiko Roth CLA 2011-04-13 09:07:26 EDT
(In reply to comment #55)
> Other than bug#342488 everything seems to be working fine. I do not get an
> Invalid
> thread access exception if the jnlp file specifies -XstartOnFirstThread
> properly. 
> 
> Heiko Roth, please try the test case attached to bug#342488 (note that you need
> to update the path in the jnlp file) and let me know if it works for you. I do
> not think this bug is back.

Thank you for the example in bug#342488. It worked out of the box.
We found the problem inside our jnlp file.

    <resources>
 	<!-- REMOVED   <j2se version="1.6+" />  REMOVED -->
       <!-- Application Resources -->
        <jar href="javaclient-3796.jar" main="true" />
        <jar href="lib/apache-mime4j-0.6.jar" />
        <jar href="lib/commons-codec-1.3.jar" />
        <jar href="lib/commons-httpclient-3.1.jar" />
        <jar href="lib/commons-logging-1.1.1.jar" />
        <jar href="lib/json_simple-1.1.jar" />
    </resources>
    <resources os="Mac OS X" arch="x86_64">
		<j2se version="1.6+" java-vm-args="-XstartOnFirstThread" />
		<jar href="lib/swt-macosx.jar" />
    </resources>

We removed the first <j2se version="1.6+" /> entry and everything worked fine.
Thanks.