Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 76196 invoked from network); 22 May 2003 21:51:54 -0000 Received: from exchange.sun.com (192.18.33.10) by daedalus.apache.org with SMTP; 22 May 2003 21:51:54 -0000 Received: (qmail 24020 invoked by uid 97); 22 May 2003 21:54:07 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@nagoya.betaversion.org Received: (qmail 24013 invoked from network); 22 May 2003 21:54:06 -0000 Received: from daedalus.apache.org (HELO apache.org) (208.185.179.12) by nagoya.betaversion.org with SMTP; 22 May 2003 21:54:06 -0000 Received: (qmail 73944 invoked by uid 500); 22 May 2003 21:51:28 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 73904 invoked by uid 500); 22 May 2003 21:51:27 -0000 Received: (qmail 73890 invoked from network); 22 May 2003 21:51:27 -0000 Received: from icarus.apache.org (208.185.179.13) by daedalus.apache.org with SMTP; 22 May 2003 21:51:27 -0000 Received: (qmail 13865 invoked by uid 1529); 22 May 2003 21:51:26 -0000 Date: 22 May 2003 21:51:26 -0000 Message-ID: <20030522215126.13864.qmail@icarus.apache.org> From: scolebourne@apache.org To: jakarta-commons-cvs@apache.org Subject: cvs commit: jakarta-commons/lang/src/java/org/apache/commons/lang SystemUtils.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N scolebourne 2003/05/22 14:51:26 Modified: lang/src/java/org/apache/commons/lang SystemUtils.java Log: Reworked class to avoid security exceptions from Michael Becke Revision Changes Path 1.10 +135 -29 jakarta-commons/lang/src/java/org/apache/commons/lang/SystemUtils.java Index: SystemUtils.java =================================================================== RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/SystemUtils.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- SystemUtils.java 14 May 2003 17:13:00 -0000 1.9 +++ SystemUtils.java 22 May 2003 21:51:26 -0000 1.10 @@ -55,12 +55,16 @@ /** *

Common System class helpers.

+ * + *

If a particular system property cannot be read due to security + * restrictions, the field will return null.

* * @author Based on code from Avalon Excalibur * @author Based on code from Lucene * @author Stephen Colebourne * @author Steve Downey * @author Gary Gregory + * @author Michael Becke * @since 1.0 * @version $Id$ */ @@ -81,224 +85,309 @@ * The file.separator System Property. * File separator ("/" on UNIX). * First in JDK version 1.1. + *

+ * Defaults to null if the runtime does not have + * security access to read this property. */ - public static final String FILE_SEPARATOR = System.getProperty("file.separator"); + public static final String FILE_SEPARATOR = getSystemProperty("file.separator"); /** * The java.class.path System Property. * Java class path. * First in JDK version 1.1. + *

+ * Defaults to null if the runtime does not have + * security access to read this property. */ - public static final String JAVA_CLASS_PATH = System.getProperty("java.class.path"); + public static final String JAVA_CLASS_PATH = getSystemProperty("java.class.path"); /** * The java.class.version System Property. * Java class format version number. * First in JDK version 1.1. + *

+ * Defaults to null if the runtime does not have + * security access to read this property. */ - public static final String JAVA_CLASS_VERSION = System.getProperty("java.class.version"); + public static final String JAVA_CLASS_VERSION = getSystemProperty("java.class.version"); /** * The java.compiler System Property. * Name of JIT compiler to use. * First in JDK version 1.4. + *

+ * Defaults to null if the runtime does not have + * security access to read this property. */ - public static final String JAVA_COMPILER = System.getProperty("java.compiler"); + public static final String JAVA_COMPILER = getSystemProperty("java.compiler"); /** * The java.ext.dirs System Property. * Path of extension directory or directories. * First in JDK version 1.3. + *

+ * Defaults to null if the runtime does not have + * security access to read this property. */ - public static final String JAVA_EXT_DIRS = System.getProperty("java.ext.dirs"); + public static final String JAVA_EXT_DIRS = getSystemProperty("java.ext.dirs"); /** * The java.home System Property. * Java installation directory. * First in JDK version 1.1. + *

+ * Defaults to null if the runtime does not have + * security access to read this property. */ - public static final String JAVA_HOME = System.getProperty("java.home"); + public static final String JAVA_HOME = getSystemProperty("java.home"); /** * The java.io.tmpdir System Property. * Default temp file path. * First in JDK version 1.4. + *

+ * Defaults to null if the runtime does not have + * security access to read this property. */ - public static final String JAVA_IO_TMPDIR = System.getProperty("java.io.tmpdir"); + public static final String JAVA_IO_TMPDIR = getSystemProperty("java.io.tmpdir"); /** * The java.library.path System Property. * List of paths to search when loading libraries. * First in JDK version 1.4. + *

+ * Defaults to null if the runtime does not have + * security access to read this property. */ - public static final String JAVA_LIBRARY_PATH = System.getProperty("java.library.path"); + public static final String JAVA_LIBRARY_PATH = getSystemProperty("java.library.path"); /** * The java.specification.name System Property. * Java Runtime Environment specification name. * First in JDK version 1.2. + *

+ * Defaults to null if the runtime does not have + * security access to read this property. */ - public static final String JAVA_SPECIFICATION_NAME = System.getProperty("java.specification.name"); + public static final String JAVA_SPECIFICATION_NAME = getSystemProperty("java.specification.name"); /** * The java.specification.vendor System Property. * Java Runtime Environment specification vendor. * First in JDK version 1.2. + *

+ * Defaults to null if the runtime does not have + * security access to read this property. */ - public static final String JAVA_SPECIFICATION_VENDOR = System.getProperty("java.specification.vendor"); + public static final String JAVA_SPECIFICATION_VENDOR = getSystemProperty("java.specification.vendor"); /** * The java.specification.version System Property. * Java Runtime Environment specification version. * First in JDK version 1.2. + *

+ * Defaults to null if the runtime does not have + * security access to read this property. */ - public static final String JAVA_SPECIFICATION_VERSION = System.getProperty("java.specification.version"); + public static final String JAVA_SPECIFICATION_VERSION = getSystemProperty("java.specification.version"); /** * The java.vendor System Property. * Java vendor-specific string. * First in JDK version 1.1. + *

+ * Defaults to null if the runtime does not have + * security access to read this property. */ - public static final String JAVA_VENDOR = System.getProperty("java.vendor"); + public static final String JAVA_VENDOR = getSystemProperty("java.vendor"); /** * The java.vendor.url System Property. * Java vendor URL. * First in JDK version 1.1. + *

+ * Defaults to null if the runtime does not have + * security access to read this property. */ - public static final String JAVA_VENDOR_URL = System.getProperty("java.vendor.url"); + public static final String JAVA_VENDOR_URL = getSystemProperty("java.vendor.url"); /** * The java.version System Property. * Java version number. * First in JDK version 1.1. + *

+ * Defaults to null if the runtime does not have + * security access to read this property. */ - public static final String JAVA_VERSION = System.getProperty("java.version"); + public static final String JAVA_VERSION = getSystemProperty("java.version"); /** * The java.vm.name System Property. * Java Virtual Machine implementation name. * First in JDK version 1.2. + *

+ * Defaults to null if the runtime does not have + * security access to read this property. */ - public static final String JAVA_VM_NAME = System.getProperty("java.vm.name"); + public static final String JAVA_VM_NAME = getSystemProperty("java.vm.name"); /** * The java.vm.specification.name System Property. * Java Virtual Machine specification name. * First in JDK version 1.2. + *

+ * Defaults to null if the runtime does not have + * security access to read this property. */ - public static final String JAVA_VM_SPECIFICATION_NAME = System.getProperty("java.vm.specification.name"); + public static final String JAVA_VM_SPECIFICATION_NAME = getSystemProperty("java.vm.specification.name"); /** * The java.vm.specification.vendor System Property. * Java Virtual Machine specification vendor. * First in JDK version 1.2. + *

+ * Defaults to null if the runtime does not have + * security access to read this property. */ - public static final String JAVA_VM_SPECIFICATION_VENDOR = System.getProperty("java.vm.specification.vendor"); + public static final String JAVA_VM_SPECIFICATION_VENDOR = getSystemProperty("java.vm.specification.vendor"); /** * The java.vm.specification.version System Property. * Java Virtual Machine specification version. * First in JDK version 1.2. + *

+ * Defaults to null if the runtime does not have + * security access to read this property. */ - public static final String JAVA_VM_SPECIFICATION_VERSION = System.getProperty("java.vm.specification.version"); + public static final String JAVA_VM_SPECIFICATION_VERSION = getSystemProperty("java.vm.specification.version"); /** * The java.vm.vendor System Property. * Java Virtual Machine implementation vendor. * First in JDK version 1.2. + *

+ * Defaults to null if the runtime does not have + * security access to read this property. */ - public static final String JAVA_VM_VENDOR = System.getProperty("java.vm.vendor"); + public static final String JAVA_VM_VENDOR = getSystemProperty("java.vm.vendor"); /** * The java.vm.version System Property. * Java Virtual Machine implementation version. * First in JDK version 1.2. + *

+ * Defaults to null if the runtime does not have + * security access to read this property. */ - public static final String JAVA_VM_VERSION = System.getProperty("java.vm.version"); + public static final String JAVA_VM_VERSION = getSystemProperty("java.vm.version"); /** * The line.separator System Property. * Line separator ("\n" on UNIX). * First in JDK version 1.1. + *

+ * Defaults to null if the runtime does not have + * security access to read this property. */ - public static final String LINE_SEPARATOR = System.getProperty("line.separator"); + public static final String LINE_SEPARATOR = getSystemProperty("line.separator"); /** * The os.arch System Property. * Operating system architecture. * First in JDK version 1.1. + *

+ * Defaults to null if the runtime does not have + * security access to read this property. */ - public static final String OS_ARCH = System.getProperty("os.arch"); + public static final String OS_ARCH = getSystemProperty("os.arch"); /** * The os.name System Property. * Operating system name. * First in JDK version 1.1. + *

+ * Defaults to null if the runtime does not have + * security access to read this property. */ - public static final String OS_NAME = System.getProperty("os.name"); + public static final String OS_NAME = getSystemProperty("os.name"); /** * The os.version System Property. * Operating system version. * First in JDK version 1.1. + *

+ * Defaults to null if the runtime does not have + * security access to read this property. */ - public static final String OS_VERSION = System.getProperty("os.version"); + public static final String OS_VERSION = getSystemProperty("os.version"); /** * The path.separator System Property. * Path separator (":" on UNIX). * First in JDK version 1.1. + *

+ * Defaults to null if the runtime does not have + * security access to read this property. */ - public static final String PATH_SEPARATOR = System.getProperty("path.separator"); + public static final String PATH_SEPARATOR = getSystemProperty("path.separator"); /** * The user.dir System Property. * User's current working directory. * First in JDK version 1.1. + *

+ * Defaults to null if the runtime does not have + * security access to read this property. */ - public static final String USER_DIR = System.getProperty("user.dir"); + public static final String USER_DIR = getSystemProperty("user.dir"); /** * The user.home System Property. * User's home directory. * First in JDK version 1.1. + *

+ * Defaults to null if the runtime does not have + * security access to read this property. */ - public static final String USER_HOME = System.getProperty("user.home"); + public static final String USER_HOME = getSystemProperty("user.home"); /** * The user.name System Property. * User's account name. * First in JDK version 1.1. + *

+ * Defaults to null if the runtime does not have + * security access to read this property. */ - public static final String USER_NAME = System.getProperty("user.name"); + public static final String USER_NAME = getSystemProperty("user.name"); + /** * Is true if this is Java version 1.1 (also 1.1.x versions). @@ -325,6 +414,23 @@ */ public static final boolean IS_JAVA_1_5 = JAVA_VERSION.startsWith("1.5."); + + /** + * Gets a System property, defaulting to the given value if the property + * cannot be read. + * + * @param property the system property name + * @return the system property value or null if security problem + */ + private static String getSystemProperty(String property) { + try { + return System.getProperty(property); + + } catch (SecurityException ex) { + // we are not allowed to look at this property + return null; + } + } // Parsing operating system may stay here, or it may be moved somewhere else entirely // /** True iff this is running on Windows */ --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org