CollectionListeners listeners = new CollectionListeners( getSessions() ); ParentWithCollection parent = createParentWithNullChildren( "parent" ); listeners.clear(); assertNull( parent.getChildren() ); Session s = openSession(); Transaction tx = s.beginTransaction(); parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() ); assertNotNull( parent.getChildren() ); Child newChild = parent.addChild( "new" ); tx.commit(); s.close(); int index = 0; if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) { checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ ); } checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ ); checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ ); if ( newChild instanceof ChildWithBidirectionalManyToMany ) { checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ ); checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ ); } checkNumberOfResults( listeners, index );
CollectionListeners listeners = new CollectionListeners( getSessions() ); ParentWithCollection parent = createParentWithNoChildren( "parent" ); listeners.clear(); assertEquals( 0, parent.getChildren().size() ); Session s = openSession(); Transaction tx = s.beginTransaction(); parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() ); Collection oldCollection = parent.getChildren(); parent.newChildren( null ); tx.commit(); s.close(); int index = 0; if ( ( ( PersistentCollection ) oldCollection ).wasInitialized() ) { checkResult( listeners, listeners.getInitializeCollectionListener(), parent, oldCollection, index++ ); } checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ ); checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++ ); // pre- and post- collection recreate events should be created when updating an entity with a "null" collection checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ ); checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ ); checkNumberOfResults( listeners, index );
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/event/collection/AbstractCollectionEventTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/event/collection/BrokenCollectionEventTest.java
Method name: void testUpdateParentNullToOneChild() Method name: void testUpdateParentNoChildrenToNullFailureExpected()
Number of AST nodes: 20 Number of AST nodes: 19
1
CollectionListeners listeners = new CollectionListeners( getSessions() );
1
CollectionListeners listeners = new CollectionListeners( getSessions() );
2
		ParentWithCollection parent = createParentWithNullChildren( "parent" );
2
		ParentWithCollection parent = createParentWithNoChildren( "parent" );
3
		listeners.clear();
3
		listeners.clear();
4
		assertNull( parent.getChildren() );
4
		assertEquals( 0, parent.getChildren().size() );
5
		Session s = openSession();
5
		Session s = openSession();
6
		Transaction tx = s.beginTransaction();
6
		Transaction tx = s.beginTransaction();
7
		parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
7
		parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
8
		assertNotNull( parent.getChildren() );
8
		Collection oldCollection = parent.getChildren();
9
		Child newChild = parent.addChild( "new" );
9
		parent.newChildren( null );
10
		tx.commit();
10
		tx.commit();
11
		s.close();
11
		s.close();
12
		int index = 0;
12
		int index = 0;
13
		if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) {
13
		if ( ( ( PersistentCollection ) oldCollection ).wasInitialized() ) {
14
			checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );
14
			checkResult( listeners, listeners.getInitializeCollectionListener(), parent, oldCollection, index++ );
15
		}
15
		}
16
		checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );
16
		checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ );
17
		checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );
17
		checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, 
18
		if ( newChild instanceof ChildWithBidirectionalManyToMany ) {
19
	
18
oldCollection, index++ );
19
		// pre- and post- collection recreate events should be created when updating an entity with a "null" collection
20
		checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
20
		checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
21
			checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
21
		checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ );
22
		}
22
		
23
		checkNumberOfResults( listeners, index );
23
checkNumberOfResults( listeners, index );
Summary
Number of common nesting structure subtrees1
Number of refactorable cases0
Number of non-refactorable cases1
Time elapsed for finding largest common nesting structure subtrees (ms)0.4
Clones locationClones are in different classes having the same super class
Number of node comparisons186
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements15
    Number of unmapped statements in the first code fragment2
    Number of unmapped statements in the second code fragment4
    Time elapsed for statement mapping (ms)172.6
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    1
    CollectionListeners listeners = new CollectionListeners(getSessions());
    1
    CollectionListeners listeners = new CollectionListeners(getSessions());
    2
    ParentWithCollection parent = createParentWithNullChildren("parent");
    2
    ParentWithCollection parent = createParentWithNullChildren("parent");
    2
    ParentWithCollection parent = createParentWithNoChildren("parent");
    Differences
    Expression1Expression2Difference
    createParentWithNullChildrencreateParentWithNoChildrenMETHOD_INVOCATION_NAME_MISMATCH
    2
    ParentWithCollection parent = createParentWithNoChildren("parent");
    3
    listeners.clear();
    3
    listeners.clear();
    4
    assertNull(parent.getChildren());
    4
    assertNull(parent.getChildren());
    4
    assertEquals(0, parent.getChildren().size());
    Differences
    Expression1Expression2Difference
    assertNullassertEqualsMETHOD_INVOCATION_NAME_MISMATCH
    assertNull(parent.getChildren())assertEquals(0,parent.getChildren().size())ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression assertNull(parent.getChildren()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals(0,parent.getChildren().size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertNull(parent.getChildren()) is a void method call, and thus it cannot be parameterized
    Expression assertEquals(0,parent.getChildren().size()) is a void method call, and thus it cannot be parameterized
    Expression assertNull(parent.getChildren()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals(0,parent.getChildren().size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertNull(parent.getChildren()) is a void method call, and thus it cannot be parameterized
    Expression assertEquals(0,parent.getChildren().size()) is a void method call, and thus it cannot be parameterized
    4
    assertEquals(0, parent.getChildren().size());
    5
    Session s = openSession();
    5
    Session s = openSession();
    6
    Transaction tx = s.beginTransaction();
    6
    Transaction tx = s.beginTransaction();
    7
    parent = (ParentWithCollection)s.get(parent.getClass(), parent.getId());
    7
    parent = (ParentWithCollection)s.get(parent.getClass(), parent.getId());
                                                                                                      
    8
    Collection oldCollection = parent.getChildren();
    Preondition Violations
    Unmatched statement Collection oldCollection=parent.getChildren(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    8
    Collection oldCollection = parent.getChildren();
    8
    assertNotNull(parent.getChildren());
    8
    assertNotNull(parent.getChildren());
    Preondition Violations
    Unmatched statement assertNotNull(parent.getChildren()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                  
                                                            
    9
    parent.newChildren(null);
    Preondition Violations
    Unmatched statement parent.newChildren(null); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    9
    parent.newChildren(null);
    9
    Child newChild = parent.addChild("new");
    9
    Child newChild = parent.addChild("new");
    Preondition Violations
    Unmatched statement Child newChild=parent.addChild("new"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                      
    10
    tx.commit();
    10
    tx.commit();
    11
    s.close();
    11
    s.close();
    12
    int index = 0;
    12
    int index = 0;
    13
    if (((PersistentCollection)parent.getChildren()).wasInitialized())
    13
    if (((PersistentCollection)parent.getChildren()).wasInitialized())
    13
    if (((PersistentCollection)oldCollection).wasInitialized())
    Differences
    Expression1Expression2Difference
    parent.getChildren()oldCollectionTYPE_COMPATIBLE_REPLACEMENT
    Preondition Violations
    Expression parent.getChildren() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression oldCollection cannot be parameterized, because it has dependencies to/from statements that will be extracted
    13
    if (((PersistentCollection)oldCollection).wasInitialized())
    14
    checkResult(listeners, listeners.getInitializeCollectionListener(), parent, index++);
    14
    checkResult(listeners, listeners.getInitializeCollectionListener(), parent, index++);
    14
    checkResult(listeners, listeners.getInitializeCollectionListener(), parent, oldCollection, index++);
    Differences
    Expression1Expression2Difference
    checkResult(listeners,listeners.getInitializeCollectionListener(),parent,index++)checkResult(listeners,listeners.getInitializeCollectionListener(),parent,oldCollection,index++)ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression checkResult(listeners,listeners.getInitializeCollectionListener(),parent,index++) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression checkResult(listeners,listeners.getInitializeCollectionListener(),parent,oldCollection,index++) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression checkResult(listeners,listeners.getInitializeCollectionListener(),parent,index++) is a void method call, and thus it cannot be parameterized
    Expression checkResult(listeners,listeners.getInitializeCollectionListener(),parent,oldCollection,index++) is a void method call, and thus it cannot be parameterized
    14
    checkResult(listeners, listeners.getInitializeCollectionListener(), parent, oldCollection, index++);
                                                                                                                                                                                                          
    15
    checkResult(listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++);
    Preondition Violations
    Unmatched statement checkResult(listeners,listeners.getPreCollectionRemoveListener(),parent,oldCollection,index++); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    15
    checkResult(listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++);
                                                                                                                                                                                                            
    16
    checkResult(listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++);
    Preondition Violations
    Unmatched statement checkResult(listeners,listeners.getPostCollectionRemoveListener(),parent,oldCollection,index++); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    16
    checkResult(listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++);
    15
    checkResult(listeners, listeners.getPreCollectionUpdateListener(), parent, index++);
    15
    checkResult(listeners, listeners.getPreCollectionUpdateListener(), parent, index++);
    17
    checkResult(listeners, listeners.getPreCollectionRecreateListener(), parent, index++);
    Differences
    Expression1Expression2Difference
    getPreCollectionUpdateListenergetPreCollectionRecreateListenerMETHOD_INVOCATION_NAME_MISMATCH
    Preondition Violations
    Expression listeners.getPreCollectionUpdateListener() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression listeners.getPreCollectionRecreateListener() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    17
    checkResult(listeners, listeners.getPreCollectionRecreateListener(), parent, index++);
    16
    checkResult(listeners, listeners.getPostCollectionUpdateListener(), parent, index++);
    16
    checkResult(listeners, listeners.getPostCollectionUpdateListener(), parent, index++);
    18
    checkResult(listeners, listeners.getPostCollectionRecreateListener(), parent, index++);
    Differences
    Expression1Expression2Difference
    getPostCollectionUpdateListenergetPostCollectionRecreateListenerMETHOD_INVOCATION_NAME_MISMATCH
    Preondition Violations
    Expression listeners.getPostCollectionUpdateListener() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression listeners.getPostCollectionRecreateListener() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    18
    checkResult(listeners, listeners.getPostCollectionRecreateListener(), parent, index++);
    20
    checkNumberOfResults(listeners, index);
    19
    checkNumberOfResults(listeners, index);
    Precondition Violations (25)
    Row Violation
    1Expression assertNull(parent.getChildren()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    2Expression assertEquals(0,parent.getChildren().size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3Expression assertNull(parent.getChildren()) is a void method call, and thus it cannot be parameterized
    4Expression assertEquals(0,parent.getChildren().size()) is a void method call, and thus it cannot be parameterized
    5Expression assertNull(parent.getChildren()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    6Expression assertEquals(0,parent.getChildren().size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7Expression assertNull(parent.getChildren()) is a void method call, and thus it cannot be parameterized
    8Expression assertEquals(0,parent.getChildren().size()) is a void method call, and thus it cannot be parameterized
    9Unmatched statement Collection oldCollection=parent.getChildren(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    10Unmatched statement assertNotNull(parent.getChildren()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    11Unmatched statement parent.newChildren(null); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    12Unmatched statement Child newChild=parent.addChild("new"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    13Expression parent.getChildren() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    14Expression oldCollection cannot be parameterized, because it has dependencies to/from statements that will be extracted
    15Expression checkResult(listeners,listeners.getInitializeCollectionListener(),parent,index++) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    16Expression checkResult(listeners,listeners.getInitializeCollectionListener(),parent,oldCollection,index++) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    17Expression checkResult(listeners,listeners.getInitializeCollectionListener(),parent,index++) is a void method call, and thus it cannot be parameterized
    18Expression checkResult(listeners,listeners.getInitializeCollectionListener(),parent,oldCollection,index++) is a void method call, and thus it cannot be parameterized
    19Unmatched statement checkResult(listeners,listeners.getPreCollectionRemoveListener(),parent,oldCollection,index++); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    20Unmatched statement checkResult(listeners,listeners.getPostCollectionRemoveListener(),parent,oldCollection,index++); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    21Expression listeners.getPreCollectionUpdateListener() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    22Expression listeners.getPreCollectionRecreateListener() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    23Expression listeners.getPostCollectionUpdateListener() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    24Expression listeners.getPostCollectionRecreateListener() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    25Clone fragment #1 returns variables parent, listeners, index , while Clone fragment #2 returns variables parent, listeners, index