This discussion is archived
2 Replies Latest reply: Oct 27, 2012 2:36 AM by sabre150 RSS

Problem with Logger setLevel() method in applet

John L. Newbie
Currently Being Moderated
I am executing the following line of code in an applet:

Logger.getLogger("Debug.log").setLevel(Level.ALL);

I receive an AccessControlException, with e.getPermission()="java.util.logging.LoggingPermission control"

When I do this in the policy file (following the manual, and the above direction):

grant codeBase "file://C:/Documents and Settings/All Users/Documents/XMLEHT-Develop"
{
permission java.util.logging.LoggingPermission control;
};

I get this:

java.security.policy: error parsing file:/C:/Documents%20and%20Settings/John/.java.policy:
     line 3: expected [;], found [control]

When I do this in the policy file (incorrect, but following the above error message):

grant codeBase "file://C:/Documents and Settings/All Users/Documents/XMLEHT-Develop"
{
permission java.util.logging.LoggingPermission ;
};

I get this:

java.security.policy: error adding Permission, java.util.logging.LoggingPermission:
     java.lang.NullPointerException: name can't be null

This problem occurs with JRE 1.5.0_14 installed. I also attempted re-installing Java, to no avail.

Thanks in advance for any help you may provide.

Edited by: John L. on Oct 26, 2012 12:33 PM
  • 1. Re: Problem with Logger setLevel() method in applet
    jtahlborn Expert
    Currently Being Moderated
    If you look at the examples http://docs.oracle.com/javase/6/docs/technotes/guides/security/permissions.html , you will see that the arguments are always quoted, e.g.:
    grant codeBase "file://C:/Documents and Settings/All Users/Documents/XMLEHT-Develop"
    {
      permission java.util.logging.LoggingPermission "control";
    };
  • 2. Re: Problem with Logger setLevel() method in applet
    sabre150 Expert
    Currently Being Moderated
    As all are aware Java Applets run on the client and except in a corporate environment it is difficult to edit the policy file. Added to this is the problem caused by explicitly defining where the log file is to be written since even if only targetting at Windows the "Documents and Settings" may not be on the "C" drive and on Windows 7 "Documents and Settings" is not used.

    Since modifications to the policy file are not specific to a particular Applet they can be a security nightmare. When working with Applets it is normally best sign the Applet and then to only use a users home directory (System.getProperty("user.home")) or the temp directory (System.getProperty("java.io.tmpdir")) since these are pretty much guaranteed to be available.

    I'm not overly keen on Logging especially in Applets. To my mind Logging is primarily creating an audit trail (especially when things go wrong) and if the log file is on the client how is the Applet writer going to access the log file?

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points