*) Bugfix for serverClassLoader.java

- Classloading didn't work properly if there are multiple classes with the same name
   - This could occure because the yacy servlets have no package name defined and therefore
     are all in the same (default) package.

*) Bugfix for Duplicated Class Error
   See: http://www.yacy-forum.de/viewtopic.php?t=1341

  

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1135 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
theli 19 years ago
parent d4ac3e25b1
commit 5bf70e6e14

@ -64,6 +64,7 @@
<property name="libx" location="libx"/> <property name="libx" location="libx"/>
<property name="build" location="classes"/> <property name="build" location="classes"/>
<property name="htroot" location="htroot"/> <property name="htroot" location="htroot"/>
<property name="www" location="DATA/HTDOCS/www"/>
<property name="locales" location="locales"/> <property name="locales" location="locales"/>
<property name="release" location="RELEASE"/> <property name="release" location="RELEASE"/>
@ -214,6 +215,12 @@
classpathref="project.class.path" classpathref="project.class.path"
debug="true" debuglevel="lines,vars,source" debug="true" debuglevel="lines,vars,source"
source="${javacSource}" target="${javacTarget}"/> source="${javacSource}" target="${javacTarget}"/>
<!-- compile www directory -->
<javac srcdir="${www}/"
classpathref="project.class.path"
debug="true" debuglevel="lines,vars,source"
source="${javacSource}" target="${javacTarget}"/>
</target> </target>
<!-- compiling optional content parsers and building install packages --> <!-- compiling optional content parsers and building install packages -->

@ -43,20 +43,21 @@ package de.anomic.server;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.Hashtable; import java.util.Hashtable;
public final class serverClassLoader extends ClassLoader { public final class serverClassLoader extends ClassLoader {
private final Hashtable classes; private final HashMap classes;
public serverClassLoader() { public serverClassLoader() {
super(ClassLoader.getSystemClassLoader()); super(ClassLoader.getSystemClassLoader());
classes = new Hashtable(); this.classes = new HashMap();
} }
public serverClassLoader(ClassLoader parent) { public serverClassLoader(ClassLoader parent) {
super(parent); super(parent);
classes = new Hashtable(); classes = new HashMap();
} }
public Package[] packages() { public Package[] packages() {
@ -70,8 +71,17 @@ public final class serverClassLoader extends ClassLoader {
// normalize classkey: strip off '.class' // normalize classkey: strip off '.class'
//if (classkey.endsWith(".class")) classkey = classkey.substring(0, classkey.length() - 6); //if (classkey.endsWith(".class")) classkey = classkey.substring(0, classkey.length() - 6);
// try to find the class in the hashtable String classFileName = null;
Class c = (Class) classes.get(classfile); try {
classFileName = classfile.getCanonicalPath();
} catch (IOException e) {
throw new ClassNotFoundException("Unable to resolve the classfile path");
}
// try to load the class
synchronized(classFileName.intern()) {
// first try: take the class out of the cache, denoted by the classname
Class c = (Class) this.classes.get(classfile);
if (c != null) return c; if (c != null) return c;
// consider classkey as a file and extract the file name // consider classkey as a file and extract the file name
@ -87,19 +97,23 @@ public final class serverClassLoader extends ClassLoader {
// now that we have the name, we can create the real class file // now that we have the name, we can create the real class file
//classfile = new File(classkey + ".class"); //classfile = new File(classkey + ".class");
// first try: take the class out of the cache, denoted by the classname
try { // This code doesn't work properly if there are multiple classes with the same name
c = findLoadedClass(classname); // This is because we havn't definded package names in our servlets
if (c == null) { //
// second try: ask the system // try {
c = findSystemClass(classname); // c = findLoadedClass(classname);
} // if (c == null) {
if (c == null) { // // second try: ask the system
// third try // c = findSystemClass(classname);
throw new ClassNotFoundException("internal trigger"); // }
} // if (c == null) {
} catch (ClassNotFoundException e) { // // third try
// throw new ClassNotFoundException("internal trigger");
// }
// } catch (ClassNotFoundException e) {
//System.out.println("INTERNAL ERROR1 in cachedClassLoader: " + e.getMessage()); //System.out.println("INTERNAL ERROR1 in cachedClassLoader: " + e.getMessage());
// third try: load the file from the file system // third try: load the file from the file system
byte[] b; byte[] b;
try { try {
@ -108,13 +122,14 @@ public final class serverClassLoader extends ClassLoader {
// System.out.println("loading class " + classname + " from file " + classfile.toString()); // System.out.println("loading class " + classname + " from file " + classfile.toString());
c = this.defineClass(classname, b, 0, b.length); c = this.defineClass(classname, b, 0, b.length);
resolveClass(c); resolveClass(c);
classes.put(classfile, c); this.classes.put(classfile, c);
} catch (IOException ee) { } catch (IOException ee) {
//System.out.println("INTERNAL ERROR2 in cachedClassLoader: " + ee.getMessage()); //System.out.println("INTERNAL ERROR2 in cachedClassLoader: " + ee.getMessage());
throw new ClassNotFoundException(classfile.toString()); throw new ClassNotFoundException(classfile.toString());
} }
} // }
return c; return c;
} }
}
} }
Loading…
Cancel
Save