src/share/vm/prims/jvm.cpp

Print this page
rev 7343 : 8058313: Mismatch of method descriptor and MethodParameters.parameters_count should cause MalformedParameterException
Summary: Allow hotspot to store and report zero-length MethodParameters attribute data
Reviewed-by: coleenp, jiangli

@@ -1655,11 +1655,21 @@
   Method* method_ptr = jvm_get_method_common(method);
   methodHandle mh (THREAD, method_ptr);
   Handle reflected_method (THREAD, JNIHandles::resolve_non_null(method));
   const int num_params = mh->method_parameters_length();
 
-  if (0 != num_params) {
+  if (num_params < 0) {
+    // A -1 return value from method_parameters_length means there is no
+    // parameter data.  Return null to indicate this to the reflection
+    // API.
+    assert(num_params == -1, "num_params should be -1 if it is less than zero");
+    return (jobjectArray)NULL;
+  } else {
+    // Otherwise, we return something up to reflection, even if it is
+    // a zero-length array.  Why?  Because in some cases this can
+    // trigger a MalformedParametersException.
+
     // make sure all the symbols are properly formatted
     for (int i = 0; i < num_params; i++) {
       MethodParametersElement* params = mh->method_parameters_start();
       int index = params[i].name_cp_index;
       bounds_check(mh->constants(), index, CHECK_NULL);

@@ -1683,12 +1693,10 @@
       oop param = Reflection::new_parameter(reflected_method, i, sym,
                                             flags, CHECK_NULL);
       result->obj_at_put(i, param);
     }
     return (jobjectArray)JNIHandles::make_local(env, result());
-  } else {
-    return (jobjectArray)NULL;
   }
 }
 JVM_END
 
 // New (JDK 1.4) reflection implementation /////////////////////////////////////