I started off replicating the AS 4 classloaders with my new classpools, and stumbled upon
the following inconsistency when trying out how they work. Does anybody have any
pointers?
| public void testUndeployParentDomainClassLoader() throws Exception
| {
| ClassLoader globalA = null;
| ClassLoader globalB = null;
| ClassLoader child = null;
| try
| {
| try
| {
| globalA = createGlobalClassLoader(JAR_A_1); //Contains CLASS_A
| assertCannotLoadClass(globalA, CLASS_B);
|
| child = createChildClassLoader(JAR_C_1, true); //Contains CLASS_C
| assertCannotLoadClass(child, CLASS_B);
|
| globalB = createGlobalClassLoader(JAR_B_1); //Contains CLASS_B
| Class<?> bFromChild = child.loadClass(CLASS_B);
| Class<?> bFromA = globalA.loadClass(CLASS_B);
| assertSame(globalB, bFromA.getClassLoader());
| assertSame(bFromA, bFromChild);
| }
| finally
| {
| removeClassLoaderFromRepository(globalB); //This should remove the
classloader containing JAR_B_1/CLASS_B
| }
| assertCannotLoadClass(child, CLASS_B); //Fails since we can still find
CLASS_B
| }
| finally
| {
| removeClassLoaderFromRepository(globalA);
| }
| }
|
If I try the same from sibling loaders it works as expected
| public void testUndeploySibling() throws Exception
| {
| ClassLoader clA = null;
| ClassLoader clB = null;
| try
| {
| try
| {
| clA = createGlobalClassLoader(JAR_A_1);
| assertCannotLoadClass(clA, CLASS_B);
|
| clB = createGlobalClassLoader(JAR_B_1);
| Class<?> bFromA = clA.loadClass(CLASS_B);
| assertSame(clB, bFromA.getClassLoader());
| }
| finally
| {
| removeClassLoaderFromRepository(clB);
| }
| assertCannotLoadClass(clA, CLASS_B);
| }
| finally
| {
| removeClassLoaderFromRepository(clA);
| }
| }
|
The helper functions are here:
| protected ClassLoader createGlobalClassLoader(URL url) throws Exception
| {
| ClassLoader cl = globalRepository.newClassLoader(url, true); //This is the main
repository
| registeredClassLoaders.add(cl);
| return cl;
| }
|
| protected ClassLoader createChildClassLoader(URL url, boolean parentFirst) throws
Exception
| {
| HeirarchicalLoaderRepository3 repository = new
HeirarchicalLoaderRepository3(getServer(), MAIN_LOADER_REPOSITORY_OBJECT_NAME);
| repository.setUseParentFirst(parentFirst);
| ClassLoader cl = repository.newClassLoader(url, true);
| registeredClassLoaders.add(cl);
| return cl;
| }
|
| protected void removeClassLoaderFromRepository(ClassLoader cl)
| {
| if (cl != null)
| {
| if (cl instanceof RepositoryClassLoader)
| {
| LoaderRepository repository =
((RepositoryClassLoader)cl).getLoaderRepository();
| repository.removeClassLoader(cl);
| }
| }
| }
|
| protected void assertCannotLoadClass(ClassLoader cl, String className)
| {
| try
| {
| cl.loadClass(className);
| fail("Should not have been able to load " + className);
| }
| catch(Exception expected)
| {
| }
| }
|
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4185459#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...