153-1-9

DefaultKeyedValues v1 = new DefaultKeyedValues(); v1.addValue("V1", new Integer(1)); v1.addValue("V2", null); v1.addValue("V3", new Integer(3)); DefaultKeyedValues v2 = null; try { v2 = (DefaultKeyedValues) v1.clone(); } catch (CloneNotSupportedException e) { System.err.println("Failed to clone."); } assertTrue(v1 != v2); assertTrue(v1.getClass() == v2.getClass()); assertTrue(v1.equals(v2)); // confirm that the clone is independent of the original v2.setValue("V1", new Integer(44)); assertFalse(v1.equals(v2));
ContourEntity e1 = new ContourEntity( new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), "ToolTip", "URL" ); ContourEntity e2 = null; try { e2 = (ContourEntity) e1.clone(); } catch (CloneNotSupportedException e) { System.err.println("Failed to clone."); } assertTrue(e1 != e2); assertTrue(e1.getClass() == e2.getClass()); assertTrue(e1.equals(e2));

Clone fragments detected by clone detection tool
File path: /jfreechart-1.0.10/tests/org/jfree/data/junit/DefaultKeyedValuesTests.java |  | File path: /jfreechart-1.0.10/tests/org/jfree/chart/entity/junit/ContourEntityTests.java
Method name: `void testCloning()` |  | Method name: `void testCloning()`
Number of AST nodes: 12 |  | Number of AST nodes: 7

1

    DefaultKeyedValues v1 = new DefaultKeyedValues();↵

2

            v1.addValue("V1", new Integer(1));↵

3

            v1.addValue("V2", null);↵

4

            v1.addValue("V3", new Integer(3)↵

1

    ContourEntity e1 = new ContourEntity(↵

2

                new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), "ToolTip", "URL"↵

5

    );↵

3

            ); ↵

6

            DefaultKeyedValues v2 = null;↵

4

            ContourEntity e2 = null;↵

5

            ↵

7

            try {↵

6

            try {↵

8

                v2 = (DefaultKeyedValues) v1.clone();↵

7

                e2 = (ContourEntity) e1.clone();↵

9

            }↵

8

            }↵

10

            catch (CloneNotSupportedException e) {↵

9

            catch (CloneNotSupportedException e) {↵

11

                System.err.println("Failed to clone.");↵

10

                System.err.println("Failed to clone.");↵

12

            }↵

11

            }↵

13

            assertTrue(v1 != v2);↵

12

            assertTrue(e1 != e2);↵

14

            assertTrue(v1.getClass() == v2.getClass());↵

13

            assertTrue(e1.getClass() == e2.getClass());↵

15

            assertTrue(v1.equals(v2));↵

14

            assertTrue(e1.equals(↵

16

            ↵

17

            // confirm that the clone is independent of the original↵

18

            v2.setValue("V1", new Integer(44));↵

19

            assertFalse(v1.equals(v2));

15

    e2));

See real code fragment |  | See real code fragment

Summary
Number of common nesting structure subtrees | 1
Number of refactorable cases | 0
Number of non-refactorable cases | 1
Time elapsed for finding largest common nesting structure subtrees (ms) | 0.2
Clones location | Clones are in different classes having the same super class
Number of node comparisons | 54

1. {Non-refactorable}

   Mapping Summary
   Number of mapped statements | 4
   Number of unmapped statements in the first code fragment | 8
   Number of unmapped statements in the second code fragment | 3
   Time elapsed for statement mapping (ms) | 2.5
   Clone type | Type 3

   Mapped Statements
   ID | Statement |  | ID | Statement
   --- | --- | --- | --- | ---

   1

       ContourEntity e1 = new ContourEntity(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), "ToolTip", "URL");

   1

       DefaultKeyedValues v1 = new DefaultKeyedValues();

   2

       ContourEntity e2 = null;

   2

       v1.addValue("V1", new Integer(1));

   3

       v1.addValue("V2", null);

   4

       v1.addValue("V3", new Integer(3));

   5

       DefaultKeyedValues v2 = null;

   6

       try

   3

       try

   4 | e2 = (ContourEntity)e1.clone();

   Preondition Violations
   Unmatched statement e2=(ContourEntity)e1.clone(); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted

   4

       e2 = (ContourEntity)e1.clone();

   7

       v2 = (DefaultKeyedValues)v1.clone();

   7 | v2 = (DefaultKeyedValues)v1.clone();

   Preondition Violations
   Unmatched statement v2=(DefaultKeyedValues)v1.clone(); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted

   8

       assertTrue(v1 != v2);

   8 | assertTrue(v1 != v2);
   7 | assertTrue(e1.equals(e2));

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   v1 != v2 | e1.equals(e2) | TYPE_COMPATIBLE_REPLACEMENT

   7

       assertTrue(e1.equals(e2));

   9

       assertTrue(v1.getClass() == v2.getClass());

   10

       assertTrue(v1.equals(v2));

   10 | assertTrue(v1.equals(v2));
   5 | assertTrue(e1 != e2);

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   v1.equals(v2) | e1 != e2 | TYPE_COMPATIBLE_REPLACEMENT

   5

       assertTrue(e1 != e2);

   11

       v2.setValue("V1", new Integer(44));

   12

       assertFalse(v1.equals(v2));

   12 | assertFalse(v1.equals(v2));
   6 | assertTrue(e1.getClass() == e2.getClass());

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   assertFalse | assertTrue | METHOD_INVOCATION_NAME_MISMATCH
   v1.equals(v2) | e1.getClass() == e2.getClass() | TYPE_COMPATIBLE_REPLACEMENT

   Preondition Violations
   Expression assertFalse(v1.equals(v2)) is a void method call, and thus it cannot be parameterized
   Expression assertTrue(e1.getClass() == e2.getClass()) is a void method call, and thus it cannot be parameterized

   6

       assertTrue(e1.getClass() == e2.getClass());

   Precondition Violations (4)
   Row | Violation
   --- | ---
   1 | Unmatched statement e2=(ContourEntity)e1.clone(); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
   2 | Unmatched statement v2=(DefaultKeyedValues)v1.clone(); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
   3 | Expression assertFalse(v1.equals(v2)) is a void method call, and thus it cannot be parameterized
   4 | Expression assertTrue(e1.getClass() == e2.getClass()) is a void method call, and thus it cannot be parameterized