changeset 86:3e262febedc3

8067184: Missing doPriveleged() {} blocks in Configuration.java Summary: Do doPrivileged() for all system properties access. Reviewed-by: raimandi
author snazarki
date Thu, 22 Jan 2015 14:19:29 +0400
parents 76b295ea4035
children c6c932e7ba18
files src/se/classes/com/oracle/dio/utils/Configuration.java
diffstat 1 files changed, 13 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/src/se/classes/com/oracle/dio/utils/Configuration.java	Thu Jan 22 14:16:54 2015 +0400
+++ b/src/se/classes/com/oracle/dio/utils/Configuration.java	Thu Jan 22 14:19:29 2015 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -48,7 +48,7 @@
      * @exception  IllegalArgumentException if <code>key</code> is empty.
      */
     public static String getProperty(String key) {
-        return System.getProperty(key);
+        return getPropertyDefault(key, null);
     }
 
     /**
@@ -58,11 +58,7 @@
      * @return property value
      */
     public static String getSystemProperty(final String key) {
-        return AccessController.doPrivileged(new PrivilegedAction<String>() {
-                public String run() {
-                    return System.getProperty(key);
-                }
-            });
+        return getPropertyDefault(key, null);
     }
 
     /**
@@ -80,8 +76,12 @@
      *             <code>null</code>.
      * @exception  IllegalArgumentException if <code>key</code> is empty.
      */
-    public static String getPropertyDefault(String key, String def) {
-        return System.getProperty(key, def);
+    public static String getPropertyDefault(final String key, final String def) {
+        return AccessController.doPrivileged(new PrivilegedAction<String>() {
+                public String run() {
+                    return System.getProperty(key, def);
+                }
+            });
     }
 
     /**
@@ -103,7 +103,7 @@
      * @exception  IllegalArgumentException if <code>key</code> is empty.
      */
     public static int getPositiveIntProperty(String key, int def) {
-        int value = Configuration.getIntProperty(key, def);
+        int value = getIntProperty(key, def);
         return (value > 0 ? value : def);
     }
 
@@ -124,7 +124,7 @@
      * @exception  IllegalArgumentException if <code>key</code> is empty.
      */
     public static int getNonNegativeIntProperty(String key, int def) {
-        int value = Configuration.getIntProperty(key, def);
+        int value = getIntProperty(key, def);
         return (value >= 0 ? value : def);
     }
 
@@ -146,7 +146,7 @@
      * @exception  IllegalArgumentException if <code>key</code> is empty.
      */
     public static int getIntProperty(String key, int def) {
-        String value = System.getProperty(key);
+        String value = getPropertyDefault(key, null);
         if (value != null) {
             try {
                 return Integer.valueOf(value).intValue();
@@ -174,7 +174,7 @@
      * @exception  IllegalArgumentException if <code>key</code> is empty.
      */
     public static boolean getBoolProperty(String key, boolean def) {
-        String value = System.getProperty(key);
+        String value = getPropertyDefault(key, null);
         if (value != null) {
             try {
                 return Boolean.valueOf(value).booleanValue();
@@ -183,40 +183,4 @@
         }
         return def;
     }
-
-    /**
-     * Set the implementation property indicated by the specified key.
-     *
-     * @param      key   the name of the implementation property.
-     * @param      val   the value of the implementation property.
-     *
-     * @exception  NullPointerException if <code>key</code> is
-     *             <code>null</code>.
-     * @exception  IllegalArgumentException if <code>key</code> is empty.
-     */
-    public static void setProperty(String key, String val) {
-        System.setProperty(key, val);
-    }
-
-    /**
-     * Gets all system properties names.
-     *
-     * @return  the string contains space separated system properties list
-     */
-    public static String getSystemPropertiesNames() {
-        Properties props = AccessController.doPrivileged(new PrivilegedAction<Properties>() {
-                public Properties run() {
-                    return System.getProperties();
-                }
-            });
-        String result = new String();
-        try {
-            Enumeration<?> names = props.propertyNames();
-            while (names.hasMoreElements()) {
-                result += (String)names.nextElement() + " ";
-            }
-        } catch (ClassCastException e) {
-        }
-        return result;
-    }
 }