Parent parent = new Parent( "p1" ); Child child = new Child( "c1" ); parent.getChildren().put( child.getName(), child ); child.setParent( parent ); Child otherChild = new Child( "c2" ); Session session = openSession(); session.beginTransaction(); session.save( parent ); session.flush(); // at this point, the set on parent has now been replaced with a PersistentSet... PersistentMap children = ( PersistentMap ) parent.getChildren(); Object old = children.put( child.getName(), child ); assertTrue( old == child ); assertFalse( children.isDirty() ); old = children.remove( otherChild.getName() ); assertNull( old ); assertFalse( children.isDirty() ); HashMap otherMap = new HashMap(); otherMap.put( child.getName(), child ); children.putAll( otherMap ); assertFalse( children.isDirty() ); otherMap = new HashMap(); otherMap.put( otherChild.getName(), otherChild ); children.putAll( otherMap ); assertTrue( children.isDirty() ); children.clearDirty(); session.delete( child ); children.clear(); assertTrue( children.isDirty() ); session.flush(); children.clear(); assertFalse( children.isDirty() ); session.delete( parent ); session.getTransaction().commit(); session.close();
Container container = new Container( "p1" ); Container.Content c1 = new Container.Content( "c1" ); container.getContents().add( c1 ); Container.Content c2 = new Container.Content( "c2" ); Session session = openSession(); session.beginTransaction(); session.save( container ); session.flush(); // at this point, the set on container has now been replaced with a PersistentSet... PersistentSet children = ( PersistentSet ) container.getContents(); assertFalse( children.add( c1 ) ); assertFalse( children.isDirty() ); assertFalse( children.remove( c2 ) ); assertFalse( children.isDirty() ); HashSet otherSet = new HashSet(); otherSet.add( c1 ); assertFalse( children.addAll( otherSet ) ); assertFalse( children.isDirty() ); assertFalse( children.retainAll( otherSet ) ); assertFalse( children.isDirty() ); otherSet = new HashSet(); otherSet.add( c2 ); assertFalse( children.removeAll( otherSet ) ); assertFalse( children.isDirty() ); assertTrue( children.retainAll( otherSet )); assertTrue( children.isDirty() ); assertTrue( children.isEmpty() ); children.clear(); assertTrue( children.isDirty() ); session.flush(); children.clear(); assertFalse( children.isDirty() ); session.delete( container ); session.getTransaction().commit(); session.close();
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/collection/map/PersistentMapTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/collection/set/PersistentSetTest.java
Method name: void testWriteMethodDirtying() Method name: void testCompositeElementWriteMethodDirtying()
Number of AST nodes: 34 Number of AST nodes: 34
1
Parent parent = new Parent( "p1" );
2
		Child child = new Child( "c1" );
3
		parent.getChildren().put( child.getName(), child );
4
		child.setParent( parent );
5
		Child otherChild = new Child
1
Container container = new Container( "p1" );
2
		Container.Content c1 = new Container.Content( "c1" );
3
		container.getContents().add( c1 );
6
( "c2" );
4
		Container.Content c2 = new Container.Content( "c2" );
7
		Session session = openSession();
5
		Session session = openSession();
8
		session.beginTransaction();
6
		session.beginTransaction();
9
		session.save( parent );
7
		session.save( container );
10
		session.flush();
8
		session.flush();
11
		// at this point, the set on parent has now been replaced with a PersistentSet...
9
		// at this point, the set on container has now been replaced with a PersistentSet...
12
		PersistentMap children = ( PersistentMap ) parent.getChildren();
10
		PersistentSet children = ( Persistent
13
		Object old = children.put( child.getName(), child );
14
		assertTrue( old == child
11
Set ) container.getContents();
15
 );
12
		assertFalse( children.add( c1 ) );
16
		assertFalse( children.isDirty() );
13
		assertFalse( children.isDirty() );
17
		old = children.remove( otherChild.getName() );
14
		assertFalse( children.remove( 
18
		assertNull( old );
15
c2 ) );
19
		assertFalse( children.isDirty() );
16
		assertFalse( children.isDirty() );
20
		HashMap otherMap = new HashMap();
17
		HashSet otherSet = new HashSet();
21
		otherMap.put( child.getName(), child
18
		otherSet.add( c1 );
19
		assertFalse( children.addAll( otherSet ) );
22
 );
20
		assertFalse( children.isDirty() );
23
		children.putAll( otherMap );
21
		assertFalse( children.retainAll( otherSet ) );
24
		assertFalse( children.isDirty() );
22
		assertFalse( children.isDirty() );
25
		otherMap = new HashMap();
23
		otherSet = new HashSet();
26
		otherMap.put( otherChild.getName(), otherChild );
24
		other
27
		
25
Set.add( c2 );
28
children.putAll( otherMap );
26
		assertFalse( children.removeAll( otherSet ) );
29
		assertTrue( children.isDirty() );
27
		assertFalse( children.isDirty() );
30
		children.clear
28
		assertTrue( children.retainAll( otherSet ));
31
Dirty();
29
		assertTrue( children.isDirty() );
32
		session.delete( child );
30
		assertTrue( children.isEmpty() );
33
		children.clear();
31
		children.clear();
34
		assertTrue( children.isDirty() );
32
		assertTrue( children.isDirty() );
35
		session.flush();
33
		session.flush();
36
		children.clear();
34
		children.clear();
37
		assertFalse( children.isDirty() );
35
		assertFalse( children.isDirty() );
38
		session.delete( parent );
36
		session.delete( container );
39
		session.getTransaction().commit();
37
		session.getTransaction().commit();
40
		session.close();
38
		session.close();
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.0
Clones locationClones are in different classes having the same super class
Number of node comparisons612
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements17
    Number of unmapped statements in the first code fragment17
    Number of unmapped statements in the second code fragment17
    Time elapsed for statement mapping (ms)0.0
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
                                                                                          
    1
    Container container = new Container("p1");
    Preondition Violations
    Unmatched statement Container container=new Container("p1"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    1
    Container container = new Container("p1");
    1
    Parent parent = new Parent("p1");
    1
    Parent parent = new Parent("p1");
    Preondition Violations
    Unmatched statement Parent parent=new Parent("p1"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                                        
                                                                                                            
    2
    Container.Content c1 = new Container.Content("c1");
    Preondition Violations
    Unmatched statement Container.Content c1=new Container.Content("c1"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    2
    Container.Content c1 = new Container.Content("c1");
    2
    Child child = new Child("c1");
    2
    Child child = new Child("c1");
    Preondition Violations
    Unmatched statement Child child=new Child("c1"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                                  
                                                                          
    3
    container.getContents().add(c1);
    3
    parent.getChildren().put(child.getName(), child);
                                                                                                          
                                                                                                            
    4
    Container.Content c2 = new Container.Content("c2");
    Preondition Violations
    Unmatched statement Container.Content c2=new Container.Content("c2"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    4
    Container.Content c2 = new Container.Content("c2");
    4
    child.setParent(parent);
    4
    child.setParent(parent);
    Preondition Violations
    Unmatched statement child.setParent(parent); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                          
    5
    Child otherChild = new Child("c2");
    5
    Child otherChild = new Child("c2");
    Preondition Violations
    Unmatched statement Child otherChild=new Child("c2"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                                            
    6
    Session session = openSession();
    5
    Session session = openSession();
    7
    session.beginTransaction();
    6
    session.beginTransaction();
    8
    session.save(parent);
    8
    session.save(parent);
    7
    session.save(container);
    Differences
    Expression1Expression2Difference
    parentcontainerVARIABLE_NAME_MISMATCH
    org.hibernate.test.collection.map.Parentorg.hibernate.test.collection.set.ContainerVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Expression parent cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression container cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Type org.hibernate.test.collection.map.Parent of variable parent does not match with type org.hibernate.test.collection.set.Container of variable container
    • Make classes org.hibernate.test.collection.map.Parent and org.hibernate.test.collection.set.Container extend a common superclass
    7
    session.save(container);
    9
    session.flush();
    8
    session.flush();
                                                                                                                                      
    9
    PersistentSet children = (PersistentSet)container.getContents();
                                                                        
    10
    assertFalse(children.add(c1));
    10
    PersistentMap children = (PersistentMap)parent.getChildren();
                                                                                                                                  
                                                                            
    11
    assertFalse(children.isDirty());
    11
    Object old = children.put(child.getName(), child);
                                                                                                          
                                                                              
    12
    assertFalse(children.remove(c2));
    12
    assertTrue(old == child);
    12
    assertTrue(old == child);
    26
    assertTrue(children.isEmpty());
    Differences
    Expression1Expression2Difference
    old == childchildren.isEmpty()TYPE_COMPATIBLE_REPLACEMENT
    Preondition Violations
    Expression old == child cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression children.isEmpty() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    26
    assertTrue(children.isEmpty());
    13
    assertFalse(children.isDirty());
    13
    assertFalse(children.isDirty());
    13
    assertFalse(children.isDirty());
    Differences
    Expression1Expression2Difference
    org.hibernate.collection.PersistentMaporg.hibernate.collection.PersistentSetSUBCLASS_TYPE_MISMATCH
    13
    assertFalse(children.isDirty());
                                                                          
    14
    HashSet otherSet = new HashSet();
    14
    old = children.remove(otherChild.getName());
    14
    old = children.remove(otherChild.getName());
    Preondition Violations
    Unmatched statement old=children.remove(otherChild.getName()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                
                                              
    15
    otherSet.add(c1);
    15
    assertNull(old);
                                            
                                                                                          
    16
    assertFalse(children.addAll(otherSet));
    16
    assertFalse(children.isDirty());
    16
    assertFalse(children.isDirty());
    17
    assertFalse(children.isDirty());
    Differences
    Expression1Expression2Difference
    org.hibernate.collection.PersistentMaporg.hibernate.collection.PersistentSetSUBCLASS_TYPE_MISMATCH
    17
    assertFalse(children.isDirty());
    17
    HashMap otherMap = new HashMap();
                                                                          
                                                                                                
    18
    assertFalse(children.retainAll(otherSet));
    18
    otherMap.put(child.getName(), child);
                                                                                    
    19
    children.putAll(otherMap);
                                                                
    20
    assertFalse(children.isDirty());
    20
    assertFalse(children.isDirty());
    19
    assertFalse(children.isDirty());
    Differences
    Expression1Expression2Difference
    org.hibernate.collection.PersistentMaporg.hibernate.collection.PersistentSetSUBCLASS_TYPE_MISMATCH
    19
    assertFalse(children.isDirty());
                                                          
    20
    otherSet = new HashSet();
                                              
    21
    otherSet.add(c2);
    21
    otherMap = new HashMap();
                                                          
                                                                                                
    22
    assertFalse(children.removeAll(otherSet));
    22
    otherMap.put(otherChild.getName(), otherChild);
                                                                                                        
                                                                            
    23
    assertFalse(children.isDirty());
    23
    children.putAll(otherMap);
                                                                
                                                                                              
    24
    assertTrue(children.retainAll(otherSet));
    24
    assertTrue(children.isDirty());
    24
    assertTrue(children.isDirty());
    25
    assertTrue(children.isDirty());
    Differences
    Expression1Expression2Difference
    org.hibernate.collection.PersistentMaporg.hibernate.collection.PersistentSetSUBCLASS_TYPE_MISMATCH
    25
    assertTrue(children.isDirty());
    25
    children.clearDirty();
    25
    children.clearDirty();
    Preondition Violations
    Unmatched statement children.clearDirty(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                        
    26
    session.delete(child);
    26
    session.delete(child);
    32
    session.delete(container);
    Differences
    Expression1Expression2Difference
    childcontainerVARIABLE_NAME_MISMATCH
    org.hibernate.test.collection.map.Childorg.hibernate.test.collection.set.ContainerVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Expression child cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression container cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Type org.hibernate.test.collection.map.Child of variable child does not match with type org.hibernate.test.collection.set.Container of variable container
    • Make classes org.hibernate.test.collection.map.Child and org.hibernate.test.collection.set.Container extend a common superclass
    32
    session.delete(container);
    27
    children.clear();
    27
    children.clear();
    27
    children.clear();
    Differences
    Expression1Expression2Difference
    org.hibernate.collection.PersistentMaporg.hibernate.collection.PersistentSetSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression children cannot be unified with expression children , because common superclass org.hibernate.collection.AbstractPersistentCollection does not declare member(s) public void clear()
    27
    children.clear();
    28
    assertTrue(children.isDirty());
    28
    assertTrue(children.isDirty());
    28
    assertTrue(children.isDirty());
    Differences
    Expression1Expression2Difference
    org.hibernate.collection.PersistentMaporg.hibernate.collection.PersistentSetSUBCLASS_TYPE_MISMATCH
    28
    assertTrue(children.isDirty());
    29
    session.flush();
    29
    session.flush();
    30
    children.clear();
    30
    children.clear();
    30
    children.clear();
    Differences
    Expression1Expression2Difference
    org.hibernate.collection.PersistentMaporg.hibernate.collection.PersistentSetSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression children cannot be unified with expression children , because common superclass org.hibernate.collection.AbstractPersistentCollection does not declare member(s) public void clear()
    30
    children.clear();
    31
    assertFalse(children.isDirty());
    31
    assertFalse(children.isDirty());
    31
    assertFalse(children.isDirty());
    Differences
    Expression1Expression2Difference
    org.hibernate.collection.PersistentMaporg.hibernate.collection.PersistentSetSUBCLASS_TYPE_MISMATCH
    31
    assertFalse(children.isDirty());
    32
    session.delete(parent);
    32
    session.delete(parent);
    Preondition Violations
    Unmatched statement session.delete(parent); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                          
    33
    session.getTransaction().commit();
    33
    session.getTransaction().commit();
    34
    session.close();
    34
    session.close();
    Precondition Violations (21)
    Row Violation
    1Unmatched statement Container container=new Container("p1"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    2Unmatched statement Parent parent=new Parent("p1"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    3Unmatched statement Container.Content c1=new Container.Content("c1"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    4Unmatched statement Child child=new Child("c1"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    5Unmatched statement Container.Content c2=new Container.Content("c2"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    6Unmatched statement child.setParent(parent); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    7Unmatched statement Child otherChild=new Child("c2"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    8Expression parent cannot be parameterized, because it has dependencies to/from statements that will be extracted
    9Expression container cannot be parameterized, because it has dependencies to/from statements that will be extracted
    10Type org.hibernate.test.collection.map.Parent of variable parent does not match with type org.hibernate.test.collection.set.Container of variable container
    11Expression old == child cannot be parameterized, because it has dependencies to/from statements that will be extracted
    12Expression children.isEmpty() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    13Unmatched statement old=children.remove(otherChild.getName()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    14Unmatched statement children.clearDirty(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    15Expression child cannot be parameterized, because it has dependencies to/from statements that will be extracted
    16Expression container cannot be parameterized, because it has dependencies to/from statements that will be extracted
    17Type org.hibernate.test.collection.map.Child of variable child does not match with type org.hibernate.test.collection.set.Container of variable container
    18Expression children cannot be unified with expression children , because common superclass org.hibernate.collection.AbstractPersistentCollection does not declare member(s) public void clear()
    19Expression children cannot be unified with expression children , because common superclass org.hibernate.collection.AbstractPersistentCollection does not declare member(s) public void clear()
    20Unmatched statement session.delete(parent); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    21Clone fragment #1 returns variables session , while Clone fragment #2 returns variables