<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    Jboss AOP classloading bug
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="https://community.jboss.org/people/ud1">ud1</a> in <i>JBoss AOP</i> - <a href="https://community.jboss.org/message/715200#715200">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p><p>I'm using JBoss 6.0.0 with AOP for logging user actions and function call durations. Functions of interest are marked by our custom @Trace annotation and there is an our tracing aspect, that do all the work. But sometimes, probably after jboss restart, some random functionality of the project becomes unavailable, e.g. some dropdown lists didn't working or some buttons pressing do nothing. After second rebooting everething work fine. I can't reproduce this on my machine, but customers regulary (once or twice a month) reporting about the problem. Here is the typical log with org.jboss.classpool logging on:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><a class="jive-link-external-small" href="http://pastebin.com/f4TEduCB" target="_blank">http://pastebin.com/f4TEduCB</a></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>When all is functioning properly the log look's like:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><a class="jive-link-external-small" href="http://pastebin.com/zZKPk643" target="_blank">http://pastebin.com/zZKPk643</a></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I have made some investigation and degugging, so probably I have found the cause of the problem.</p><p>At first, if you look at ClassPoolToDomainAdapter with a lot of byte array class paths in it, you could see the difference, at normal working this list</p><p>contains BaseClassLoader@xxxxxx{vfs:///D:/retailHub/loan/server/default/deploy/myProject.ear} ClassPath at the end, but then the problem is it doesn't.</p><p>After deepest code investigation I figured out, that this could happen then something call close() on а ClassPool, and this probably happens inside unregisterClassLoader() function.</p><p>During joint point constraction Aspect Manager calls several times unregisterClassLoader() function:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>ClassPoolRepository</p><p>&#160;&#160; public void unregisterClassLoader(ClassLoader classLoader)</p><p>&#160;&#160; {</p><p>&#160;&#160;&#160;&#160;&#160; registryHandler.unregisterClassLoader(classLoader); // &lt;-- calls JBossClRegistryHandler.unregisterClassLoader()</p><p>&#160;&#160;&#160;&#160;&#160; if (callbacks != null &amp;&amp; callbacks.size() &gt; 0)</p><p>&#160;&#160;&#160;&#160;&#160; {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; for (ClassPoolRepositoryCallback callback : callbacks)</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; callback.classLoaderUnregistered(classLoader);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>which in turn calls JBossClRegistryHandler.registerClassLoader() functions with possible result of a closing the class pool.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>JBossClRegistryHandler</p><p>&#160;&#160; public ClassPool registerClassLoader(ClassLoader classLoader)</p><p>&#160;&#160; {</p><p>&#160;&#160;&#160;&#160;&#160; ScopedClassPool classPool = (ScopedClassPool) successor.registerClassLoader(classLoader);</p><p>&#160;&#160;&#160;&#160;&#160; if (classPool == null) // &lt;-- true</p><p>&#160;&#160;&#160;&#160;&#160; {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // TODO check this works; was delegate before</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; successor.unregisterClassLoader(classLoader); // &lt;-- calls classLoader.close()</p><p>&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160;&#160;&#160; else</p><p>&#160;&#160;&#160;&#160;&#160; {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Module module = getModuleForClassLoader(classLoader);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.registeredModules.put(module, classPool);</p><p>&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160;&#160;&#160; return classPool;</p><p>&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I can't understand what is the purpose of the DefaultClassLoaderRegistryHandler, but it can return null from registerClassLoader() function,</p><p>probaly then several jointpoints are generated concurrently from different threads:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>ClassPoolRepository$DefaultClassLoaderRegistryHandler</p><p>&#160;&#160;&#160;&#160;&#160; public ClassPool registerClassLoader(ClassLoader classLoader)</p><p>&#160;&#160;&#160;&#160;&#160; {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (classLoader == null)</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; classLoader = SecurityActions.getContextClassLoader();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (currentClassLoaders.putIfAbsent(classLoader, Boolean.TRUE) != null)</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return null; // &lt;-- Returns null</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ScopedClassPool classPool = (ScopedClassPool) ClassPoolRepository.super.registerClassLoader(classLoader);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; currentClassLoaders.remove(classLoader);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return classPool;</p><p>&#160;&#160;&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>ScopedClassPoolRepositoryImpl:</p><p>&#160;&#160; public void unregisterClassLoader(ClassLoader cl) {</p><p>&#160;&#160;&#160;&#160;&#160; synchronized (registeredCLs) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ScopedClassPool pool = registeredCLs.remove(cl);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (pool != null)</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; pool.close(); // &lt;-- close</p><p>&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160; }</p><p>&#160; </p><p>ScopedClassPool:</p><p>&#160;&#160; public void close() {</p><p>&#160;&#160;&#160;&#160;&#160; this.removeClassPath(classPath); // &lt;-- remove BaseClassLoader@xxxxxx{vfs:///D:/retailHub/loan/server/default/deploy/myProject.ear} classpath</p><p>&#160;&#160;&#160;&#160;&#160; classPath.close();</p><p>&#160;&#160;&#160;&#160;&#160; classes.clear();</p><p>&#160;&#160;&#160;&#160;&#160; softcache.clear();</p><p>&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>During joint point creation the myProject.war class loader is used, it redirects calls to JBossClClassPoolDomain, and in turn to SuperClassesFirstWeavingStrategy, and finally</p><p>the reference to the old ClassPool (with a lot of byte array class paths) is used. Is has no myProject.ear ClassLoader any more, so NotFoundException is fired.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I don't know how to fix this, I will appreciate your help.</p></p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/715200#715200">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JBoss AOP at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2027">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>