Pass NULL as receiver for static methods for ArgArray builder.

The receiver field is ignored for static methods, and may be null, but it
could be anything. Changed test 46 to make sure the value is properly
handled when it is not null.

Change-Id: Ide182b99c40a757e158f3587de7b413cd0cbb089
diff --git a/src/jni_internal.cc b/src/jni_internal.cc
index 344ce78..8729ed7 100644
--- a/src/jni_internal.cc
+++ b/src/jni_internal.cc
@@ -146,8 +146,8 @@
 static JValue InvokeWithVarArgs(const ScopedObjectAccess& soa, jobject obj,
                                 jmethodID mid, va_list args)
     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
-  Object* receiver = soa.Decode<Object*>(obj);
   AbstractMethod* method = soa.DecodeMethod(mid);
+  Object* receiver = method->IsStatic() ? NULL : soa.Decode<Object*>(obj);
   MethodHelper mh(method);
   JValue result;
   JValue float_result;
@@ -593,8 +593,8 @@
 
 JValue InvokeWithJValues(const ScopedObjectAccess& soa, jobject obj, jmethodID mid,
                          jvalue* args) {
-  Object* receiver = soa.Decode<Object*>(obj);
   AbstractMethod* method = soa.DecodeMethod(mid);
+  Object* receiver = method->IsStatic() ? NULL : soa.Decode<Object*>(obj);
   MethodHelper mh(method);
   JValue result;
   JValue float_result;
diff --git a/test/046-reflect/src/Main.java b/test/046-reflect/src/Main.java
index cf0a7e6..9d4cacf 100644
--- a/test/046-reflect/src/Main.java
+++ b/test/046-reflect/src/Main.java
@@ -391,6 +391,17 @@
         }
 
         try {
+            String s = "Should be ignored";
+            m.invoke(s, new Object(), Object.class);
+        } catch (IllegalAccessException iae) {
+            iae.printStackTrace();
+            return;
+        } catch (InvocationTargetException ite) {
+            ite.printStackTrace();
+            return;
+        }
+
+        try {
             System.out.println("checkType invoking null");
             m.invoke(null, new Object(), int.class);
             System.out.println("ERROR: should throw InvocationTargetException");