Showing posts with label Arraylist giving error on add() method. Show all posts
Showing posts with label Arraylist giving error on add() method. Show all posts

Thursday, 29 April 2010

Found shared references to a collection hibernate

 Today when i was working on my project i saw a very strange bug saying "Found shared references to a collection hibernate" with a long stacktrace. After wasting a long time browsing through different sites. I started seeing the code, there i found a very small thing which solved my problem and it was that i initialized the variable before starting FOR loop and was trying to add multiple objects of the same memory reference again and again. For e.g.

ArrayList list = new ArrayList();
String str= new String("test");
for(int i=0; i
    list.add(i);
}
here you will get the same Found shared references error. Therefore i simply brougth the initialization into the FOR loop and it got resolved