jQuery in Action, 3rd edition
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 OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 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: http://aspose.com/file-tools
subject: StackOverflowError in hashCode due to recursion
It's not a secret anymore!