Patch: fix for Array.newInstance

Tom Tromey tromey@cygnus.com
Wed Mar 8 20:47:00 GMT 2000


I'm committing this patch.  It fixes a bug in Array.newInstance.

2000-03-08  Tom Tromey  <tromey@cygnus.com>

	* java/lang/reflect/natArray.cc (newInstance): Don't allow array
	of `void' to be created.

Tom

Index: java/lang/reflect/natArray.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/lang/reflect/natArray.cc,v
retrieving revision 1.5
diff -u -r1.5 natArray.cc
--- natArray.cc	2000/03/07 19:55:27	1.5
+++ natArray.cc	2000/03/09 04:46:16
@@ -1,6 +1,6 @@
 // natField.cc - Implementation of java.lang.reflect.Field native methods.
 
-/* Copyright (C) 1999  Free Software Foundation
+/* Copyright (C) 1999, 2000  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -29,7 +29,14 @@
 java::lang::reflect::Array::newInstance (jclass componentType, jint length)
 {
   if (componentType->isPrimitive())
-    return _Jv_NewPrimArray (componentType, length);
+    {
+      // We could check for this in _Jv_NewPrimArray, but that seems
+      // like needless overhead when the only real route to this
+      // problem is here.
+      if (componentType == JvPrimClass (void))
+	throw new java::lang::IllegalArgumentException ();
+      return _Jv_NewPrimArray (componentType, length);
+    }
   else
     return JvNewObjectArray (length, componentType, NULL);
 


More information about the Java-patches mailing list