Java com.sun.jdi.InvocationException 在 JDK8 中调用方法发生
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31541283/
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
com.sun.jdi.InvocationException occurred invoking method in JDK8
提问by sridhar
I am migrating my application from JDK 7 to JDK 8. While doing, I am facing an exception com.sun.jdi.InvocationException occurred invoking method
when an instance of TestField
as shown below is created. I am getting the exception while debugging and could not find the reason for it. I suspect NullPointerExceptionoccurs and InvocationExceptionmasks it. I have the below Object methods overridden in TestField
.
我正在将我的应用程序从 JDK 7 迁移到 JDK 8。在这样做时,com.sun.jdi.InvocationException occurred invoking method
当TestField
创建如下所示的实例时,我遇到了异常。我在调试时遇到异常,但找不到原因。我怀疑发生NullPointerException并且InvocationException掩盖了它。我在TestField
.
Below utility classes are a part of commons-lang
jar.
下面的实用程序类是commons-lang
jar的一部分。
HashCodeBuilder
EqualsBuilder
ToStringBuilder
HashCodeBuilder
EqualsBuilder
ToStringBuilder
public class TestField {
private String name;
private Rules rules;
public TestField(String name, Rules rules)
{ this.name = name;
this.rules = rules;
}
public String toString() {
return new ToStringBuilder(this)
.append("\n name", this.getName())
.append("\n Rules", this.getRules())
.append("\n ")
.toString();
}
public boolean equals(Object other) {
if ( !(other instanceof TestField) ) return false;
TestField castOther = (TestField) other;
return new EqualsBuilder()
.append(this.getName(), castOther.getName())
.append(this.getRules(), castOther.getRules())
.isEquals();
}
public int hashCode() {
return new HashCodeBuilder()
.append(this.getName())
.append(this.getRules())
.toHashCode();
}
}
Have anyone faced such an issue. Could anyone please help me to resolve the same. Thanks.
有没有人遇到过这样的问题。任何人都可以帮我解决同样的问题。谢谢。
采纳答案by Blizzardengle
Although I have not run into this particular issue I have had my fair share of migration issues that were caused by little changes that got masked by later processes.
尽管我还没有遇到过这个特定问题,但我也遇到过相当多的迁移问题,这些问题是由后来的流程掩盖的微小变化引起的。
I was going to suggest backtracking and looking at your toString method but it seems several people have had this same exact problem already; toString or your toHashCode is the most likely culprits. In a nut shell a null pointer exception is most likely being thrown but masked by the com.sun.jdi.InvocationException error. So if you are getting a Null Pointer Exception chances are there still was something that happened before that but was masked. Just take parts of your code out and work them back in step by step.
我打算建议回溯并查看您的 toString 方法,但似乎有几个人已经遇到了同样的问题;toString 或您的 toHashCode 是最有可能的罪魁祸首。简而言之,最有可能抛出空指针异常,但被 com.sun.jdi.InvocationException 错误掩盖。因此,如果您收到空指针异常,则可能在此之前仍然发生了一些事情,但被屏蔽了。只需取出部分代码,然后一步一步地重新处理它们。
Here is the other question and answers that I think will solve this (I do not have the reputation to mark as a duplicate):
这是我认为可以解决此问题的其他问题和答案(我没有将其标记为重复的声誉):
com-sun-jdi-invocationexception occurred invoking method
com-sun-jdi-invocationException 发生调用方法
Also take a look at this question, particularly the comment by Robin Green, have you tried debugging this code that way?
也看看这个问题,特别是 Robin Green 的评论,你试过用这种方式调试这段代码吗?
回答by PipoTells
You might want to check the hashcode() of your class. If by any way it can get stuck in a nullPointer Exception, Mockito will not be able to invoke the method. For example, if the hashCode() has been implemeted using arguments passed int he constructor of your class, and any of them is null.
您可能想要检查您班级的 hashcode()。如果它以任何方式卡在 nullPointer 异常中,Mockito 将无法调用该方法。例如,如果 hashCode() 已经使用传递给你的类的构造函数的参数来实现,并且它们中的任何一个都是空的。