title: java.lang.VerifyError Incompatible object argument for function call
body: <p>While writing some java code I run across an Exception that I did not recognise, the java.lang.VerifyError. Some googling indicated that this is often an jvm/javac bug and I'm curious if my case is.</p>
  
  <p>The lines I suspect are</p>
  
  <pre><code>private Pair&lt;Integer/*used size*/,Pair&lt;K,V[]&gt;[]&gt;[] map=(Pair&lt;Integer,Pair&lt;K,V[]&gt;[]&gt;[])Array.newInstance(Pair.class,63);//good start number
  </code></pre>
  
  <p>and   </p>
  
  <pre><code>map[b]=new Pair&lt;Integer,Pair&lt;K,V[]&gt;[]&gt;(7,(Pair&lt;K,V[]&gt;[])Array.newInstance(Pair.class,7));     
  </code></pre>
  
  <p>but I'm far from certain.</p>
  
  <p>Is this a compiler bug or is my code at fault.</p>
  
  <p>Those lines are workarounds for the failure of array creation for arrays of generics that I found somewhere.</p>
  
  <p>Code attached. </p>
  
  <pre><code>package osm2spacebook;
  
  import java.util.Iterator;
  import java.lang.reflect.Array;
  import java.util.NoSuchElementException;
  
  public class MultiMap&lt;K,V&gt; implements Iterable&lt;K&gt;{
      private int num_keys;
      @SuppressWarnings("unchecked")
      private Pair&lt;Integer/*used size*/,Pair&lt;K,V[]&gt;[]&gt;[] map=(Pair&lt;Integer,Pair&lt;K,V[]&gt;[]&gt;[])Array.newInstance(Pair.class,63);//good start number
      @SuppressWarnings("unchecked")
      private int bucket(K key){//position in bucket
          int h=key.hashCode();
          int b=h%map.length;
          if(map[b]==null)
              map[b]=new Pair&lt;Integer,Pair&lt;K,V[]&gt;[]&gt;(7,(Pair&lt;K,V[]&gt;[])Array.newInstance(Pair.class,7));
          return b;
      }
      private int position(K key){//position within bucket
          int b=bucket(key);//IMPORTANT this must use the buket function to obtain this otherwise it is a race
          for(int i=0;i&lt;map[b].v1;i++)
              if(map[b].v2[i].v1==key)
                  return i;
          if(map[b].v1==map[b].v2.length)
              map[b].v2=java.util.Arrays.copyOf(map[b].v2,map[b].v1*2);
          return map[b].v1++;
      }
      public V put(K key,V value){
          Pair&lt;K,V[]&gt; m=map[bucket(key)].v2[position(key)];
          for(int i=0;i&lt;m.v2.length;i++)
              if(m.v2[i]==value)
                  return value;
          m.v2=java.util.Arrays.copyOf(m.v2,m.v2.length+1);
          return m.v2[m.v2.length-1]=value;
      }
      public V[] get(K key){
          V[] v=map[bucket(key)].v2[position(key)].v2;
          return java.util.Arrays.copyOf(v,v.length);
      }
      public V[] remove(K key){
          throw new UnsupportedOperationException("Not implemented"); //TODO
      }
      public V remove(K key,V value){
          throw new UnsupportedOperationException("Not implemented"); //TODO
      }
      public boolean contains(K key){
          return position(key)&lt;map[bucket(key)].v1;
      }
      public int numKeys(){
          return num_keys;
      }
      public Iterator&lt;K&gt; iterator(){
          return new Iterator&lt;K&gt;(){
              int bucket=0;
              int position=0;
              public boolean hasNext(){
                  while(bucket&lt;map.length){
                      if(map[bucket]!=null) 
                          if(position&lt;map[bucket].v1)
                              return true;
                          else
                              position=0;
                      bucket++;
                  }
                  return false;
              }
              public K next(){
                  if(hasNext())//positions cursor on next element if any
                      return map[bucket].v2[position++].v1;//updates position after read
                  else
                      throw new NoSuchElementException();
              }
              public void remove(){
                  throw new UnsupportedOperationException("Remove not supported in multimap iterator du to ambiguity");
              }
          };
      }
  }
  </code></pre>
  
  <p>and the Pair class this depends on</p>
  
  <pre><code>package osm2spacebook;
  
  public class Pair&lt;T1,T2&gt;{
      public T1 v1;
      public T2 v2;
      public Pair(T1 t1,T2 t2){
          v1=t1;
          v2=t2;
      }
  }
  </code></pre>
  
  <p>Full error message</p>
  
  <pre><code>Exception in thread "main" java.lang.VerifyError: (class: osm2spacebook/MultiMap, method: position signature: (Ljava/lang/Object;)I) Incompatible object argument for function call
      at osm2spacebook.SqlOutput.&lt;init&gt;(SqlOutput.java:64)
      at osm2spacebook.OsmImport.&lt;init&gt;(OsmImport.java:142)
      at osm2spacebook.OsmImport.main(OsmImport.java:280)
  </code></pre>
  
  <p>Line 64 of SqlOutput is the following</p>
  
  <pre><code>private MultiMap&lt;Integer,Integer&gt; edge_index=new MultiMap&lt;Integer,Integer&gt;();
  </code></pre>