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 statements19
    Number of unmapped statements in the first code fragment15
    Number of unmapped statements in the second code fragment15
    Time elapsed for statement mapping (ms)0.0
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
                                                                                          
    1
    Container container = new Container("p1");
    1
    Parent parent = new Parent("p1");
                                                                        
                                                                                                            
    2
    Container.Content c1 = new Container.Content("c1");
    2
    Child child = new Child("c1");
                                                                  
                                                                          
    3
    container.getContents().add(c1);
    3
    parent.getChildren().put(child.getName(), child);
                                                                                                          
                                                                                                            
    4
    Container.Content c2 = new Container.Content("c2");
    4
    child.setParent(parent);
                                                          
    5
    Child otherChild = new Child("c2");
                                                                            
    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
    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);
    24
    assertTrue(children.retainAll(otherSet));
    Differences
    Expression1Expression2Difference
    old == childchildren.retainAll(otherSet)TYPE_COMPATIBLE_REPLACEMENT
    24
    assertTrue(children.retainAll(otherSet));
    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);
                                                                                          
    16
    assertFalse(children.addAll(otherSet));
                                                                                                
    18
    assertFalse(children.retainAll(otherSet));
    15
    assertNull(old);
    15
    assertNull(old);
    33
    session.getTransaction().commit();
    Differences
    Expression1Expression2Difference
    assertNullcommitMETHOD_INVOCATION_NAME_MISMATCH
    assertNull(old)session.getTransaction().commit()ARGUMENT_NUMBER_MISMATCH
    session.getTransaction()MISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression session.getTransaction().commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertNull(old) is a void method call, and thus it cannot be parameterized
    Expression session.getTransaction().commit() is a void method call, and thus it cannot be parameterized
    Expression session.getTransaction().commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertNull(old) is a void method call, and thus it cannot be parameterized
    Expression session.getTransaction().commit() is a void method call, and thus it cannot be parameterized
    33
    session.getTransaction().commit();
    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
    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
    children.putAll(otherMap);
                                                                
    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();
    23
    assertFalse(children.isDirty());
    Differences
    Expression1Expression2Difference
    clearDirtyassertFalseMETHOD_INVOCATION_NAME_MISMATCH
    children.clearDirty()assertFalse(children.isDirty())ARGUMENT_NUMBER_MISMATCH
    childrenMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression children.clearDirty() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression children.clearDirty() is a void method call, and thus it cannot be parameterized
    Expression assertFalse(children.isDirty()) is a void method call, and thus it cannot be parameterized
    Expression children.clearDirty() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression children.clearDirty() is a void method call, and thus it cannot be parameterized
    Expression assertFalse(children.isDirty()) is a void method call, and thus it cannot be parameterized
    23
    assertFalse(children.isDirty());
    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
    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);
                                                          
    33
    session.getTransaction().commit();
    33
    session.getTransaction().commit();
    26
    assertTrue(children.isEmpty());
    Differences
    Expression1Expression2Difference
    commitassertTrueMETHOD_INVOCATION_NAME_MISMATCH
    session.getTransaction().commit()assertTrue(children.isEmpty())ARGUMENT_NUMBER_MISMATCH
    session.getTransaction()MISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression session.getTransaction().commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression session.getTransaction().commit() is a void method call, and thus it cannot be parameterized
    Expression assertTrue(children.isEmpty()) is a void method call, and thus it cannot be parameterized
    Expression session.getTransaction().commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression session.getTransaction().commit() is a void method call, and thus it cannot be parameterized
    Expression assertTrue(children.isEmpty()) is a void method call, and thus it cannot be parameterized
    26
    assertTrue(children.isEmpty());
    34
    session.close();
    34
    session.close();
    Precondition Violations (24)
    Row Violation
    1Type org.hibernate.test.collection.map.Parent of variable parent does not match with type org.hibernate.test.collection.set.Container of variable container
    2Unmatched 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
    3Expression session.getTransaction().commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    4Expression assertNull(old) is a void method call, and thus it cannot be parameterized
    5Expression session.getTransaction().commit() is a void method call, and thus it cannot be parameterized
    6Expression session.getTransaction().commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7Expression assertNull(old) is a void method call, and thus it cannot be parameterized
    8Expression session.getTransaction().commit() is a void method call, and thus it cannot be parameterized
    9Expression children.clearDirty() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    10Expression children.clearDirty() is a void method call, and thus it cannot be parameterized
    11Expression assertFalse(children.isDirty()) is a void method call, and thus it cannot be parameterized
    12Expression children.clearDirty() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    13Expression children.clearDirty() is a void method call, and thus it cannot be parameterized
    14Expression assertFalse(children.isDirty()) is a void method call, and thus it cannot be parameterized
    15Type org.hibernate.test.collection.map.Child of variable child does not match with type org.hibernate.test.collection.set.Container of variable container
    16Expression children cannot be unified with expression children , because common superclass org.hibernate.collection.AbstractPersistentCollection does not declare member(s) public void clear()
    17Expression children cannot be unified with expression children , because common superclass org.hibernate.collection.AbstractPersistentCollection does not declare member(s) public void clear()
    18Expression session.getTransaction().commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    19Expression session.getTransaction().commit() is a void method call, and thus it cannot be parameterized
    20Expression assertTrue(children.isEmpty()) is a void method call, and thus it cannot be parameterized
    21Expression session.getTransaction().commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    22Expression session.getTransaction().commit() is a void method call, and thus it cannot be parameterized
    23Expression assertTrue(children.isEmpty()) is a void method call, and thus it cannot be parameterized
    24Clone fragment #1 returns variables session , while Clone fragment #2 returns variables