Take the 2-minute tour ×

We are developing java applet and embedding it in our web pages. When the applet is loaded via HTML APPLET tags, the browser/JVM prompts the user to allow it to run. When we hit cancel, the java console indicates the following exception:

java.lang.RuntimeException: java.lang.ExceptionInInitializerError
    at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ExceptionInInitializerError
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at java.lang.Class.newInstance0(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager$12.run(Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$000(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.security.AccessControlException: access denied (java.lang.RuntimePermission getenv.TEMP)
    at java.security.AccessControlContext.checkPermission(Unknown Source)
    at java.security.AccessController.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkPermission(Unknown Source)
    at java.lang.System.getenv(Unknown Source)
    at downLoadApp.<clinit>(downLoadApp.java:15)
    ... 21 more
Exception: java.lang.RuntimeException: java.lang.ExceptionInInitializerError

Now, I realize it's most likely because the class java tried to load was prevented from loading, and therefore the exception is thrown, but how do we gracefully handle this situation in the browser? I'd like to detect that the applet was denied and post a reasonable response to the condition, but I'm unaware of how to catch this exception since it appears to have been thrown by the JVM in reaction to not getting the jar file to load rather than code written in it...



share|improve this question
downLoadApp.java Please learn common Java nomenclature and use it consistently. That should be capitalized as DownLoadApp.java –  Andrew Thompson Feb 21 '12 at 16:18
add comment

3 Answers

up vote 3 down vote accepted

You can catch the access control exception by putting the call to System.getenv in downLoadApp.java line 15 in a try-catch statement. That is, instead of this:

static String tmp = System.getenv("TEMP");

you should have:

static String tmp;

static {
    try {
        tmp = System.getenv("TEMP");
    } catch (java.security.AccessControlException ace) {
        // tmp is not set, maybe use some default value?
share|improve this answer
Giving you the "closest answer"... The variable was declared globally instead of individually each time it's used, therefore causing this crash where it couldn't be try/caught. We loaded it into each function that uses it instead, so we could try/catch it, and now it is caught successfully and the applet doesn't crash and hang the whole browser! –  Rimer Feb 24 '12 at 22:21
By "declared globally" do you mean like a static variable in a class? –  Joni Feb 24 '12 at 23:56
add comment

Do you call System.getenv("TEMP") somewhere in the static context of the downLoadApp class? Most probably this is in the initializer of a static field, but it could be in a static code block.

This is the place where it fails (a java.security.AccessControlException is thrown). The rest of the stack trace are errors following from that. You need to catch this exception to detect that you don't have the appropriate permissions.

As you can't catch exceptions of static field initializers, you need to move the call to getenv into a method or a static code block.

share|improve this answer
this is more or less the issue. Joni put in code samples, so I gave it to him/her :) –  Rimer Feb 24 '12 at 22:22
add comment

I don't think that you can catch this exception as this is thrown by JVM while loading applet.

share|improve this answer
Well, I'm confused then because when this occurs, the entire browser is HUNG by the dangling plugin-container process that is dead with this exception... Shouldn't the BROWSER handle this exception? is it a FF bug? –  Rimer Feb 24 '12 at 17:34
Additionally, one of the weirdest things about Java Applets is that they seem to run even if you don't allow them to, they just run with limited permissions... So weird –  Rimer Feb 24 '12 at 22:24
add comment

Your Answer


