title: Kotlin: Argument Type Mismatch when passing Array as vararg parameter
body: <p>I have a simple interface and its implementation:</p>
  
  <pre><code>interface Iface {
      fun doSomething(s: String)
  }
  
  class IfaceImpl : Iface {
      override fun doSomething(s: String) {
          println("Doing the job, s = $s")
      }
  }
  </code></pre>
  
  <p>Also, there are two identical (at least I cannot spot the difference) invocation handlers, one in Java and one in Kotlin:</p>
  
  <pre><code>public class JavaHandler implements InvocationHandler {
      private final Iface target;
  
      public JavaHandler(Iface target) {
          this.target = target;
      }
  
      @Override
      public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
          System.out.println("Java handler works");
          return method.invoke(target, args);
      }
  }
  
  class KotlinHandler(private val target: Iface) : InvocationHandler {
      override fun invoke(proxy: Any?, method: Method?, args: Array&lt;out Any&gt;?): Any {
          println("Kotlin proxy works")
          return method!!.invoke(target, args)
      }
  }
  </code></pre>
  
  <p>They both just output some string and then invoke the method on the target.</p>
  
  <p>Finally, here is the code I run:</p>
  
  <pre><code>fun main(args: Array&lt;String&gt;) {
      val target = IfaceImpl()
      target.doSomething("one")
  
      val javaProxy = newProxy(JavaHandler(target))
      javaProxy.doSomething("two")
  
      val kotlinProxy = newProxy(KotlinHandler(target))
      kotlinProxy.doSomething("three")
  }
  
  fun newProxy(handler: InvocationHandler): Iface {
      return Proxy.newProxyInstance(Iface::class.java.classLoader, arrayOf(Iface::class.java), handler) as Iface
  }
  </code></pre>
  
  <p>It creates two java proxies, using both invocation handlers, and tries to exercise them.</p>
  
  <p>Java handler works fine, but Kotlin handler does not. The output follows:</p>
  
  <pre><code>Doing the job, s = one
  Java handler works
  Doing the job, s = two
  Kotlin proxy works
  Exception in thread "main" java.lang.IllegalArgumentException: argument type mismatch
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at KotlinHandler.invoke(KotlinHandler.kt:12)
      at com.sun.proxy.$Proxy0.doSomething(Unknown Source)
      at TestKt.main(Test.kt:17)
  </code></pre>
  
  <p>I can see with a debugger that in both cases <code>args</code> consists of 1 element, and it's a <code>java.lang.Integer</code> instance.</p>
  
  <p>An interesting thing is that if the method has 0 parameters, the error message is different:</p>
  
  <pre><code>Exception in thread "main" java.lang.IllegalArgumentException: wrong number of arguments
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  </code></pre>
  
  <p>In such a case, <code>null</code> is passed as <code>args</code> parameter (which is allowed by javadocs for parameterless calls).</p>
  
  <p>Do I do something wrong? Or is this a bug?</p>
  
  <p>My build.gradle has the following:</p>
  
  <pre><code>plugins {
      id 'org.jetbrains.kotlin.jvm' version '1.2.61'
  }
  </code></pre>