* prims.cc (_Jv_NewMultiArrayUnchecked): New method.
authortromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 2 Oct 2001 13:44:32 +0000 (13:44 +0000)
committertromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 2 Oct 2001 13:44:32 +0000 (13:44 +0000)
(_Jv_NewMultiArray): Use it.  Check each array dimension.
(_Jv_NewMultiArray): Likewise.
* java/lang/reflect/natMethod.cc (can_widen): Nothing promotes to
`char'.
* java/lang/reflect/natArray.cc (newInstance): Throw
IllegalArgumentException if there are no dimensions.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@45951 138bc75d-0d04-0410-961f-82ee72b054a4

libjava/ChangeLog
libjava/java/lang/reflect/natArray.cc
libjava/java/lang/reflect/natMethod.cc
libjava/prims.cc

index c7e3a57..ee54950 100644 (file)
@@ -1,3 +1,13 @@
+2001-10-01  Tom Tromey  <tromey@redhat.com>
+
+       * prims.cc (_Jv_NewMultiArrayUnchecked): New method.
+       (_Jv_NewMultiArray): Use it.  Check each array dimension.
+       (_Jv_NewMultiArray): Likewise.
+       * java/lang/reflect/natMethod.cc (can_widen): Nothing promotes to
+       `char'.
+       * java/lang/reflect/natArray.cc (newInstance): Throw
+       IllegalArgumentException if there are no dimensions.
+
 2001-10-01  Mark Wielaard  <mark@klomp.org>
 
        * java/io/FileWriter.java: Merge with Classpath.
index bc48041..7875122 100644 (file)
@@ -43,11 +43,12 @@ java::lang::reflect::Array::newInstance (jclass componentType, jint length)
 }
 
 jobject
-java::lang::reflect::Array::newInstance (jclass componentType, jintArray dimensions)
+java::lang::reflect::Array::newInstance (jclass componentType,
+                                        jintArray dimensions)
 {
   jint ndims = dimensions->length;
   if (ndims == 0)
-    return componentType->newInstance ();
+    throw new java::lang::IllegalArgumentException ();
   jint* dims = elements (dimensions);
   if (ndims == 1)
     return newInstance (componentType, dims[0]);
index 96cc132..26c270e 100644 (file)
@@ -100,8 +100,8 @@ can_widen (jclass from, jclass to)
   // Boolean arguments may not be widened.
   if (fromx == BOOLEAN && tox != BOOLEAN)
     return false;
-  // Special-case short->char conversions.
-  if (fromx == SHORT && tox == CHAR)
+  // Nothing promotes to char.
+  if (tox == CHAR && fromx != CHAR)
     return false;
 
   return fromx <= tox;
index 6a13ed5..9b4ac24 100644 (file)
@@ -516,8 +516,10 @@ _Jv_NewArray (jint type, jint size)
   return NULL;                 // Placate compiler.
 }
 
-jobject
-_Jv_NewMultiArray (jclass type, jint dimensions, jint *sizes)
+// Allocate a possibly multi-dimensional array but don't check that
+// any array length is <0.
+static jobject
+_Jv_NewMultiArrayUnchecked (jclass type, jint dimensions, jint *sizes)
 {
   JvAssert (type->isArray());
   jclass element_type = type->getComponentType();
@@ -533,14 +535,24 @@ _Jv_NewMultiArray (jclass type, jint dimensions, jint *sizes)
       JvAssert (element_type->isArray());
       jobject *contents = elements ((jobjectArray) result);
       for (int i = 0; i < sizes[0]; ++i)
-       contents[i] = _Jv_NewMultiArray (element_type, dimensions - 1,
-                                        sizes + 1);
+       contents[i] = _Jv_NewMultiArrayUnchecked (element_type, dimensions - 1,
+                                                 sizes + 1);
     }
 
   return result;
 }
 
 jobject
+_Jv_NewMultiArray (jclass type, jint dimensions, jint *sizes)
+{
+  for (int i = 0; i < dimensions; ++i)
+    if (sizes[i] < 0)
+      throw new java::lang::NegativeArraySizeException;
+
+  return _Jv_NewMultiArrayUnchecked (type, dimensions, sizes);
+}
+
+jobject
 _Jv_NewMultiArray (jclass array_type, jint dimensions, ...)
 {
   va_list args;
@@ -549,11 +561,13 @@ _Jv_NewMultiArray (jclass array_type, jint dimensions, ...)
   for (int i = 0; i < dimensions; ++i)
     {
       jint size = va_arg (args, jint);
+      if (size < 0)
+       throw new java::lang::NegativeArraySizeException;
       sizes[i] = size;
     }
   va_end (args);
 
-  return _Jv_NewMultiArray (array_type, dimensions, sizes);
+  return _Jv_NewMultiArrayUnchecked (array_type, dimensions, sizes);
 }
 
 \f