Ensure that BoxPrimitive only sees clean data...

...rather than forcing it to zero irrelevant bits itself.

Change-Id: Ibbd28db08b68fac84704a911a6f927f7d9343055
diff --git a/src/java_lang_reflect_Field.cc b/src/java_lang_reflect_Field.cc
index d1b40f3..b22212f 100644
--- a/src/java_lang_reflect_Field.cc
+++ b/src/java_lang_reflect_Field.cc
@@ -89,11 +89,11 @@
   }
 
   // Get the field's value, boxing if necessary.
-  JValue value;
+  JValue value = { 0 };
   if (!GetFieldValue(o, f, value, true)) {
     return NULL;
   }
-  BoxPrimitive(env, FieldHelper(f).GetTypeAsPrimitiveType(), value);
+  BoxPrimitive(FieldHelper(f).GetTypeAsPrimitiveType(), value);
 
   return AddLocalReference<jobject>(env, value.l);
 }
@@ -106,7 +106,7 @@
   }
 
   // Read the value.
-  JValue field_value;
+  JValue field_value = { 0 };
   if (!GetFieldValue(o, f, field_value, false)) {
     return JValue();
   }
@@ -206,7 +206,7 @@
   // Unbox the value, if necessary.
   Object* boxed_value = Decode<Object*>(env, javaValue);
   JValue unboxed_value;
-  if (!UnboxPrimitive(env, boxed_value, FieldHelper(f).GetType(), unboxed_value, "field")) {
+  if (!UnboxPrimitive(boxed_value, FieldHelper(f).GetType(), unboxed_value, "field")) {
     return;
   }
 
diff --git a/src/jni_internal.cc b/src/jni_internal.cc
index 5230de92..37ca93d 100644
--- a/src/jni_internal.cc
+++ b/src/jni_internal.cc
@@ -257,7 +257,7 @@
 
 static JValue InvokeWithArgArray(JNIEnv* public_env, Object* receiver, Method* method, JValue* args) {
   JNIEnvExt* env = reinterpret_cast<JNIEnvExt*>(public_env);
-  JValue result;
+  JValue result = { 0 };
   method->Invoke(env->self, receiver, args, &result);
   return result;
 }
diff --git a/src/reflection.cc b/src/reflection.cc
index c06a879..ffc1e1f 100644
--- a/src/reflection.cc
+++ b/src/reflection.cc
@@ -92,7 +92,7 @@
     Class* dst_class = mh.GetClassFromTypeIdx(classes->GetTypeItem(i).type_idx_);
     if (dst_class->IsPrimitive()) {
       std::string what(StringPrintf("argument %d", i + 1)); // Humans count from 1.
-      if (!UnboxPrimitive(env, arg, dst_class, decoded_args[i], what.c_str())) {
+      if (!UnboxPrimitive(arg, dst_class, decoded_args[i], what.c_str())) {
         return NULL;
       }
     } else {
@@ -115,7 +115,7 @@
   }
 
   // Box if necessary and return.
-  BoxPrimitive(env, mh.GetReturnType()->GetPrimitiveType(), value);
+  BoxPrimitive(mh.GetReturnType()->GetPrimitiveType(), value);
   return AddLocalReference<jobject>(env, value.l);
 }
 
@@ -229,46 +229,36 @@
   return false;
 }
 
-void BoxPrimitive(JNIEnv*, Primitive::Type src_class, JValue& value) {
+void BoxPrimitive(Primitive::Type src_class, JValue& value) {
   if (src_class == Primitive::kPrimNot) {
     return;
   }
 
   Method* m = NULL;
-  JValue args[1];
-  args[0].j = 0;
   switch (src_class) {
   case Primitive::kPrimBoolean:
     m = gBoolean_valueOf;
-    args[0].z = value.z;
     break;
   case Primitive::kPrimByte:
     m = gByte_valueOf;
-    args[0].b = value.b;
     break;
   case Primitive::kPrimChar:
     m = gCharacter_valueOf;
-    args[0].c = value.c;
     break;
   case Primitive::kPrimDouble:
     m = gDouble_valueOf;
-    args[0].d = value.d;
     break;
   case Primitive::kPrimFloat:
     m = gFloat_valueOf;
-    args[0].f = value.f;
     break;
   case Primitive::kPrimInt:
     m = gInteger_valueOf;
-    args[0].i = value.i;
     break;
   case Primitive::kPrimLong:
     m = gLong_valueOf;
-    args[0].j = value.j;
     break;
   case Primitive::kPrimShort:
     m = gShort_valueOf;
-    args[0].s = value.s;
     break;
   case Primitive::kPrimVoid:
     // There's no such thing as a void field, and void methods invoked via reflection return null.
@@ -280,10 +270,11 @@
 
   Thread* self = Thread::Current();
   ScopedThreadStateChange tsc(self, Thread::kRunnable);
+  JValue args[1] = { value };
   m->Invoke(self, NULL, args, &value);
 }
 
-bool UnboxPrimitive(JNIEnv*, Object* o, Class* dst_class, JValue& unboxed_value, const char* what) {
+bool UnboxPrimitive(Object* o, Class* dst_class, JValue& unboxed_value, const char* what) {
   if (!dst_class->IsPrimitive()) {
     if (o != NULL && !o->InstanceOf(dst_class)) {
       Thread::Current()->ThrowNewExceptionF("Ljava/lang/IllegalArgumentException;",
diff --git a/src/reflection.h b/src/reflection.h
index a286a57..f5173d9 100644
--- a/src/reflection.h
+++ b/src/reflection.h
@@ -27,8 +27,8 @@
 class Object;
 
 void InitBoxingMethods();
-void BoxPrimitive(JNIEnv* env, Primitive::Type src_class, JValue& value);
-bool UnboxPrimitive(JNIEnv* env, Object* o, Class* dst_class, JValue& unboxed_value, const char* what);
+void BoxPrimitive(Primitive::Type src_class, JValue& value);
+bool UnboxPrimitive(Object* o, Class* dst_class, JValue& unboxed_value, const char* what);
 
 bool ConvertPrimitiveValue(Primitive::Type src_class, Primitive::Type dst_class, const JValue& src, JValue& dst);
 
diff --git a/src/runtime_support.cc b/src/runtime_support.cc
index 230c24f..c61db20 100644
--- a/src/runtime_support.cc
+++ b/src/runtime_support.cc
@@ -1170,7 +1170,7 @@
         uint64_t high_half = *reinterpret_cast<uint32_t*>(stack_args + (13 * kPointerSize));
         val.j = (val.j & 0xffffffffULL) | (high_half << 32);
       }
-      BoxPrimitive(env, param_type->GetPrimitiveType(), val);
+      BoxPrimitive(param_type->GetPrimitiveType(), val);
       if (self->IsExceptionPending()) {
         return;
       }
@@ -1189,7 +1189,7 @@
       obj = self->DecodeJObject(*reinterpret_cast<jobject*>(stack_args + (cur_arg * kPointerSize)));
     } else {
       JValue val = *reinterpret_cast<JValue*>(stack_args + (cur_arg * kPointerSize));
-      BoxPrimitive(env, param_type->GetPrimitiveType(), val);
+      BoxPrimitive(param_type->GetPrimitiveType(), val);
       if (self->IsExceptionPending()) {
         return;
       }
@@ -1218,7 +1218,7 @@
     Object* result_ref = self->DecodeJObject(result);
     if (result_ref != NULL) {
       JValue result_unboxed;
-      bool unboxed_okay = UnboxPrimitive(env, result_ref, proxy_mh.GetReturnType(), result_unboxed, "result");
+      bool unboxed_okay = UnboxPrimitive(result_ref, proxy_mh.GetReturnType(), result_unboxed, "result");
       CHECK(unboxed_okay);
       *reinterpret_cast<JValue*>(stack_args) = result_unboxed;
     } else {