diff --git a/WHATSNEW b/WHATSNEW index ce82b7223..d4d3281ab 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -7,6 +7,9 @@ Changes that could break older environments: Fixed bugs: ----------- +* OOM caused by IH holding on to classes and thus their classloaders. + Bugzilla 28283 and 33061. + Other changes: -------------- diff --git a/src/main/org/apache/tools/ant/IntrospectionHelper.java b/src/main/org/apache/tools/ant/IntrospectionHelper.java index 05f675f66..55055d7f1 100644 --- a/src/main/org/apache/tools/ant/IntrospectionHelper.java +++ b/src/main/org/apache/tools/ant/IntrospectionHelper.java @@ -48,9 +48,9 @@ public final class IntrospectionHelper implements BuildListener { = Collections.unmodifiableMap(new HashMap(0)); /** - * Helper instances we've already created (Class to IntrospectionHelper). + * Helper instances we've already created (Class.getName() to IntrospectionHelper). */ - private static final Hashtable HELPERS = new Hashtable(); + private static final Map HELPERS = new Hashtable(); /** * Map from primitive types to wrapper classes for use in @@ -331,13 +331,15 @@ public final class IntrospectionHelper implements BuildListener { * @return a helper for the specified class */ public static IntrospectionHelper getHelper(Project p, Class c) { - IntrospectionHelper ih = (IntrospectionHelper) HELPERS.get(c); - if (ih == null) { + IntrospectionHelper ih = (IntrospectionHelper) HELPERS.get(c.getName()); + // If a helper cannot be found, or if the helper is for another + // classloader, create a new IH + if (ih == null || ih.bean != c) { 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); + HELPERS.put(c.getName(), ih); } } if (p != null) {