bodewig 2003/04/04 05:51:12
Modified: src/main/org/apache/tools/ant RuntimeConfigurable.java
src/main/org/apache/tools/ant/listener MailLogger.java
src/main/org/apache/tools/ant/taskdefs AntStructure.java
Concat.java FixCRLF.java Javadoc.java Replace.java
SQLExec.java
src/main/org/apache/tools/ant/taskdefs/email Message.java
src/main/org/apache/tools/ant/taskdefs/optional
ReplaceRegExp.java
src/main/org/apache/tools/ant/taskdefs/optional/junit
JUnitTask.java
src/main/org/apache/tools/ant/taskdefs/optional/perforce
P4Add.java P4Fstat.java
src/main/org/apache/tools/ant/taskdefs/optional/sitraka/bytecode
Utils.java
src/main/org/apache/tools/ant/types Commandline.java
Path.java
src/main/org/apache/tools/ant/util DOMElementWriter.java
RegexpPatternMapper.java ResourceUtils.java
Log:
Avoid reusing StringBuffers to work around JDK 1.4.1 memory leak.
I'm sure that my changes in most cases are of the paranoid type,
ResourceUtils and FixCRLF look as if they really had a chance of
running into trouble.
Revision Changes Path
1.29 +1 -1
ant/src/main/org/apache/tools/ant/RuntimeConfigurable.java
Index: RuntimeConfigurable.java
===================================================================
RCS file:
/home/cvs/ant/src/main/org/apache/tools/ant/RuntimeConfigurable.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- RuntimeConfigurable.java 2 Apr 2003 11:43:41 -0000 1.28
+++ RuntimeConfigurable.java 4 Apr 2003 13:51:11 -0000 1.29
@@ -324,7 +324,7 @@
id = (String) attributeMap.get("id");
if (characters.length() != 0) {
- ProjectHelper.addText(p, wrappedObject, characters.toString());
+ ProjectHelper.addText(p, wrappedObject, characters.substring(0));
}
Enumeration enum = children.elements();
1.15 +2 -2
ant/src/main/org/apache/tools/ant/listener/MailLogger.java
Index: MailLogger.java
===================================================================
RCS file:
/home/cvs/ant/src/main/org/apache/tools/ant/listener/MailLogger.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- MailLogger.java 10 Feb 2003 14:13:34 -0000 1.14
+++ MailLogger.java 4 Apr 2003 13:51:11 -0000 1.15
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2002-2002 The Apache Software Foundation. All rights
+ * Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -158,7 +158,7 @@
String subject = getValue(properties, prefix + ".subject",
(success) ? "Build Success" : "Build Failure");
- sendMail(mailhost, port, from, toList, subject,
buffer.toString());
+ sendMail(mailhost, port, from, toList, subject,
buffer.substring(0));
} catch (Exception e) {
System.out.println("MailLogger failed to send e-mail!");
e.printStackTrace(System.err);
1.32 +4 -4
ant/src/main/org/apache/tools/ant/taskdefs/AntStructure.java
Index: AntStructure.java
===================================================================
RCS file:
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/AntStructure.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- AntStructure.java 7 Mar 2003 11:23:00 -0000 1.31
+++ AntStructure.java 4 Apr 2003 13:51:11 -0000 1.32
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
+ * Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -294,8 +294,8 @@
sb.append(">");
out.println(sb);
- sb.setLength(0);
- sb.append("<!ATTLIST ").append(name);
+ sb = new StringBuffer("<!ATTLIST ");
+ sb.append(name);
sb.append(lSep).append(" id ID #IMPLIED");
enum = ih.getAttributes();
1.18 +2 -2 ant/src/main/org/apache/tools/ant/taskdefs/Concat.java
Index: Concat.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Concat.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- Concat.java 28 Mar 2003 12:41:01 -0000 1.17
+++ Concat.java 4 Apr 2003 13:51:11 -0000 1.18
@@ -412,7 +412,7 @@
if (textBuffer != null) {
reader = new StringReader(
- getProject().replaceProperties(textBuffer.toString()));
+ getProject().replaceProperties(textBuffer.substring(0)));
} else {
reader = new MultiReader();
}
@@ -476,7 +476,7 @@
*/
private void sanitizeText() {
if (textBuffer != null) {
- if (textBuffer.toString().trim().length() == 0) {
+ if (textBuffer.substring(0).trim().length() == 0) {
textBuffer = null;
}
}
1.45 +10 -10 ant/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java
Index: FixCRLF.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -r1.44 -r1.45
--- FixCRLF.java 10 Feb 2003 14:13:34 -0000 1.44
+++ FixCRLF.java 4 Apr 2003 13:51:11 -0000 1.45
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
+ * Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -720,7 +720,7 @@
// process sequences of white space
// first convert all tabs to spaces
- linebuf.setLength(0);
+ linebuf = new StringBuffer();
while ((nextTab = line.indexOf((int) '\t', place)) >= 0) {
linebuf.append(line.substring(place, nextTab)); // copy to the
TAB
col += nextTab - place;
@@ -731,7 +731,7 @@
} // end of while
linebuf.append(line.substring(place, line.length()));
// if converting to spaces, all finished
- String linestring = new String(linebuf.toString());
+ String linestring = new String(linebuf.substring(0));
if (tabs == REMOVE) {
try {
outWriter.write(linestring);
@@ -740,7 +740,7 @@
} // end of try-catch
} else { // tabs == ADD
int tabCol;
- linebuf2.setLength(0);
+ linebuf2 = new StringBuffer();
place = 0;
col = bufline.getColumn();
int placediff = col - 0;
@@ -782,7 +782,7 @@
linebuf2.append(linestring.substring(place,
linestring.length()));
try {
- outWriter.write(linebuf2.toString());
+ outWriter.write(linebuf2.substring(0));
} catch (IOException e) {
throw new BuildException(e);
} // end of try-catch
@@ -826,8 +826,8 @@
int ch = -1;
int eolcount = 0;
- eolStr.setLength(0);
- line.setLength(0);
+ eolStr = new StringBuffer();
+ line = new StringBuffer();
try {
ch = reader.read();
@@ -907,7 +907,7 @@
}
public String getEofStr() {
- return eofStr.toString();
+ return eofStr.substring(0);
}
public int getState() {
@@ -928,7 +928,7 @@
throw new NoSuchElementException("OneLiner");
}
BufferLine tmpLine =
- new BufferLine(line.toString(), eolStr.toString());
+ new BufferLine(line.toString(), eolStr.substring(0));
nextLine();
return tmpLine;
}
1.111 +1 -1 ant/src/main/org/apache/tools/ant/taskdefs/Javadoc.java
Index: Javadoc.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Javadoc.java,v
retrieving revision 1.110
retrieving revision 1.111
diff -u -r1.110 -r1.111
--- Javadoc.java 7 Mar 2003 11:23:02 -0000 1.110
+++ Javadoc.java 4 Apr 2003 13:51:11 -0000 1.111
@@ -362,7 +362,7 @@
* @return the current text.
*/
public String getText() {
- return text.toString();
+ return text.substring(0);
}
}
1.38 +2 -2 ant/src/main/org/apache/tools/ant/taskdefs/Replace.java
Index: Replace.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Replace.java,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- Replace.java 10 Feb 2003 14:13:36 -0000 1.37
+++ Replace.java 4 Apr 2003 13:51:11 -0000 1.38
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
+ * Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -124,7 +124,7 @@
}
public String getText() {
- return buf.toString();
+ return buf.substring(0);
}
}
1.52 +2 -2 ant/src/main/org/apache/tools/ant/taskdefs/SQLExec.java
Index: SQLExec.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/SQLExec.java,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -r1.51 -r1.52
--- SQLExec.java 14 Mar 2003 09:24:41 -0000 1.51
+++ SQLExec.java 4 Apr 2003 13:51:11 -0000 1.52
@@ -555,7 +555,7 @@
}
line.append(md.getColumnName(columnCount));
out.println(line);
- line.setLength(0);
+ line = new StringBuffer();
}
while (rs.next()) {
boolean first = true;
@@ -573,7 +573,7 @@
line.append(columnValue);
}
out.println(line);
- line.setLength(0);
+ line = new StringBuffer();
}
}
}
1.7 +2 -2
ant/src/main/org/apache/tools/ant/taskdefs/email/Message.java
Index: Message.java
===================================================================
RCS file:
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/email/Message.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Message.java 10 Feb 2003 14:13:45 -0000 1.6
+++ Message.java 4 Apr 2003 13:51:11 -0000 1.7
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2002 The Apache Software Foundation. All rights
+ * Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -162,7 +162,7 @@
freader.close();
}
} else {
- out.println(getProject().replaceProperties(buffer.toString()));
+ out.println(getProject().replaceProperties(buffer.substring(0)));
}
}
1.18 +3 -3
ant/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java
Index: ReplaceRegExp.java
===================================================================
RCS file:
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- ReplaceRegExp.java 10 Feb 2003 14:13:45 -0000 1.17
+++ ReplaceRegExp.java 4 Apr 2003 13:51:11 -0000 1.18
@@ -365,7 +365,7 @@
pw.print(res);
pw.print('\r');
- linebuf.setLength(0);
+ linebuf = new StringBuffer();
// hasCR is still true (for the second one)
} else {
// first CR in this line
@@ -388,7 +388,7 @@
}
pw.print('\n');
- linebuf.setLength(0);
+ linebuf = new StringBuffer();
} else { // any other char
if ((hasCR) || (c < 0)) {
// Mac-style linebreak or EOF (or both)
@@ -405,7 +405,7 @@
hasCR = false;
}
- linebuf.setLength(0);
+ linebuf = new StringBuffer();
}
if (c >= 0) {
1.61 +2 -2
ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
Index: JUnitTask.java
===================================================================
RCS file:
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -r1.60 -r1.61
--- JUnitTask.java 31 Mar 2003 13:46:18 -0000 1.60
+++ JUnitTask.java 4 Apr 2003 13:51:12 -0000 1.61
@@ -640,7 +640,7 @@
formatterArg.append(outFile);
}
cmd.createArgument().setValue(formatterArg.toString());
- formatterArg.setLength(0);
+ formatterArg = new StringBuffer();
}
// Create a temporary file to pass the Ant properties to the
1.14 +1 -1
ant/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Add.java
Index: P4Add.java
===================================================================
RCS file:
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Add.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- P4Add.java 10 Feb 2003 14:14:18 -0000 1.13
+++ P4Add.java 4 Apr 2003 13:51:12 -0000 1.14
@@ -145,7 +145,7 @@
filelist.append("
").append('"').append(f.getAbsolutePath()).append('"');
if (filelist.length() > cmdLength) {
execP4Add(filelist);
- filelist.setLength(0);
+ filelist = new StringBuffer();
}
}
if (filelist.length() > 0) {
1.5 +1 -1
ant/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Fstat.java
Index: P4Fstat.java
===================================================================
RCS file:
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Fstat.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- P4Fstat.java 4 Apr 2003 13:02:40 -0000 1.4
+++ P4Fstat.java 4 Apr 2003 13:51:12 -0000 1.5
@@ -165,7 +165,7 @@
if (filelist.length() > cmdLength) {
execP4Fstat(filelist);
- filelist.setLength(0);
+ filelist = new StringBuffer();
}
}
if (filelist.length() > 0) {
1.9 +3 -3
ant/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/bytecode/Utils.java
Index: Utils.java
===================================================================
RCS file:
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/bytecode/Utils.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Utils.java 10 Feb 2003 14:14:23 -0000 1.8
+++ Utils.java 4 Apr 2003 13:51:12 -0000 1.9
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001-2002 The Apache Software Foundation. All rights
+ * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -122,8 +122,8 @@
StringBuffer param = new StringBuffer();
i++;
while ((i = descriptor2java(descriptor, i, param)) <
descriptor.length()) {
- params.add(param.toString());
- param.setLength(0); // reset
+ params.add(param.substring(0));
+ param = new StringBuffer();
if (descriptor.charAt(i) == ')') {
i++;
break;
1.28 +2 -2 ant/src/main/org/apache/tools/ant/types/Commandline.java
Index: Commandline.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/types/Commandline.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- Commandline.java 7 Mar 2003 11:23:07 -0000 1.27
+++ Commandline.java 4 Apr 2003 13:51:12 -0000 1.28
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
+ * Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -399,7 +399,7 @@
} else if (" ".equals(nextTok)) {
if (lastTokenHasBeenQuoted || current.length() != 0) {
v.addElement(current.toString());
- current.setLength(0);
+ current = new StringBuffer();
}
} else {
current.append(nextTok);
1.48 +1 -1 ant/src/main/org/apache/tools/ant/types/Path.java
Index: Path.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/types/Path.java,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -r1.47 -r1.48
--- Path.java 11 Mar 2003 10:57:42 -0000 1.47
+++ Path.java 4 Apr 2003 13:51:12 -0000 1.48
@@ -397,7 +397,6 @@
PathTokenizer tok = new PathTokenizer(source);
StringBuffer element = new StringBuffer();
while (tok.hasMoreTokens()) {
- element.setLength(0);
String pathElement = tok.nextToken();
try {
element.append(resolveFile(project, pathElement));
@@ -410,6 +409,7 @@
translateFileSep(element, i);
}
result.addElement(element.toString());
+ element = new StringBuffer();
}
String[] res = new String[result.size()];
result.copyInto(res);
1.18 +2 -3
ant/src/main/org/apache/tools/ant/util/DOMElementWriter.java
Index: DOMElementWriter.java
===================================================================
RCS file:
/home/cvs/ant/src/main/org/apache/tools/ant/util/DOMElementWriter.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- DOMElementWriter.java 4 Apr 2003 08:36:22 -0000 1.17
+++ DOMElementWriter.java 4 Apr 2003 13:51:12 -0000 1.18
@@ -80,7 +80,6 @@
public class DOMElementWriter {
private static String lSep = System.getProperty("line.separator");
- private StringBuffer sb = new StringBuffer();
/**
* Don't try to be too smart but at least recognize the predefined
@@ -204,7 +203,7 @@
* drop characters that are illegal in XML documents.
*/
public String encode(String value) {
- sb.setLength(0);
+ StringBuffer sb = new StringBuffer();
int len = value.length();
for (int i = 0; i < len; i++) {
char c = value.charAt(i);
@@ -254,7 +253,7 @@
*/
public String encodedata(final String value) {
- sb.setLength(0);
+ StringBuffer sb = new StringBuffer();
for (int i = 0; i < value.length(); ++i) {
char c = value.charAt(i);
if (isLegalCharacter(c)) {
1.9 +2 -2
ant/src/main/org/apache/tools/ant/util/RegexpPatternMapper.java
Index: RegexpPatternMapper.java
===================================================================
RCS file:
/home/cvs/ant/src/main/org/apache/tools/ant/util/RegexpPatternMapper.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- RegexpPatternMapper.java 7 Mar 2003 11:23:08 -0000 1.8
+++ RegexpPatternMapper.java 4 Apr 2003 13:51:12 -0000 1.9
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2000,2002 The Apache Software Foundation. All rights
+ * Copyright (c) 2000,2002-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -133,7 +133,7 @@
result.append(to[i]);
}
}
- return result.toString();
+ return result.substring(0);
}
}
1.2 +1 -2 ant/src/main/org/apache/tools/ant/util/ResourceUtils.java
Index: ResourceUtils.java
===================================================================
RCS file:
/home/cvs/ant/src/main/org/apache/tools/ant/util/ResourceUtils.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ResourceUtils.java 19 Feb 2003 07:57:29 -0000 1.1
+++ ResourceUtils.java 4 Apr 2003 13:51:12 -0000 1.2
@@ -89,7 +89,6 @@
FileNameMapper mapper,
ResourceFactory targets)
{
long now = (new java.util.Date()).getTime();
- StringBuffer targetList = new StringBuffer();
/*
If we're on Windows, we have to munge the time up to 2 secs to
@@ -116,7 +115,7 @@
.replace('/', File.separatorChar));
if (targetnames != null) {
boolean added = false;
- targetList.setLength(0);
+ StringBuffer targetList = new StringBuffer();
for (int ctarget = 0; !added && ctarget <
targetnames.length;
ctarget++) {
Resource atarget =