diff -ur -x BUILD* -x *.log -x *.o -x Make* -x config* -x *.in -x include -x *.*o -x man -x scripts -x libtool -x *warnings -x *.la -x .libs -x rebuildLib* -x TestScript kaffe/libraries/clib/native/Class.c patched-kaffe/libraries/clib/native/Class.c
--- kaffe/libraries/clib/native/Class.c	Fri Jun  1 21:31:44 2001
+++ patched-kaffe/libraries/clib/native/Class.c	Sun Mar  3 11:35:50 2002
@@ -177,19 +177,6 @@
 }
 
 /*
- * Create a new instance of the derived class.
- */
-struct Hjava_lang_Object*
-java_lang_Class_newInstance(struct Hjava_lang_Class* this)
-{
-	if (CLASS_IS_PRIMITIVE(this)) {
-		SignalError("java.lang.InstantiationException",
-			    CLASS_CNAME(this));
-	}
-	return (execute_java_constructor(0, 0, this, "()V"));
-}
-
-/*
  * Return super class.
  *
  * Note that the specs demands to return null if the class object is an
@@ -776,8 +763,13 @@
 	 * parameter to all get(Declared){Method|Constructor} functions
 	 * is treated like passing an empty array "new Class [] {}"
 	 */
-	if ((argtypes == NULL) && METHOD_NARGS(mth) == 0) {
-		return (1);
+	if (argtypes == NULL) {
+		if (METHOD_NARGS(mth) == 0) {
+			return (1);
+		}
+		else {
+			return (0);
+		}
 	}
 
 	if (ARRAY_SIZE(argtypes) != METHOD_NARGS(mth)) {
@@ -800,6 +792,17 @@
 	return (1);
 }
 
+/* Check whether the loading of the class has failed. Throw an NoClassDefFoundError
+   in that the case.
+*/
+static
+void
+checkIfClassHasFailed(struct Hjava_lang_Class* clas)
+{
+	if (clas != NULL && clas->state == CSTATE_FAILED) {
+		SignalError("java.lang.NoClassDefFoundError", CLASS_CNAME(clas));
+	}
+}
 
 static
 Hjava_lang_reflect_Method*
@@ -827,6 +831,8 @@
 	Hjava_lang_reflect_Method *rmeth;
 
 	clas = this;
+	checkIfClassHasFailed(clas);
+
 	do {
 		rmeth = findMatchingMethod(clas, name, arr, declared);
 		if (rmeth != 0) {
@@ -862,11 +868,17 @@
 {
 	Hjava_lang_Class* clas = this;
 
-	Method* mth = CLASS_METHODS(clas);
-	int n = CLASS_NMETHODS(clas);
+	Method* mth;
+	int n;
 	int i;
+
+	checkIfClassHasFailed(clas);
+
+	mth = CLASS_METHODS(clas);
+	n = CLASS_NMETHODS(clas);
+
 	for (i = 0;  i < n;  ++mth, ++i) {
-		if (((mth->accflags & ACC_PUBLIC) || declared) && (mth->accflags & ACC_CONSTRUCTOR)) {
+		if (((mth->accflags & ACC_PUBLIC) || declared) && (METHOD_IS_CONSTRUCTOR(mth))) {
 			if (checkParameters(mth, arr))
 				return (makeConstructor(clas, i));
 		}
diff -ur -x BUILD* -x *.log -x *.o -x Make* -x config* -x *.in -x include -x *.*o -x man -x scripts -x libtool -x *warnings -x *.la -x .libs -x rebuildLib* -x TestScript kaffe/libraries/javalib/java/lang/Class.java patched-kaffe/libraries/javalib/java/lang/Class.java
--- kaffe/libraries/javalib/java/lang/Class.java	Thu Dec 20 13:50:57 2001
+++ patched-kaffe/libraries/javalib/java/lang/Class.java	Sun Mar  3 12:02:54 2002
@@ -14,6 +14,7 @@
 import java.io.Serializable;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Member;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
@@ -330,7 +331,29 @@
 
 native public boolean isPrimitive();
 
-native public Object newInstance() throws InstantiationException, IllegalAccessException;
+public Object newInstance() throws InstantiationException, IllegalAccessException {
+    if (Modifier.isAbstract(getModifiers()) || isInterface() || isPrimitive()) {
+	throw new InstantiationException(getName());
+    }
+    else {
+	try {
+	    return getDeclaredConstructor(null).newInstance(null);
+	}
+	catch (InvocationTargetException e) {
+	    // we rethrow runtime exceptions thrown by constructors, in order to
+	    // pass on exceptions like NullPointerException to the caller.
+	    if (e.getTargetException() instanceof RuntimeException) {
+		throw (RuntimeException) e.getTargetException();
+	    }
+	    else {
+		throw new InstantiationException(e.getTargetException().getMessage());
+	    }
+	}
+	catch (NoSuchMethodException e) {
+	    throw new InstantiationException(e.getMessage());
+	}
+    }
+}
 
 /*
  * toString()
diff -ur -x BUILD* -x *.log -x *.o -x Make* -x config* -x *.in -x include -x *.*o -x man -x scripts -x libtool -x *warnings -x *.la -x .libs -x rebuildLib* -x TestScript kaffe/test/regression/ConstructorTest.java patched-kaffe/test/regression/ConstructorTest.java
--- kaffe/test/regression/ConstructorTest.java	Fri Feb 12 14:51:07 1999
+++ patched-kaffe/test/regression/ConstructorTest.java	Sat Mar  2 15:47:16 2002
@@ -1,7 +1,7 @@
 /**
  * test that a class whose objects are instantiated via newInstance
  * do in fact have a default, no-arg constructor.  If they don't,
- * a NoSuchMethodError must be thrown.
+ * an InstantiationException must be thrown.
  */
 public class ConstructorTest {
   public ConstructorTest(int i) {}
@@ -10,7 +10,7 @@
   {
     try {
 	Object o = ConstructorTest.class.newInstance();
-    } catch (NoSuchMethodError e) {
+    } catch (InstantiationException e) {
 	System.out.println("Success.");
 	return;
     }





