232-1-4

DefaultKeyedValue v1 = new DefaultKeyedValue("Test", new Double(45.5)); DefaultKeyedValue v2 = null; try { v2 = (DefaultKeyedValue) 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(new Double(12.3)); assertFalse(v1.equals(v2));
CombinedDomainCategoryPlot plot1 = createPlot(); CombinedDomainCategoryPlot plot2 = null; try { plot2 = (CombinedDomainCategoryPlot) plot1.clone(); } catch (CloneNotSupportedException e) { System.err.println("Failed to clone."); } assertTrue(plot1 != plot2); assertTrue(plot1.getClass() == plot2.getClass()); assertTrue(plot1.equals(plot2));

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

1

    DefaultKeyedValue v1 = new DefaultKeyedValue("Test", new Double(45.5));↵

2

            DefaultKeyedValue v↵

1

    CombinedDomainCategoryPlot plot1 = createPlot();        ↵

3

    2 = null;↵

2

            CombinedDomainCategoryPlot plot2 = null;↵

4

            try {↵

3

            try {↵

5

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

4

                plot2 = (CombinedDomainCategoryPlot) plot1.clone();↵

6

            }↵

5

            }↵

7

            catch (CloneNotSupportedException e) {↵

6

            catch (CloneNotSupportedException e) {↵

8

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

7

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

9

            }↵

8

            }↵

10

            assertTrue(v1 != v2);↵

9

            assertTrue(plot1 != plot2);↵

11

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

10

            assertTrue(plot1.getClass() == plot2.getClass());↵

12

            assertTrue(v1.equals(v2));↵

11

            assertTrue(plot1.equals(↵

13

            ↵

14

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

15

            v2.setValue(new Double(12.3));↵

16

            assertFalse(v1.equals(v2));

12

    plot2));

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 | 39

1. {Non-refactorable}

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

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

   1

       CombinedDomainCategoryPlot plot1 = createPlot();

   1

       DefaultKeyedValue v1 = new DefaultKeyedValue("Test", new Double(45.5));

   2

       CombinedDomainCategoryPlot plot2 = null;

   2

       DefaultKeyedValue v2 = null;

   3

       try

   3

       try

   4 | plot2 = (CombinedDomainCategoryPlot)plot1.clone();

   Preondition Violations
   Unmatched statement plot2=(CombinedDomainCategoryPlot)plot1.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

       plot2 = (CombinedDomainCategoryPlot)plot1.clone();

   4

       v2 = (DefaultKeyedValue)v1.clone();

   4 | v2 = (DefaultKeyedValue)v1.clone();

   Preondition Violations
   Unmatched statement v2=(DefaultKeyedValue)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

   5

       assertTrue(v1 != v2);

   6

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

   6 | assertTrue(v1.getClass() == v2.getClass());
   7 | assertTrue(plot1.equals(plot2));

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   v1.getClass() == v2.getClass() | plot1.equals(plot2) | TYPE_COMPATIBLE_REPLACEMENT

   7

       assertTrue(plot1.equals(plot2));

   7

       assertTrue(v1.equals(v2));

   7 | assertTrue(v1.equals(v2));
   5 | assertTrue(plot1 != plot2);

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   v1.equals(v2) | plot1 != plot2 | TYPE_COMPATIBLE_REPLACEMENT

   5

       assertTrue(plot1 != plot2);

   8

       v2.setValue(new Double(12.3));

   9

       assertFalse(v1.equals(v2));

   9 | assertFalse(v1.equals(v2));
   6 | assertTrue(plot1.getClass() == plot2.getClass());

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

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

   6

       assertTrue(plot1.getClass() == plot2.getClass());

   Precondition Violations (4)
   Row | Violation
   --- | ---
   1 | Unmatched statement plot2=(CombinedDomainCategoryPlot)plot1.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=(DefaultKeyedValue)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(plot1.getClass() == plot2.getClass()) is a void method call, and thus it cannot be parameterized