JCL icon indicating copy to clipboard operation
JCL copied to clipboard

java.lang.LinkageError

Open mortezaadi opened this issue 12 years ago • 1 comments

  @Test
  public void test() throws Exception {
JarClassLoader jcl = new JarClassLoader();

//adding Test.jar (consist of com.google.at.mortezaadi.Sample)
//to JCL
jcl.add("test/Test.jar");

// insuring JCL can load the class
Class loadedClass = jcl.loadClass(
    "com.google.at.mortezaadi.Sample");
assertNotNull(loadedClass);

// unload class file inside the Test.Jar
jcl.unloadClass("com.google.at.mortezaadi.Sample");

// insuring jcl unloaded the class
boolean classExsist = false;
try{
    jcl.loadClass("com.google.at.mortezaadi.Sample");
    classExsist = true;
}catch(Exception ex) {
}
assertTrue(!classExsist);

/******************************/
//adding jar file again  
jcl.add("test/Test.jar");

   /** loading file again THROWS EXCEPTION
 * java.lang.LinkageError: loader (instance of  org/xeustechnologies/jcl/JarClassLoader): attempted  duplicate    class definition for name: "com/google/at/mortezaadi/Sample"
 */
loadedClass = jcl.loadClass(
    "com.google.at.mortezaadi.Sample");
}

mortezaadi avatar Dec 02 '13 08:12 mortezaadi

unload(String name) only remove the class entry from classPathResource. So, it cannot unload class from PermGen.

Only way i think is set JarclassLoader to null.

zhwbqd avatar Jun 22 '15 08:06 zhwbqd