java.lang.VerifyError 函数调用的不兼容对象参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5411487/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.lang.VerifyError Incompatible object argument for function call
提问by Lijat
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.
在编写一些 Java 代码时,我遇到了一个我不认识的异常,java.lang.VerifyError。一些谷歌搜索表明这通常是一个 jvm/javac 错误,我很好奇我的情况是否是这样。
The lines I suspect are
我怀疑的线路是
private Pair<Integer/*used size*/,Pair<K,V[]>[]>[] map=(Pair<Integer,Pair<K,V[]>[]>[])Array.newInstance(Pair.class,63);//good start number
and
和
map[b]=new Pair<Integer,Pair<K,V[]>[]>(7,(Pair<K,V[]>[])Array.newInstance(Pair.class,7));
but I'm far from certain.
但我还不确定。
Is this a compiler bug or is my code at fault.
这是编译器错误还是我的代码有问题。
Those lines are workarounds for the failure of array creation for arrays of generics that I found somewhere.
这些行是我在某处找到的泛型数组的数组创建失败的解决方法。
Code attached.
附上代码。
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");
}
};
}
}
and the Pair class this depends on
和 Pair 类这取决于
package osm2spacebook;
public class Pair<T1,T2>{
public T1 v1;
public T2 v2;
public Pair(T1 t1,T2 t2){
v1=t1;
v2=t2;
}
}
Full error message
完整的错误信息
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)
Line 64 of SqlOutput is the following
SqlOutput 的第 64 行如下
private MultiMap<Integer,Integer> edge_index=new MultiMap<Integer,Integer>();
回答by templatetypedef
A VerifyError usually means that you loaded in a class file that is somehow malformed or which references another class file that has changed in a way that causes the code in another class file to no longer be valid. For example, if you compiled a class file that referenced a method in some other class, then independently modified and recompiled the second class after altering that method's signature, you'd get this sort of error.
VerifyError 通常意味着您加载了一个以某种方式格式错误的类文件,或者它引用了另一个类文件,该类文件的更改方式导致另一个类文件中的代码不再有效。例如,如果您编译一个引用其他类中方法的类文件,然后在更改该方法的签名后独立修改并重新编译第二个类,则会出现此类错误。
I'd suggest doing a clean build and seeing if this issue goes away. If not, check whether you're using up-to-date JARs and source files.
我建议做一个干净的构建,看看这个问题是否消失。如果没有,请检查您是否使用了最新的 JAR 和源文件。
回答by Mike
For the unfortunate soul out there who runs across this issue... I've solved it twice now, 2 different ways (probably same underlying solution). I hope this saves you from the days I spent researching and beating head on wall...
对于遇到这个问题的不幸灵魂......我现在已经解决了两次,两种不同的方式(可能是相同的基本解决方案)。我希望这能让你免于我花时间研究和撞墙的日子......
My Project: SBT 0.13 / Lift 2.5 / Scala 2.10.2
我的项目:SBT 0.13 / Lift 2.5 / Scala 2.10.2
1st SOLUTION: I upgraded from SBT 0.11 / Lift 2.4 / Scala 2.9.2 to SBT 0.13 / Lift 2.5 / Scala 2.10.2. This was hell to get all the dependencies updated properly (took a day or 2), but it worked.
第一个解决方案:我从 SBT 0.11 / Lift 2.4 / Scala 2.9.2 升级到 SBT 0.13 / Lift 2.5 / Scala 2.10.2。正确更新所有依赖项(花了一两天时间)真是太糟糕了,但它起作用了。
2nd SOLUTION: I had no more-recent version to which I could upgrade, so I found another option: running an SBT clean didn't do the trick, so I went further and renamed (effectively deleting as far as SBT knew) all intermediate/derivative object folders (just added a '.archived' to their names) in the project folder structure (to force SBT to rebuild/populate everything from scratch), ie.
第二个解决方案:我没有可以升级到的最新版本,所以我找到了另一个选择:运行 SBT clean 没有成功,所以我更进一步并重命名(据 SBT 所知,有效删除)所有中间版本/derivative 对象文件夹(只是在其名称中添加了“.archived”)(强制 SBT 从头开始重建/填充所有内容),即。
- /lib/ --> which I believe is a folder I added, so may not be applicable to you.
- /project/target/\*.\*
- /project/project/target/\*.\*
- /target/\*.\*
- /lib/ --> 我认为这是我添加的文件夹,因此可能不适用于您。
- /项目/目标/\*.\*
- /project/project/target/\*.\*
- /目标/\*。\*
After that, SBT re-downloaded what it needed, rebuilt the contents of those folders, and everything worked. And as mentioned earlier, I believe this would have worked the first time also. I believe the upgrade did nothing other than create a scala_2.10.2 folder to populate freshly with intermediate/compiled objects, similar to me renaming the 'target' folders.
之后,SBT 重新下载了它需要的内容,重建了这些文件夹的内容,一切正常。正如前面提到的,我相信这也是第一次奏效。我相信升级只是创建了一个 scala_2.10.2 文件夹来填充中间/编译对象,类似于我重命名“目标”文件夹。