ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject [Bug 1480] New - Bad Environment kills ant
Date Tue, 24 Apr 2001 16:23:25 GMT
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=1480

*** shadow/1480	Tue Apr 24 09:23:25 2001
--- shadow/1480.tmp.16314	Tue Apr 24 09:23:25 2001
***************
*** 0 ****
--- 1,48 ----
+ +============================================================================+
+ | Bad Environment kills ant                                                  |
+ +----------------------------------------------------------------------------+
+ |        Bug #: 1480                        Product: Ant                     |
+ |       Status: NEW                         Version: 1.3                     |
+ |   Resolution:                            Platform: PC                      |
+ |     Severity: Normal                   OS/Version:                         |
+ |     Priority:                           Component: Core tasks              |
+ +----------------------------------------------------------------------------+
+ |  Assigned To: ant-dev@jakarta.apache.org                                   |
+ |  Reported By: neil+apache@askneil.com                                      |
+ |      CC list: Cc:                                                          |
+ +----------------------------------------------------------------------------+
+ |          URL:                                                              |
+ +============================================================================+
+ |                              DESCRIPTION                                   |
+ If you have a malformed environment variable ant will die if you
+ use the <properties environment="foo"/> property.
+ 
+ Here is some code from org.apache.tools.ant.taskdefs.Property,
+ routine loadEnvironment:
+ 
+         try {
+             Vector osEnv = Execute.getProcEnvironment();
+             for (Enumeration e = osEnv.elements(); e.hasMoreElements(); ) {
+                 String entry = (String)e.nextElement();
+                 int pos = entry.indexOf('=');
+                 props.put(prefix + entry.substring(0, pos), 
+                           entry.substring(pos + 1));
+             }
+             addProperties(props);
+         } catch (Exception ex) {
+             throw new BuildException(ex, location);
+         }
+ 
+ The problem is if there is no '=' sign in an environment
+ variable the entry.substring() call fails (pos will be -1).
+ 
+ My suggested fix:
+ 
+             for (Enumeration e = osEnv.elements(); e.hasMoreElements(); ) {
+                 String entry = (String)e.nextElement();
+                 int pos = entry.indexOf('=');
+                 if (pos > 0) {
+                         props.put(prefix + entry.substring(0, pos), 
+                                 entry.substring(pos + 1));
+                 }
+             }

Mime
View raw message