ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgl...@apache.org
Subject svn commit: r881624 - in /ant/core/trunk/src/main/org/apache/tools/ant/taskdefs: SubAnt.java optional/PropertyFile.java
Date Tue, 17 Nov 2009 23:39:22 GMT
Author: jglick
Date: Tue Nov 17 23:39:22 2009
New Revision: 881624

URL: http://svn.apache.org/viewvc?rev=881624&view=rev
Log:
Trying to improve robustness in <subant> and <propertyfile>.
Observed a long-running build randomly failing with text like this:
[propertyfile] Updating property file: .../whatever.properties
      [subant] Failure for target 'something' of: ...module1/build.xml
      [subant] The following error occurred while executing this line:
      [subant] .../something.xml:123: java.lang.OutOfMemoryError: GC overhead limit exceeded
      [subant] Failure for target 'something' of: ...module2/build.xml
      [subant] The following error occurred while executing this line:
      [subant] ...module2/build.xml:12: The following error occurred while executing this
line:
      [subant] .../something.xml:123: Syntax error in property: ${some.prope
      [subant] Failure for target 'something' of: ...module3/build.xml [etc., hundreds of
times]
Turns out that whatever.properties had been truncated at exactly 24k characters, in the middle
of a line.
Fixing <propertyfile> to therefore collect all of what it plans to write, then write
it.
Also trying to make <subant> actually stop the build when it gets OOME, rather than
continuing
(probably in vain) just because failonerror="false" (which is intended to catch "normal" problems).
ThreadDeath should also be rethrown, not logged as a subscript failure.

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SubAnt.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SubAnt.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SubAnt.java?rev=881624&r1=881623&r2=881624&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SubAnt.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SubAnt.java Tue Nov 17 23:39:22
2009
@@ -307,6 +307,10 @@
             log("Failure for target '" + subTarget
                + "' of: " +  antfilename + "\n"
                + e.getMessage(), Project.MSG_WARN);
+        } catch (OutOfMemoryError e) {
+            throw e;
+        } catch (ThreadDeath e) {
+            throw e;
         } catch (Throwable e) {
             if (failOnError) {
                 throw new BuildException(e);

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java?rev=881624&r1=881623&r2=881624&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java Tue Nov
17 23:39:22 2009
@@ -19,11 +19,12 @@
 package org.apache.tools.ant.taskdefs.optional;
 
 import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.OutputStream;
 import java.text.DateFormat;
 import java.text.DecimalFormat;
 import java.text.ParseException;
@@ -37,7 +38,6 @@
 import java.util.Vector;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Task;
-import org.apache.tools.ant.util.FileUtils;
 import org.apache.tools.ant.util.LayoutPreservingProperties;
 import org.apache.tools.ant.types.EnumeratedAttribute;
 
@@ -233,14 +233,25 @@
     }
 
     private void writeFile() throws BuildException {
-        BufferedOutputStream bos = null;
+        // Write to RAM first, as an OOME could otherwise produce a truncated file:
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
         try {
-            bos = new BufferedOutputStream(new FileOutputStream(propertyfile));
-            properties.store(bos, comment);
-        } catch (IOException ioe) {
-            throw new BuildException(ioe, getLocation());
-        } finally {
-            FileUtils.close(bos);
+            properties.store(baos, comment);
+        } catch (IOException x) { // should not happen
+            throw new BuildException(x, getLocation());
+        }
+        try {
+            OutputStream os = new FileOutputStream(propertyfile);
+            try {
+                os.write(baos.toByteArray());
+            } catch (IOException x) {
+                propertyfile.delete(); // possibly corrupt
+                throw new BuildException(x, getLocation());
+            } finally {
+                os.close();
+            }
+        } catch (IOException x) {
+            throw new BuildException(x, getLocation());
         }
     }
 



Mime
View raw message