java.lang.VerifyError函数调用的不兼容对象参数

Lij*_*jat 5 java exception

在编写一些java代码时,我遇到了一个我无法识别的异常,即java.lang.VerifyError.一些谷歌搜索表明这通常是一个jvm/javac错误,我很好奇,如果我的情况是.

我怀疑的是

private Pair<Integer/*used size*/,Pair<K,V[]>[]>[] map=(Pair<Integer,Pair<K,V[]>[]>[])Array.newInstance(Pair.class,63);//good start number
Run Code Online (Sandbox Code Playgroud)

map[b]=new Pair<Integer,Pair<K,V[]>[]>(7,(Pair<K,V[]>[])Array.newInstance(Pair.class,7));     
Run Code Online (Sandbox Code Playgroud)

但我很不确定.

这是编译器错误还是我的代码有问题.

这些行是我在某处找到的泛型数组创建失败的解决方法.

附加代码.

package osm2spacebook;

import java.util.Iterator;
import java.lang.reflect.Array;
import java.util.NoSuchElementException;

public class MultiMap<K,V> implements Iterable<K>{
    private int num_keys;
    @SuppressWarnings("unchecked")
    private Pair<Integer/*used size*/,Pair<K,V[]>[]>[] map=(Pair<Integer,Pair<K,V[]>[]>[])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<Integer,Pair<K,V[]>[]>(7,(Pair<K,V[]>[])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<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<K,V[]> m=map[bucket(key)].v2[position(key)];
        for(int i=0;i<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)<map[bucket(key)].v1;
    }
    public int numKeys(){
        return num_keys;
    }
    public Iterator<K> iterator(){
        return new Iterator<K>(){
            int bucket=0;
            int position=0;
            public boolean hasNext(){
                while(bucket<map.length){
                    if(map[bucket]!=null) 
                        if(position<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");
            }
        };
    }
}
Run Code Online (Sandbox Code Playgroud)

这取决于对类

package osm2spacebook;

public class Pair<T1,T2>{
    public T1 v1;
    public T2 v2;
    public Pair(T1 t1,T2 t2){
        v1=t1;
        v2=t2;
    }
}
Run Code Online (Sandbox Code Playgroud)

完整的错误消息

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.<init>(SqlOutput.java:64)
    at osm2spacebook.OsmImport.<init>(OsmImport.java:142)
    at osm2spacebook.OsmImport.main(OsmImport.java:280)
Run Code Online (Sandbox Code Playgroud)

SqlOutput的第64行如下

private MultiMap<Integer,Integer> edge_index=new MultiMap<Integer,Integer>();
Run Code Online (Sandbox Code Playgroud)

tem*_*def 6

VerifyError通常意味着您加载了一个类文件,该文件以某种方式格式错误或者引用了另一个类文件,该文件的更改方式导致另一个类文件中的代码不再有效.例如,如果您编译了一个引用其他类中的方法的类文件,然后在更改该方法的签名后单独修改并重新编译第二个类,则会出现此类错误.

我建议做一个干净的构建,看看这个问题是否消失了.如果没有,请检查您是否使用了最新的JAR和源文件.