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 NullPointerException occurs and InvocationException masks it. I have the below Object methods overridden in TestField
.
Below utility classes are a part of commons-lang
jar.
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.
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.
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
Also take a look at this question, particularly the comment by Robin Green, have you tried debugging this code that way?
Example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With