JDK-4199068 : Please return the functionality of getenv()
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 1.1.2,1.3.0,1.4.0,1.4.1
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS:
    generic,solaris_2.6,windows_nt,windows_2000,windows_xp generic,solaris_2.6,windows_nt,windows_2000,windows_xp
  • CPU: generic,x86
  • Submitted: 1998-12-22
  • Updated: 2017-05-16
  • Resolved: 2003-09-12
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
5.0 tigerFixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  

Name: dbT83986			Date: 12/21/98

Feature request:
    all that remains of the getenv() function is the method that returns an error message:
   /** Obsolete. 
     * Gets an environment variable. An environment variable is a
     * system dependent external variable that has a string value.
     * @param name the name of the environment variable
     * @return 	the value of the variable, or null if the variable is
     *		not defined.
    public static String getenv(String name) {
	throw new Error("getenv no longer supported, use properties and -D instead: " + name);

The need for this particular call is very important while I continue to work with
an existing cross platform application that creates environment variables during
the runtime. There is no 'easy' way to get these values. Most of the deprecation
documentation is misleading (it states that getenv() is replaced with getProperty()).

Please return the funtionality where ever it is...
(Review ID: 38108)

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger FIXED IN: tiger INTEGRATED IN: tiger tiger-b20

WORK AROUND Name: dbT83986 Date: 12/21/98 Write code to get the current OS, Guess the Current OS command to display the environment into a dataStream, then parse out all the values. example (work in progress): /** $Workfile: OSEnvironment.java $ $Revision: 1.0 $ $Modtime: Sep 01 1998 13:31:46 $ $Log: U:/archives/VCS/VMT/COMM/src/OSEnvironment.java.v $ // // Rev 1.0 Sep 01 1998 13:31:22 opr5581 // Initial version of new class to replace System.getenv() call. // This revision works specifically for the AIX environment with the "printenv" commnad located at /usr/bin. // Since getenv has been removed... we need to get our own values from the OS for all existing Environment Variables. */ import java.lang.*; import java.io.*; import java.util.*; public class OSEnvironment { static String[][] envData; static int envDataSize = 0; String wholeEnv = ""; OSEnvironment(){ /** TODO: The following command is set for the AIX environment. In order to make this portable, an OS check and alternate command will need to be added. */ // need to know what type off system we are on an know the 'set' path/command String command = "/usr/bin/printenv"; //Get our environment into a single string: try { Process p = Runtime.getRuntime().exec(command); DataInputStream commandResult = new DataInputStream(new BufferedInputStream(p.getInputStream())); String line = null; try { while ((line = commandResult.readLine()) != null) wholeEnv = wholeEnv +"," + line; if (p.exitValue() != 0) { wholeEnv="Error=Cannot complete OSEnvironment.class: " + command + ":" + p.exitValue(); } } catch (Exception e) { } } catch (Exception e) { wholeEnv = "Error Cannot Use OSEnvironment.class: " + command + ":" + e; } envData=parseEnv(); } String[][] parseEnv(){ StringTokenizer envTokenizer = new StringTokenizer(wholeEnv,",",false); envDataSize=envTokenizer.countTokens(); String singlePair; String[][] parsedEnv = new String [envDataSize][2]; for (int i=0;i<envDataSize;i++) { if (envTokenizer.hasMoreTokens()) { singlePair=envTokenizer.nextToken(); parsedEnv[i][0]=singlePair.substring(0,singlePair.indexOf("=")); parsedEnv[i][1]=singlePair.substring(singlePair.indexOf("=")+1); } } return parsedEnv; } String getEnvValue(String envName,String defaultValue){ String valueFound = defaultValue; for (int i=0;i<envDataSize;i++){ if (envData[i][0].equals(envName)) { valueFound=envData[i][1]; } } return valueFound; } } ======================================================================

EVALUATION Many operating systems support the notion of a process environment that maps identifiers to string values, but no two systems define the contents of this environment in the same way. Even amongst Unixes there are significant differences; some define USER as the user's login name, while some define LOGNAME to have this value, and some (e.g., Linux) define both. So while we could easily reinstate the getenv() method to provide access to the process environment, any code that invokes this method would inherently be dependent upon the operating system(s) upon which it is written and tested. One of the primary goals of the Java platform is to provide a set of APIs that work in essentially the same way across a wide variety of operating systems, so that developers can write portable programs. Providing access to information that is inherently OS-specific is not consistent with this goal. -- mr@eng 2001/7/25 Due to overwhelming demand we are going to reconsider this position for the 1.5 release. -- ###@###.### 2002/4/30