[ 
https://issues.apache.org/jira/browse/SHINDIG-1132?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12736814#action_12736814
 ] 

Paul Lindner commented on SHINDIG-1132:
---------------------------------------

would creating a new errorhandler instance per builder fix this?

@@ -279,7 +266,21 @@ public class XmlUtil {
     } else {
       builder = builderFactory.newDocumentBuilder();
     }
-    builder.setErrorHandler(errorHandler);
+
+    // Create a new ErrorHandler to avoid ClassLoader issues.
+    builder.setErrorHandler(new ErrorHandler() {
+      public void error(SAXParseException exception) throws SAXException {
+        throw exception;
+      }
+      public void fatalError(SAXParseException exception) throws SAXException {
+        throw exception;
+      }
+      public void warning(SAXParseException exception) {
+        // warnings can be ignored.
+        LOG.log(Level.INFO, "XmlUtil warning", exception);
+      }
+    });
+
     return builder;
   }
 
Otherwise we might want to investigate a guice threadlocal scope as outlined 
here:

http://code.google.com/p/google-guice/issues/detail?id=114


> ClassLoader memory leak caused by XmlUtil ThreadLocal
> -----------------------------------------------------
>
>                 Key: SHINDIG-1132
>                 URL: https://issues.apache.org/jira/browse/SHINDIG-1132
>             Project: Shindig
>          Issue Type: Bug
>          Components: Java
>    Affects Versions: 1.0
>         Environment: When trying to unload the ClassLoader that loaded 
> Shindig, for instance in an OSGi environment
>            Reporter: Jed Wesley-Smith
>
> The class org.apache.shindig.common.xml.XmlUtil caches a 
> javax.xml.parsers.DocumentBuilder in the ThreadLocal reusableBuilder 
> variable. These instances are created with the static ErrorHandler instance 
> which creates the strong reference to the XmlUtil class that prevents the 
> ClassLoader from being reclaimed.
> Currently the only way to turn off this behaviour is for 
> DocumentBuilder.reset() to throw an exception.
> We need a way to turn off this caching. Maybe the caching aspect could be 
> injected via Guice?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to