Browse Source

#30162: try to avoid a memory leak in IntrospectionHelper.getHelper().

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@278078 13f79535-47bb-0310-9956-ffa450edef68
master
Jesse N. Glick 20 years ago
parent
commit
6ecb04cbad
5 changed files with 20 additions and 17 deletions
  1. +14
    -9
      src/main/org/apache/tools/ant/IntrospectionHelper.java
  2. +3
    -5
      src/main/org/apache/tools/ant/ProjectHelper.java
  3. +1
    -1
      src/main/org/apache/tools/ant/UnknownElement.java
  4. +1
    -1
      src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java
  5. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/AntStructure.java

+ 14
- 9
src/main/org/apache/tools/ant/IntrospectionHelper.java View File

@@ -310,12 +310,7 @@ public final class IntrospectionHelper implements BuildListener {
* @return a helper for the specified class
*/
public static synchronized IntrospectionHelper getHelper(Class c) {
IntrospectionHelper ih = (IntrospectionHelper) helpers.get(c);
if (ih == null) {
ih = new IntrospectionHelper(c);
helpers.put(c, ih);
}
return ih;
return getHelper(null, c);
}

/**
@@ -332,9 +327,19 @@ public final class IntrospectionHelper implements BuildListener {
* @return a helper for the specified class
*/
public static IntrospectionHelper getHelper(Project p, Class c) {
IntrospectionHelper ih = getHelper(c);
// Cleanup at end of project
p.addBuildListener(ih);
IntrospectionHelper ih = (IntrospectionHelper) helpers.get(c);
if (ih == null) {
ih = new IntrospectionHelper(c);
if (p != null) {
// #30162: do *not* cache this if there is no project, as we
// cannot guarantee that the cache will be cleared.
helpers.put(c, ih);
}
}
if (p != null) {
// Cleanup at end of project
p.addBuildListener(ih);
}
return ih;
}



+ 3
- 5
src/main/org/apache/tools/ant/ProjectHelper.java View File

@@ -304,9 +304,7 @@ public class ProjectHelper {
}

IntrospectionHelper ih =
IntrospectionHelper.getHelper(target.getClass());

project.addBuildListener(ih);
IntrospectionHelper.getHelper(project, target.getClass());

for (int i = 0; i < attrs.getLength(); i++) {
// reflect these into the target
@@ -368,7 +366,7 @@ public class ProjectHelper {
target = ((TypeAdapter) target).getProxy();
}

IntrospectionHelper.getHelper(target.getClass()).addText(project,
IntrospectionHelper.getHelper(project, target.getClass()).addText(project,
target, text);
}

@@ -388,7 +386,7 @@ public class ProjectHelper {
public static void storeChild(Project project, Object parent,
Object child, String tag) {
IntrospectionHelper ih
= IntrospectionHelper.getHelper(parent.getClass());
= IntrospectionHelper.getHelper(project, parent.getClass());
ih.storeElement(project, parent, child, tag);
}



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

@@ -320,7 +320,7 @@ public class UnknownElement extends Task {

String parentUri = getNamespace();
Class parentClass = parent.getClass();
IntrospectionHelper ih = IntrospectionHelper.getHelper(parentClass);
IntrospectionHelper ih = IntrospectionHelper.getHelper(getProject(), parentClass);


if (children != null) {


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

@@ -863,7 +863,7 @@ public class ProjectHelperImpl extends ProjectHelper {
public void init(String propType, AttributeList attrs) throws SAXParseException {
Class parentClass = parent.getClass();
IntrospectionHelper ih =
IntrospectionHelper.getHelper(parentClass);
IntrospectionHelper.getHelper(helperImpl.project, parentClass);

try {
String elementName = propType.toLowerCase(Locale.US);


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

@@ -200,7 +200,7 @@ public class AntStructure extends Task {

IntrospectionHelper ih = null;
try {
ih = IntrospectionHelper.getHelper(element);
ih = IntrospectionHelper.getHelper(getProject(), element);
} catch (Throwable t) {
/*
* XXX - failed to load the class properly.


Loading…
Cancel
Save