Applet permissions denied unpredictably
I have a Java 1.5 applet using SwingWorker that seems to break unpredictably due to the following error:
java.util.concurrent.ExecutionException: java.security.AccessControlException: access denied (java.lang.RuntimePermission modifyThreadGroup)
at java.util.concurrent.FutureTask$Sync.innerGet(Unknown Source)
at java.util.concurrent.FutureTask.get(Unknown Source)
at org.jdesktop.swingworker.SwingWorker.get(Unknown Source)
The applet is signed with jarsigner using a key I generated with
keytool and exported as a self signed certificate.
One pattern I often observe is that the applet works fine the first time I download it from a new browser when it pops up a dialog asking me if I want to trust the signer I created. However, if I close the first applet window and open it again from the same browser I do not get the trust dialog and the applet fails as above. This seems to happen for all subsequent applet invocations from the same browser.
I've observered this with Firefox 1.5.0.7 and IE 6.0 on Windows XPsp2.
Thank you.
# 1
> I have a Java 1.5 applet using SwingWorker that seems
> to break unpredictably due to the following error:
>
> java.util.concurrent.ExecutionException:
> java.security.AccessControlException: access denied
> (java.lang.RuntimePermission modifyThreadGroup)
> at
> java.util.concurrent.FutureTask$Sync.innerGet(Unknown
> Source)
> at java.util.concurrent.FutureTask.get(Unknown
> Source)
> at
> org.jdesktop.swingworker.SwingWorker.get(Unknown
> Source)
>
> The applet is signed with jarsigner using a key I
> generated with
> keytool and exported as a self signed certificate.
>
> One pattern I often observe is that the applet works
> fine the first time I download it from a new browser
> when it pops up a dialog asking me if I want to trust
> the signer I created. However, if I close the first
> applet window and open it again from the same browser
> I do not get the trust dialog and the applet fails as
> above. This seems to happen for all subsequent
> applet invocations from the same browser.
>
> I've observered this with Firefox 1.5.0.7 and IE 6.0
> on Windows XPsp2.
>
> Thank you.
Something is not getting shutdown properly; I'd wager your AWTEvent Thread.
To ensure this, make sure you overwrite stop/start/run/init for the Applet
as described here...
http://java.sun.com/j2se/1.3/docs/guide/misc/threadPrimitiveDeprecation.html
This is the safe way to implement stop/start. Do it this way and there are no issues and the behavior is consistent across different Thread / Event models/Operating Systems.
I personally prefer the Runnable interface as opposed to Thread BTW.
Good Luck!
(T)
# 3
> Thanks for the tip.
>
> I added a threadpool (ExecutorService) from which I
> invoked the
> SwingWorker task and overloaded JApplet.stop() to
> include
> ExecutorService.shutdown().
>
> That solved the problem.
Polling around controlThread does have one caveat IF you recusively
restart the thread from a different Thread. Thus I now opt for a volatile flag
instead. Hmm of course I am the only one I know of who ever thought of
doing such a thing :P
Don't forget them Dukes I have to grub as many as I can :)
(T)