153-4-8

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));
XYPointerAnnotation a1 = new XYPointerAnnotation("Label", 10.0, 20.0, Math.PI); XYPointerAnnotation a2 = null; try { a2 = (XYPointerAnnotation) a1.clone(); } catch (CloneNotSupportedException e) { System.err.println("Failed to clone."); } assertTrue(a1 != a2); assertTrue(a1.getClass() == a2.getClass()); assertTrue(a1.equals(a2));

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/annotations/junit/XYPointerAnnotationTests.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));↵

5

            KeyedObjects ko↵

1

    XYPointerAnnotation a1 = new XYPointerAnnotation("Label", 10.0, 20.0,↵

2

                    Math.PI);↵

6

    2 = null;↵

3

            XYPointerAnnotation a2 = null;↵

7

            try {↵

4

            try {↵

8

                ko2 = (KeyedObjects) ko1.clone();↵

5

                a2 = (XYPointerAnnotation) a1.clone();↵

9

            }↵

6

            }↵

10

            catch (CloneNotSupportedException e) {↵

7

            catch (CloneNotSupportedException e) {↵

11

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

8

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

12

            }↵

9

            }↵

13

            assertTrue(ko1 != ko2);↵

10

            assertTrue(a1 != a2);↵

14

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

11

            assertTrue(a1.getClass() == a2.getClass());↵

15

            assertTrue(ko1.equals(ko2));

12

            assertTrue(a1.equals(a2));

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

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) | 40.2
   Clone type | Type 3

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

   1

       XYPointerAnnotation a1 = new XYPointerAnnotation("Label", 10.0, 20.0, Math.PI);

   1

       KeyedObjects ko1 = new KeyedObjects();

   2

       XYPointerAnnotation a2 = null;

   2

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

   3

       ko1.addObject("V2", null);

   3 | ko1.addObject("V2", null);
   5 | assertTrue(a1 != a2);

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   addObject | assertTrue | METHOD_INVOCATION_NAME_MISMATCH
   ko1.addObject("V2",null) | assertTrue(a1 != a2) | ARGUMENT_NUMBER_MISMATCH
   ko1 |  | MISSING_METHOD_INVOCATION_EXPRESSION

   Preondition Violations
   Expression ko1.addObject("V2",null) is a void method call, and thus it cannot be parameterized
   Expression assertTrue(a1 != a2) is a void method call, and thus it cannot be parameterized
   Expression ko1.addObject("V2",null) is a void method call, and thus it cannot be parameterized
   Expression assertTrue(a1 != a2) is a void method call, and thus it cannot be parameterized

   5

       assertTrue(a1 != a2);

   4

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

   4 | ko1.addObject("V3", new Integer(3));
   7 | assertTrue(a1.equals(a2));

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   addObject | assertTrue | METHOD_INVOCATION_NAME_MISMATCH
   ko1.addObject("V3",new Integer(3)) | assertTrue(a1.equals(a2)) | ARGUMENT_NUMBER_MISMATCH
   ko1 |  | MISSING_METHOD_INVOCATION_EXPRESSION

   Preondition Violations
   Expression ko1.addObject("V3",new Integer(3)) cannot be parameterized, because it has dependencies to/from statements that will be extracted
   Expression ko1.addObject("V3",new Integer(3)) is a void method call, and thus it cannot be parameterized
   Expression assertTrue(a1.equals(a2)) is a void method call, and thus it cannot be parameterized
   Expression ko1.addObject("V3",new Integer(3)) cannot be parameterized, because it has dependencies to/from statements that will be extracted
   Expression ko1.addObject("V3",new Integer(3)) is a void method call, and thus it cannot be parameterized
   Expression assertTrue(a1.equals(a2)) is a void method call, and thus it cannot be parameterized

   7

       assertTrue(a1.equals(a2));

   5

       KeyedObjects ko2 = null;

   6

       try

   3

       try

   4 | a2 = (XYPointerAnnotation)a1.clone();

   Preondition Violations
   Unmatched statement a2=(XYPointerAnnotation)a1.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

       a2 = (XYPointerAnnotation)a1.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);

   9

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

   10

       assertTrue(ko1.equals(ko2));

   10 | assertTrue(ko1.equals(ko2));
   6 | assertTrue(a1.getClass() == a2.getClass());

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   ko1.equals(ko2) | a1.getClass() == a2.getClass() | TYPE_COMPATIBLE_REPLACEMENT

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

   6

       assertTrue(a1.getClass() == a2.getClass());

   Precondition Violations (13)
   Row | Violation
   --- | ---
   1 | Expression ko1.addObject("V2",null) is a void method call, and thus it cannot be parameterized
   2 | Expression assertTrue(a1 != a2) is a void method call, and thus it cannot be parameterized
   3 | Expression ko1.addObject("V2",null) is a void method call, and thus it cannot be parameterized
   4 | Expression assertTrue(a1 != a2) is a void method call, and thus it cannot be parameterized
   5 | Expression ko1.addObject("V3",new Integer(3)) cannot be parameterized, because it has dependencies to/from statements that will be extracted
   6 | Expression ko1.addObject("V3",new Integer(3)) is a void method call, and thus it cannot be parameterized
   7 | Expression assertTrue(a1.equals(a2)) is a void method call, and thus it cannot be parameterized
   8 | Expression ko1.addObject("V3",new Integer(3)) cannot be parameterized, because it has dependencies to/from statements that will be extracted
   9 | Expression ko1.addObject("V3",new Integer(3)) is a void method call, and thus it cannot be parameterized
   10 | Expression assertTrue(a1.equals(a2)) is a void method call, and thus it cannot be parameterized
   11 | Unmatched statement a2=(XYPointerAnnotation)a1.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
   12 | 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
   13 | Expression ko1.equals(ko2) cannot be parameterized, because it has dependencies to/from statements that will be extracted