• Post Reply Bookmark Topic Watch Topic
  • New Topic

StackOverflowError using hashCode() in HashMap in recursive method  RSS feed

 
Edward Martinez
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,
OK, I'm really stumped here. I'm getting a StackOverflowError, which is occurring on the first line of my overridden hashCode() method of my POJO. hashCode() is being called from the get() method of HashMap, which is used in a recursive method. The map is not self-referential. Here's a snippet of hashCode().



This is generated by Eclipse.

Here's what the recursion looks like:



Any ideas anyone has would be greatly appreciated.

Thanks,

Eddie
 
Piet Verdriet
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, apparently never happens and you keep recursively calling the method. Have you overridden the equals(Object) method as well? Can you post it here?
 
Edward Martinez
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Piet,
Thanks for your response. Sorry it took me so long to get back to you.

Here are the attributes of my class:



Here's my equals() method, which was generated by Eclipse:


I may have found a workaround for this. I started using a String as the key in the HashMap, rather than the complex type, and the infinite recursion has disappeared, so far. I'm going to let it soak for the rest of this week and see how it does.

Thanks for your help,

Eddie
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That equals method looks really ugly. With just a little utility method you can make it so much easier to read:
 
Piet Verdriet
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:... With just a little utility method you can make it so much easier to read:
...


Indeed!
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should never actually look at an automatically generated method. Not unless you have a very strong stomach
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!