jglick      2005/03/29 13:47:59

  Modified:    src/main/org/apache/tools/ant IntrospectionHelper.java
                        ProjectHelper.java UnknownElement.java
               src/main/org/apache/tools/ant/helper ProjectHelperImpl.java
               src/main/org/apache/tools/ant/taskdefs AntStructure.java
  Log:
  #30162: try to avoid a memory leak in IntrospectionHelper.getHelper().
  
  Revision  Changes    Path
  1.94      +14 -9     
ant/src/main/org/apache/tools/ant/IntrospectionHelper.java
  
  Index: IntrospectionHelper.java
  ===================================================================
  RCS file: 
/home/cvs/ant/src/main/org/apache/tools/ant/IntrospectionHelper.java,v
  retrieving revision 1.93
  retrieving revision 1.94
  diff -u -r1.93 -r1.94
  --- IntrospectionHelper.java  16 Dec 2004 21:11:19 -0000      1.93
  +++ IntrospectionHelper.java  29 Mar 2005 21:47:59 -0000      1.94
  @@ -310,12 +310,7 @@
        * @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 @@
        * @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;
       }
   
  
  
  
  1.115     +3 -5      ant/src/main/org/apache/tools/ant/ProjectHelper.java
  
  Index: ProjectHelper.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/ProjectHelper.java,v
  retrieving revision 1.114
  retrieving revision 1.115
  diff -u -r1.114 -r1.115
  --- ProjectHelper.java        13 Dec 2004 16:43:51 -0000      1.114
  +++ ProjectHelper.java        29 Mar 2005 21:47:59 -0000      1.115
  @@ -304,9 +304,7 @@
           }
   
           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 @@
               target = ((TypeAdapter) target).getProxy();
           }
   
  -        IntrospectionHelper.getHelper(target.getClass()).addText(project,
  +        IntrospectionHelper.getHelper(project, 
target.getClass()).addText(project,
               target, text);
       }
   
  @@ -388,7 +386,7 @@
       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.88      +1 -1      ant/src/main/org/apache/tools/ant/UnknownElement.java
  
  Index: UnknownElement.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/UnknownElement.java,v
  retrieving revision 1.87
  retrieving revision 1.88
  diff -u -r1.87 -r1.88
  --- UnknownElement.java       3 Mar 2005 14:02:32 -0000       1.87
  +++ UnknownElement.java       29 Mar 2005 21:47:59 -0000      1.88
  @@ -320,7 +320,7 @@
   
           String parentUri = getNamespace();
           Class parentClass = parent.getClass();
  -        IntrospectionHelper ih = IntrospectionHelper.getHelper(parentClass);
  +        IntrospectionHelper ih = IntrospectionHelper.getHelper(getProject(), 
parentClass);
   
   
           if (children != null) {
  
  
  
  1.30      +1 -1      
ant/src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java
  
  Index: ProjectHelperImpl.java
  ===================================================================
  RCS file: 
/home/cvs/ant/src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- ProjectHelperImpl.java    6 Jan 2005 12:05:09 -0000       1.29
  +++ ProjectHelperImpl.java    29 Mar 2005 21:47:59 -0000      1.30
  @@ -863,7 +863,7 @@
           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.44      +1 -1      
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.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- AntStructure.java 9 Mar 2005 00:20:40 -0000       1.43
  +++ AntStructure.java 29 Mar 2005 21:47:59 -0000      1.44
  @@ -200,7 +200,7 @@
   
           IntrospectionHelper ih = null;
           try {
  -            ih = IntrospectionHelper.getHelper(element);
  +            ih = IntrospectionHelper.getHelper(getProject(), element);
           } catch (Throwable t) {
               /*
                * XXX - failed to load the class properly.
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to