Program: 117454
Project: 117454
Buggy source:
@Test public void testReferencesHook() throws Exception {
  assertTrue(OrientDbWebSession.get().signIn("String_Node_Str","String_Node_Str"));
  ODatabaseDocument db=OrientDbWebSession.get().getDatabase();
  OSchema schema=db.getMetadata().getSchema();
  assertFalse(db.isClosed());
  db.commit();
  if (schema.existsClass(TEST_CLASS_A))   schema.dropClass(TEST_CLASS_A);
  OClass classA=schema.createClass(TEST_CLASS_A);
  try {
    OProperty parent=classA.createProperty("String_Node_Str",OType.LINK);
    OProperty child=classA.createProperty("String_Node_Str",OType.LINKLIST);
    CustomAttributes.PROP_INVERSE.setValue(parent,child);
    CustomAttributes.PROP_INVERSE.setValue(child,parent);
    ODocument rootDoc=new ODocument(classA);
    rootDoc.save();
    ODocument child1Doc=new ODocument(classA);
    child1Doc.field("String_Node_Str",rootDoc);
    child1Doc.save();
    rootDoc.reload();
    Collection<OIdentifiable> childCollection=rootDoc.field("String_Node_Str");
    assertEquals(1,childCollection.size());
    assertTrue(childCollection.contains(child1Doc));
    ODocument child2Doc=new ODocument(classA);
    child2Doc.field("String_Node_Str",rootDoc);
    child2Doc.save();
    rootDoc.reload();
    childCollection=rootDoc.field("String_Node_Str");
    assertEquals(2,childCollection.size());
    assertTrue(childCollection.contains(child1Doc));
    assertTrue(childCollection.contains(child2Doc));
    child1Doc.reload();
    child1Doc.delete();
    rootDoc.reload();
    childCollection=rootDoc.field("String_Node_Str");
    assertEquals(1,childCollection.size());
    assertTrue(childCollection.contains(child2Doc));
    ODocument child3Doc=new ODocument(classA);
    child3Doc.save();
    childCollection.add(child3Doc);
    rootDoc.field("String_Node_Str",childCollection);
    rootDoc.save();
    rootDoc.reload();
    childCollection=rootDoc.field("String_Node_Str");
    assertEquals(2,childCollection.size());
    assertTrue(childCollection.contains(child2Doc));
    assertTrue(childCollection.contains(child3Doc));
    child3Doc.reload();
    assertNotNull("String_Node_Str",child3Doc.field("String_Node_Str"));
    OIdentifiable rootId=child3Doc.field("String_Node_Str");
    assertEquals(rootDoc,rootId.getRecord());
    child2Doc.field("String_Node_Str",(Object)null);
    child2Doc.save();
    rootDoc.reload();
    childCollection=rootDoc.field("String_Node_Str");
    assertEquals(1,childCollection.size());
    assertTrue(childCollection.contains(child3Doc));
    childCollection.clear();
    rootDoc.field("String_Node_Str",childCollection);
    rootDoc.save();
    child3Doc.reload();
    assertNull(child3Doc.field("String_Node_Str"));
  }
  finally {
    schema.dropClass(TEST_CLASS_A);
    OrientDbWebSession.get().signOut();
  }
}

Fixed version (ground truth):
@Test public void testReferencesHook() throws Exception {
  assertTrue(OrientDbWebSession.get().signIn("String_Node_Str","String_Node_Str"));
  ODatabaseDocument db=OrientDbWebSession.get().getDatabase();
  OSchema schema=db.getMetadata().getSchema();
  assertFalse(db.isClosed());
  db.commit();
  if (schema.existsClass(TEST_CLASS_A))   schema.dropClass(TEST_CLASS_A);
  OClass classA=schema.createClass(TEST_CLASS_A);
  try {
    OProperty parent=classA.createProperty("String_Node_Str",OType.LINK);
    OProperty child=classA.createProperty("String_Node_Str",OType.LINKLIST);
    CustomAttributes.PROP_INVERSE.setValue(parent,child);
    CustomAttributes.PROP_INVERSE.setValue(child,parent);
    ODocument rootDoc=new ODocument(classA);
    rootDoc.save();
    ODocument child1Doc=new ODocument(classA);
    child1Doc.field("String_Node_Str",rootDoc);
    child1Doc.save();
    rootDoc.reload();
    Collection<OIdentifiable> childCollection=rootDoc.field("String_Node_Str");
    assertEquals(1,childCollection.size());
    assertTrue(childCollection.contains(child1Doc));
    ODocument child2Doc=new ODocument(classA);
    child2Doc.field("String_Node_Str",rootDoc);
    child2Doc.save();
    rootDoc.reload();
    childCollection=rootDoc.field("String_Node_Str");
    assertEquals(2,childCollection.size());
    assertTrue(childCollection.contains(child1Doc));
    assertTrue(childCollection.contains(child2Doc));
    child1Doc.reload();
    child1Doc.delete();
    rootDoc.reload();
    childCollection=rootDoc.field("String_Node_Str");
    assertEquals(1,childCollection.size());
    assertTrue(childCollection.contains(child2Doc));
    ODocument child3Doc=new ODocument(classA);
    child3Doc.save();
    childCollection.add(child3Doc);
    rootDoc.field("String_Node_Str",childCollection);
    rootDoc.save();
    rootDoc.reload();
    childCollection=rootDoc.field("String_Node_Str");
    assertEquals(2,childCollection.size());
    assertTrue(childCollection.contains(child2Doc));
    assertTrue(childCollection.contains(child3Doc));
    child3Doc.reload();
    assertNotNull("String_Node_Str",child3Doc.field("String_Node_Str"));
    OIdentifiable rootId=child3Doc.field("String_Node_Str");
    assertEquals(rootDoc,rootId.getRecord());
    child2Doc.field("String_Node_Str",(Object)null);
    child2Doc.save();
    rootDoc.reload();
    childCollection=rootDoc.field("String_Node_Str");
    assertEquals(1,childCollection.size());
    assertTrue(childCollection.contains(child3Doc));
    childCollection.clear();
    rootDoc.field("String_Node_Str",childCollection);
    rootDoc.save();
    child3Doc.reload();
    assertNull(child3Doc.field("String_Node_Str"));
    ODocument root2Doc=new ODocument(classA);
    root2Doc.save();
    ODocument childTestForNull=new ODocument(classA);
    childTestForNull.save();
    assertNull(root2Doc.field("String_Node_Str"));
    root2Doc.field("String_Node_Str",Arrays.asList(childTestForNull));
    root2Doc.save();
    childTestForNull.reload();
    childCollection=root2Doc.field("String_Node_Str");
    assertEquals(1,childCollection.size());
    assertTrue(childCollection.contains(childTestForNull));
    assertEquals(root2Doc,childTestForNull.field("String_Node_Str"));
  }
  finally {
    schema.dropClass(TEST_CLASS_A);
    OrientDbWebSession.get().signOut();
  }
}