[Kaffe] bug found in Kaffe's classloader implementation

Godmar Back gback at cs.utah.edu
Wed Mar 17 22:05:41 PST 1999


 Should be fixed now.

Thanks,

	- Godmar

> 
> Hello.
> 
> I have run into another problem with kaffe. This example code
> shows how the classloader works in the JDK and that Kaffe
> just calls exit(). I tried to implement a fix for this problem
> in the file kaffe/kaffevm/readClass.c but the code does not
> want to compile. Could someone with more knowledge of the kaffe
> internals take a look at this problem and my partial fix?
> 
> 
> 
> public class ClassDefineBug {
> 
>     public static void main(String[] argv) throws Exception {
> 
> 	MyClassLoader mcl = new MyClassLoader();
> 	
> 	String data = "somestring";
> 	
> 	Class result = mcl.defineClass(null, data.getBytes());
> 
> 	System.out.println("result is " + result);
>     }
> }
> 
> class MyClassLoader extends ClassLoader {
> 
> Class defineClass(String className, byte[] classData) {
>     Class result = null;
>     try {
> 	result = defineClass(null, classData, 0, classData.length);
>     } catch (ClassFormatError e) {
> 	System.out.println("ClassFormatError caught \"" + e.getMessage()
> 			   + "\"");
>     }
>     return result;
> }
> 
> 
> protected Class loadClass(String className,boolean resolveIt)
>     throws ClassNotFoundException, SecurityException
> {
>     return Class.forName(className);
> }
> 
> }
> 
> 
> 
> 
> 
> 
> JDK output
> 
> % java ClassDefineBug
> ClassFormatError caught "Bad magic number"
> result is null
> 
> 
> 
> Kaffe output
> 
> % kaffe ClassDefineBug
> Bad magic 736f6d65 in class
> 
> 
> 
> 
> 
> Index: readClass.c
> ===================================================================
> RCS file: /home/cvspublic/kaffe/kaffe/kaffevm/readClass.c,v
> retrieving revision 1.5
> diff -u -r1.5 readClass.c
> --- readClass.c 1999/01/07 21:03:19     1.5
> +++ readClass.c 1999/03/18 03:13:31
> @@ -19,6 +19,7 @@
>  #include "file.h"
>  #include "access.h"
>  #include "object.h"
> +#include "errors.h"
>  #include "constants.h"
>  #ifdef KAFFEH
>  #include <readClassConfig.h>
> @@ -41,8 +42,13 @@
>         /* Read in class info */
>         readu4(&magic, fp);
>         if (magic != JAVAMAGIC) {
> +               /*
>                 fprintf(stderr, "Bad magic %x in class\n", magic);
>                 EXIT(1);
> +                */
> +                SET_LANG_EXCEPTION_MESSAGE(einfo,
> +                       ClassFormatError, "Bad magic number");
> +               return (0);
>         }
>         readu2(&minor_version, fp);
>         readu2(&major_version, fp);
> 
> 
> 
> 
> thanks
> 
> Mo DeJong
> dejong at cs.umn.edu
> 
> 



More information about the kaffe mailing list