File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes StackOverflowError in hashCode due to recursion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "StackOverflowError in hashCode due to recursion" Watch "StackOverflowError in hashCode due to recursion" New topic

StackOverflowError in hashCode due to recursion

Dave Joyce

Joined: Jul 30, 2007
Posts: 1

Hi guys,

Well, I know what my problem is, but I don't know how to solve it. Here's the scenario:

I have an abstract superclass ContactsEntry, which has subclasses Group and Person. As a note, I'm using the HashCodeUtil and EqualsUtil classes based on Josh Bloch's discussions from Effective Java, which are found at Implementing hashCode and Implementing equals, respectively.

These domain model classes are structured to provide a nodetree-like structure, but I'm getting a StackOverflowError between Group and Person classes, due to the dreaded infinite recursion loop blowout in the hashCode() method.

Finally, here's the obvious stack trace:

How do I break out of the recursive loop? Thanks!
I agree. Here's the link:
subject: StackOverflowError in hashCode due to recursion
Similar Threads
Incompatible type issue
ID:8 SCJP Question of the day !!!
Sorting through Comparable(Very Urgent)
problem with @FieldResult, mapping does not seem to work
Error setting the expression with value [Ljava.lang.String;@1d05b0a