153-4-9

KeyedObjects ko1 = new KeyedObjects(); ko1.addObject("V1", new Integer(1)); ko1.addObject("V2", null); ko1.addObject("V3", new Integer(3)); KeyedObjects ko2 = null; try { ko2 = (KeyedObjects) ko1.clone(); } catch (CloneNotSupportedException e) { System.err.println("Failed to clone."); } assertTrue(ko1 != ko2); assertTrue(ko1.getClass() == ko2.getClass()); assertTrue(ko1.equals(ko2));
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/KeyedObjectsTests.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: 10 |  | Number of AST nodes: 7

1

    KeyedObjects ko1 = new KeyedObjects();↵

2

            ko1.addObject("V1", new Integer(1));↵

3

            ko1.addObject("V2", null);↵

4

            ko1.addObject("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

            KeyedObjects ko2 = null;↵

4

            ContourEntity e2 = null;↵

5

            ↵

7

            try {↵

6

            try {↵

8

                ko2 = (KeyedObjects) ko1.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(ko1 != ko2);↵

12

            assertTrue(e1 != e2);↵

14

            assertTrue(ko1.getClass() == ko2.getClass());↵

13

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

15

            assertTrue(ko1.equals(ko2));

14

            assertTrue(e1.equals(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 | 44

1. {Non-refactorable}

   Mapping Summary
   Number of mapped statements | 4
   Number of unmapped statements in the first code fragment | 6
   Number of unmapped statements in the second code fragment | 3
   Time elapsed for statement mapping (ms) | 23.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

       KeyedObjects ko1 = new KeyedObjects();

   2

       ContourEntity e2 = null;

   2

       ko1.addObject("V1", new Integer(1));

   3

       ko1.addObject("V2", null);

   4

       ko1.addObject("V3", new Integer(3));

   4 | ko1.addObject("V3", new Integer(3));
   6 | assertTrue(e1.getClass() == e2.getClass());

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   addObject | assertTrue | METHOD_INVOCATION_NAME_MISMATCH
   ko1.addObject("V3",new Integer(3)) | assertTrue(e1.getClass() == e2.getClass()) | ARGUMENT_NUMBER_MISMATCH
   ko1 |  | MISSING_METHOD_INVOCATION_EXPRESSION

   Preondition Violations
   Expression ko1.addObject("V3",new Integer(3)) 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
   Expression ko1.addObject("V3",new Integer(3)) 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());

   5

       KeyedObjects ko2 = 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

       ko2 = (KeyedObjects)ko1.clone();

   7 | ko2 = (KeyedObjects)ko1.clone();

   Preondition Violations
   Unmatched statement ko2=(KeyedObjects)ko1.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(ko1 != ko2);

   8 | assertTrue(ko1 != ko2);
   7 | assertTrue(e1.equals(e2));

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   ko1 != ko2 | e1.equals(e2) | TYPE_COMPATIBLE_REPLACEMENT

   7

       assertTrue(e1.equals(e2));

   9

       assertTrue(ko1.getClass() == ko2.getClass());

   10

       assertTrue(ko1.equals(ko2));

   10 | assertTrue(ko1.equals(ko2));
   5 | assertTrue(e1 != e2);

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   ko1.equals(ko2) | e1 != e2 | TYPE_COMPATIBLE_REPLACEMENT

   Preondition Violations
   Expression ko1.equals(ko2) cannot be parameterized, because it has dependencies to/from statements that will be extracted

   5

       assertTrue(e1 != e2);

   Precondition Violations (7)
   Row | Violation
   --- | ---
   1 | Expression ko1.addObject("V3",new Integer(3)) is a void method call, and thus it cannot be parameterized
   2 | Expression assertTrue(e1.getClass() == e2.getClass()) is a void method call, and thus it cannot be parameterized
   3 | Expression ko1.addObject("V3",new Integer(3)) 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
   5 | 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
   6 | Unmatched statement ko2=(KeyedObjects)ko1.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
   7 | Expression ko1.equals(ko2) cannot be parameterized, because it has dependencies to/from statements that will be extracted