[ 
https://issues.apache.org/jira/browse/PIVOT-742?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13033583#comment-13033583
 ] 

Andrei Pozolotin commented on PIVOT-742:
----------------------------------------

short term cheap fix is to replace all BXMLSerializer.readObject(...) to 
something like this:

public class Util {

        private static Logger log = LoggerFactory.getLogger(Util.class);

        @SuppressWarnings("unchecked")
        public static <T> T loadBXML(final Class<?> reference, final String 
resource) {

                final Thread thread = Thread.currentThread();
                final ClassLoader tccl = thread.getContextClassLoader();

                T result = null;

                try {

                        ClassLoader loader = reference.getClassLoader();

                        thread.setContextClassLoader(loader);

                        BXMLSerializer bxml = new BXMLSerializer(loader);

                        URL url = reference.getResource(resource);

                        result = (T) bxml.readObject(url);

                } catch (Exception e) {
                        log.error("", e);
                } finally {
                        thread.setContextClassLoader(tccl);
                }

                return result;

        }

}


> pluggable classloader
> ---------------------
>
>                 Key: PIVOT-742
>                 URL: https://issues.apache.org/jira/browse/PIVOT-742
>             Project: Pivot
>          Issue Type: Improvement
>            Reporter: Andrei Pozolotin
>
> pluggable classloader:
> 1) in current pivot trunk, TCCL, 
> Thread.currentThread().getContextClassLoader().... is mentioned 105 times
> I suggest to centralize it and replace with pluggable classloader (which can 
> use TCCL by default);
> 2) review all other uses of Class.getResource(), which are not using TCCL, 
> and convert when possible;
> motivation:
> https://issues.apache.org/jira/browse/PIVOT-22
> https://issues.apache.org/jira/browse/FELIX-2951
> http://njbartlett.name/2010/08/30/osgi-readiness-loading-classes.html 
> http://wiki.eclipse.org/index.php/Context_Class_Loader_Enhancements
> http://stackoverflow.com/questions/2198928/better-handling-of-thread-context-classloader-in-osgi
> http://mail-archives.apache.org/mod_mbox/pivot-user/201105.mbox/%3c4dcdf889.10...@gmail.com%3E

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to