Browse Source

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.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274397 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 22 years ago
parent
commit
1aca5cf036
19 changed files with 41 additions and 43 deletions
  1. +1
    -1
      src/main/org/apache/tools/ant/RuntimeConfigurable.java
  2. +2
    -2
      src/main/org/apache/tools/ant/listener/MailLogger.java
  3. +3
    -3
      src/main/org/apache/tools/ant/taskdefs/AntStructure.java
  4. +2
    -2
      src/main/org/apache/tools/ant/taskdefs/Concat.java
  5. +9
    -9
      src/main/org/apache/tools/ant/taskdefs/FixCRLF.java
  6. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/Javadoc.java
  7. +2
    -2
      src/main/org/apache/tools/ant/taskdefs/Replace.java
  8. +2
    -2
      src/main/org/apache/tools/ant/taskdefs/SQLExec.java
  9. +2
    -2
      src/main/org/apache/tools/ant/taskdefs/email/Message.java
  10. +3
    -3
      src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java
  11. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
  12. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Add.java
  13. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Fstat.java
  14. +3
    -3
      src/main/org/apache/tools/ant/taskdefs/optional/sitraka/bytecode/Utils.java
  15. +2
    -2
      src/main/org/apache/tools/ant/types/Commandline.java
  16. +1
    -1
      src/main/org/apache/tools/ant/types/Path.java
  17. +2
    -3
      src/main/org/apache/tools/ant/util/DOMElementWriter.java
  18. +2
    -2
      src/main/org/apache/tools/ant/util/RegexpPatternMapper.java
  19. +1
    -2
      src/main/org/apache/tools/ant/util/ResourceUtils.java

+ 1
- 1
src/main/org/apache/tools/ant/RuntimeConfigurable.java View File

@@ -324,7 +324,7 @@ public class RuntimeConfigurable implements Serializable {
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();


+ 2
- 2
src/main/org/apache/tools/ant/listener/MailLogger.java View File

@@ -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 @@ public class MailLogger extends DefaultLogger {
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);


+ 3
- 3
src/main/org/apache/tools/ant/taskdefs/AntStructure.java View File

@@ -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 @@ public class AntStructure extends Task {
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();


+ 2
- 2
src/main/org/apache/tools/ant/taskdefs/Concat.java View File

@@ -412,7 +412,7 @@ public class Concat extends Task {

if (textBuffer != null) {
reader = new StringReader(
getProject().replaceProperties(textBuffer.toString()));
getProject().replaceProperties(textBuffer.substring(0)));
} else {
reader = new MultiReader();
}
@@ -476,7 +476,7 @@ public class Concat extends Task {
*/
private void sanitizeText() {
if (textBuffer != null) {
if (textBuffer.toString().trim().length() == 0) {
if (textBuffer.substring(0).trim().length() == 0) {
textBuffer = null;
}
}


+ 9
- 9
src/main/org/apache/tools/ant/taskdefs/FixCRLF.java View File

@@ -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 @@ public class FixCRLF extends MatchingTask {

// 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 @@ public class FixCRLF extends MatchingTask {
} // 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 @@ public class FixCRLF extends MatchingTask {
} // 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 @@ public class FixCRLF extends MatchingTask {
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 @@ public class FixCRLF extends MatchingTask {
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 class FixCRLF extends MatchingTask {
}

public String getEofStr() {
return eofStr.toString();
return eofStr.substring(0);
}

public int getState() {
@@ -928,7 +928,7 @@ public class FixCRLF extends MatchingTask {
throw new NoSuchElementException("OneLiner");
}
BufferLine tmpLine =
new BufferLine(line.toString(), eolStr.toString());
new BufferLine(line.toString(), eolStr.substring(0));
nextLine();
return tmpLine;
}


+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/Javadoc.java View File

@@ -362,7 +362,7 @@ public class Javadoc extends Task {
* @return the current text.
*/
public String getText() {
return text.toString();
return text.substring(0);
}
}



+ 2
- 2
src/main/org/apache/tools/ant/taskdefs/Replace.java View File

@@ -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 class Replace extends MatchingTask {
}

public String getText() {
return buf.toString();
return buf.substring(0);
}
}



+ 2
- 2
src/main/org/apache/tools/ant/taskdefs/SQLExec.java View File

@@ -555,7 +555,7 @@ public class SQLExec extends JDBCTask {
}
line.append(md.getColumnName(columnCount));
out.println(line);
line.setLength(0);
line = new StringBuffer();
}
while (rs.next()) {
boolean first = true;
@@ -573,7 +573,7 @@ public class SQLExec extends JDBCTask {
line.append(columnValue);
}
out.println(line);
line.setLength(0);
line = new StringBuffer();
}
}
}


+ 2
- 2
src/main/org/apache/tools/ant/taskdefs/email/Message.java View File

@@ -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 @@ public class Message extends ProjectComponent {
freader.close();
}
} else {
out.println(getProject().replaceProperties(buffer.toString()));
out.println(getProject().replaceProperties(buffer.substring(0)));
}
}



+ 3
- 3
src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java View File

@@ -365,7 +365,7 @@ public class ReplaceRegExp extends Task {
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 @@ public class ReplaceRegExp extends Task {
}
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 @@ public class ReplaceRegExp extends Task {
hasCR = false;
}

linebuf.setLength(0);
linebuf = new StringBuffer();
}

if (c >= 0) {


+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java View File

@@ -640,7 +640,7 @@ public class JUnitTask extends Task {
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
- 1
src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Add.java View File

@@ -145,7 +145,7 @@ public class P4Add extends P4Base {
filelist.append(" ").append('"').append(f.getAbsolutePath()).append('"');
if (filelist.length() > cmdLength) {
execP4Add(filelist);
filelist.setLength(0);
filelist = new StringBuffer();
}
}
if (filelist.length() > 0) {


+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Fstat.java View File

@@ -165,7 +165,7 @@ public class P4Fstat extends P4Base {
if (filelist.length() > cmdLength) {

execP4Fstat(filelist);
filelist.setLength(0);
filelist = new StringBuffer();
}
}
if (filelist.length() > 0) {


+ 3
- 3
src/main/org/apache/tools/ant/taskdefs/optional/sitraka/bytecode/Utils.java View File

@@ -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 @@ public class Utils {
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;


+ 2
- 2
src/main/org/apache/tools/ant/types/Commandline.java View File

@@ -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 @@ public class Commandline implements Cloneable {
} else if (" ".equals(nextTok)) {
if (lastTokenHasBeenQuoted || current.length() != 0) {
v.addElement(current.toString());
current.setLength(0);
current = new StringBuffer();
}
} else {
current.append(nextTok);


+ 1
- 1
src/main/org/apache/tools/ant/types/Path.java View File

@@ -397,7 +397,6 @@ public class Path extends DataType implements Cloneable {
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 @@ public class Path extends DataType implements Cloneable {
translateFileSep(element, i);
}
result.addElement(element.toString());
element = new StringBuffer();
}
String[] res = new String[result.size()];
result.copyInto(res);


+ 2
- 3
src/main/org/apache/tools/ant/util/DOMElementWriter.java View File

@@ -80,7 +80,6 @@ import org.w3c.dom.Text;
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 @@ public class DOMElementWriter {
* 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 class DOMElementWriter {

*/
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)) {


+ 2
- 2
src/main/org/apache/tools/ant/util/RegexpPatternMapper.java View File

@@ -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 @@ public class RegexpPatternMapper implements FileNameMapper {
result.append(to[i]);
}
}
return result.toString();
return result.substring(0);
}

}

+ 1
- 2
src/main/org/apache/tools/ant/util/ResourceUtils.java View File

@@ -89,7 +89,6 @@ public class ResourceUtils {
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 @@ public class ResourceUtils {
.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 =


Loading…
Cancel
Save