ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Frederic Pesquet" <fpesq...@ilog.fr>
Subject [PATCH] a patch for 'org.apache.tools.ant.filters.LineContains' to work with large files
Date Fri, 24 May 2002 09:23:17 GMT
Hello,

The filter 'org.apache.tools.ant.filters.LineContains' does not work well
with big files.
There is a recursive call in read() to find a matching line, which causes a
stack overflow in the JVM when the file is too large.
I've patched the code of read() so that the loop to find a matching line
does not perform a recursive call.
It works for me.
Joined is the patch file of LineContains.java on the source of Ant1.5 beta1
(=the current CVS source as far as I can see through the CVS Web interface).
Can someone integrate this patch in the source tree?
Thanks,
Frederic

PS: this is the first time I submit a patch, please forgive me if this is
not the right procedure: I just tried to follow the guidelines.

--
Frederic Pesquet - ILOG S.A. (Sophia-Antipolis)
mail:fpesquet@ilog.fr

*************************** diff file begin ***********************
--- LineContains.java.orig	Fri May 24 11:13:42 2002
+++ LineContains.java	Fri May 24 11:13:35 2002
@@ -143,21 +143,25 @@
                 line = line.substring(1);
             }
         } else {
-            line = readLine();
-            if (line == null) {
-                ch = -1;
-            } else {
-                int containsSize = contains.size();
-                for (int i = 0; i < containsSize; i++) {
-                    String containsStr = (String) contains.elementAt(i);
-                    if (line.indexOf(containsStr) == -1) {
-                        line = null;
-                        break;
-                    }
+          String goodLine=null;
+          line = readLine();
+          while((line!=null) && (goodLine==null))
+          {
+            goodLine=line;
+            int containsSize = contains.size();
+            for (int i = 0; i < containsSize; i++) {
+                String containsStr = (String) contains.elementAt(i);
+                if (line.indexOf(containsStr) == -1) {
+                    goodLine = null;
+                    break;
                 }
-
-                return read();
             }
+            line = readLine();
+          }
+          if (goodLine != null) {
+                line=goodLine;
+                return read();
+            };
         }

         return ch;
*************************** diff file end ***********************


--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message