Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8272157

java.util.Properties.store() fails under the SecurityManager on Debian Linux



    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 11, 12, 13, 14, 15, 16
    • Fix Version/s: tbd
    • Component/s: core-libs
    • Environment:

      Open JDK 16.0.1+9-Ubuntu-120.04


    • Subcomponent:
    • Introduced In Version:
    • OS:


      This is a platform-specific bug. It affects Linux distros of the Open JDK from JDK 11 onward.

      Calling java.util.Properties.store() under a SecurityManager fails with the following exception:

      Exception in thread "main" java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "getenv.SOURCE_DATE_EPOCH")
      at java.base/java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
      at java.base/java.security.AccessController.checkPermission(AccessController.java:1036)
      at java.base/java.lang.SecurityManager.checkPermission(SecurityManager.java:408)
      at java.base/java.lang.System.getenv(System.java:1016)
      at java.base/java.util.Properties.getFormattedTimestamp(Properties.java:1599)
      at java.base/java.util.Properties.store0(Properties.java:926)
      at java.base/java.util.Properties.store(Properties.java:868)
      at DERBY_7122.main(DERBY_7122.java:37)

      The failure occurs when Properties.store0() tries to format the timestamp comment required by the javadoc contract of Properties.store(). On Linux, the exception occurs inside Properties.getFormattedTimestamp(). This method does not exist on Mac OSX distros. Instead, on Mac OSX, the timestamp is formatted via the following line of code:

      bw.write("#" + new Date().toString());

      This problem was discovered by a user of Apache Derby. The problem is described by https://issues.apache.org/jira/browse/DERBY-7122

      The following program demonstrates this problem. The program runs fine on Mac OSX up through the early access release of Open JDK 17. However, it fails on Ubuntu using Open JDK 16. According to the Derby bug report, this problem on Linux has been occurring since Open JDK 11. Here is the repro:


      import java.io.PrintWriter;
      import java.util.Properties;

       * Demonstrate that Properties.store() fails under a security manager on Ubuntu.
      public class DERBY_7122
          private static final String PROPERTY_FILE_NAME = "/tmp/derby-7122.properties";
          private static final String SECURITY_POLICY_FILE_NAME = "/tmp/derby-7122.policy";
          private static final String SECURITY_POLICY_FILE_URL = "file:" + SECURITY_POLICY_FILE_NAME;

          private final static String POLICY_FILE_PROPERTY = "java.security.policy";

          private static final String SECURITY_FILE_CONTENTS =
              "grant\n" +
              "{\n" +
              " permission java.io.FilePermission \"/tmp/-\", \"read,write,delete\";\n" +

          public static void main(String... args) throws Exception
              // write the policy file
              try (PrintWriter pw = new PrintWriter(SECURITY_POLICY_FILE_NAME))
              { pw.write(SECURITY_FILE_CONTENTS); }

              // start up a security manager using the policy file we just wrote
              System.setProperty( POLICY_FILE_PROPERTY, SECURITY_POLICY_FILE_URL );
              System.setSecurityManager( new SecurityManager() );

              // create a small Properties object
              Properties props = new Properties();
              props.setProperty("foo", "bar");

              // write the properties to disk.
              props.store(new PrintWriter(PROPERTY_FILE_NAME), "this fails on ubuntu with JVMs at level 11 and higher");



          Issue Links



              smarks Stuart Marks
              rhillegas Rick Hillegas
              0 Vote for this issue
              11 Start watching this issue