39-2-7

DialCap c1 = new DialCap(); DialCap c2 = null; try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(c1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); c2 = (DialCap) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(c1, c2); // test a custom instance c1 = new DialCap(); c1.setFillPaint(new GradientPaint(1.0f, 2.0f, Color.blue, 3.0f, 4.0f, Color.green)); c1.setOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.white, 3.0f, 4.0f, Color.gray)); c1.setOutlineStroke(new BasicStroke(2.0f)); c2 = null; try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(c1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); c2 = (DialCap) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(c1, c2);
DefaultIntervalXYDataset d1 = new DefaultIntervalXYDataset(); DefaultIntervalXYDataset d2 = null; try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(d1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); d2 = (DefaultIntervalXYDataset) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(d1, d2); // try a dataset with some content... d1 = createSampleDataset1(); try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(d1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); d2 = (DefaultIntervalXYDataset) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(d1, d2);

Clone fragments detected by clone detection tool
File path: /jfreechart-1.0.10/tests/org/jfree/chart/plot/dial/junit/DialCapTests.java |  | File path: /jfreechart-1.0.10/tests/org/jfree/data/xy/junit/DefaultIntervalXYDatasetTests.java
Method name: `void testSerialization()` |  | Method name: `void testSerialization()`
Number of AST nodes: 25 |  | Number of AST nodes: 21

1

    DialCap c1 = new DialCap();↵

1

    D↵

2

            DialCap c↵

2

    efaultIntervalXYDataset d1 = new DefaultIntervalXYDataset();↵

3

    2 = null;↵

3

            DefaultIntervalXYDataset d2 = null;↵

4

            try {↵

4

            try {↵

5

                ByteArrayOutputStream buffer = new ByteArrayOutputStream();↵

5

                ByteArrayOutputStream buffer = new ByteArrayOutputStream();↵

6

                ObjectOutput out = new ObjectOutputStream(buffer);↵

6

                ObjectOutput out = new ObjectOutputStream(buffer);↵

7

                out.writeObject(c1);↵

7

                out.writeObject(d1);↵

8

                out.close();↵

8

                out.close();↵

9

                ObjectInput in = new ObjectInputStream(↵

9

                ObjectInput in = new ObjectInputStream(↵

10

                        new ByteArrayInputStream(buffer.toByteArray()));↵

10

                        new ByteArrayInputStream(buffer.toByteArray()));↵

11

                c2 = (DialCap) in.readObject();↵

11

                d2 = (DefaultIntervalXYDataset) in.readObject();↵

12

                in.close();↵

12

                in.close();↵

13

            }↵

13

            }↵

14

            catch (Exception e) {↵

14

            catch (Exception e) {↵

15

                e.printStackTrace();↵

15

                e.printStackTrace();↵

16

            }↵

16

            }↵

17

            assertEquals(c1, c2);↵

17

            assertEquals(d1, d2);↵

18

            ↵

19

            // test a custom instance↵

18

            // t↵

20

            c1 = new DialCap();↵

21

            c1.setFillPaint(new GradientPaint(1.0f, 2.0f, Color.blue, ↵

22

                    3.0f, 4.0f, Color.green));↵

23

            c1.setOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.white, ↵

24

                    3.0f, 4.0f, Color.gray));↵

25

            c1.setOutlineStroke(new BasicStroke(2.0f));↵

26

            c2 = null;↵

19

    ry a dataset with some content...↵

20

            d1 = createSampleDataset1();↵

27

            try {↵

21

            try {↵

28

                ByteArrayOutputStream buffer = new ByteArrayOutputStream();↵

22

                ByteArrayOutputStream buffer = new ByteArrayOutputStream();↵

29

                ObjectOutput out = new ObjectOutputStream(buffer);↵

23

                ObjectOutput out = new ObjectOutputStream(buffer);↵

30

                out.writeObject(c1);↵

24

                out.writeObject(d1);↵

31

                out.close();↵

25

                out.close();↵

32

                ObjectInput in = new ObjectInputStream(↵

26

                ObjectInput in = new ObjectInputStream(↵

33

                        new ByteArrayInputStream(buffer.toByteArray()));↵

27

                        new ByteArrayInputStream(buffer.toByteArray()));↵

34

                c2 = (DialCap) in.readObject();↵

28

                d2 = (DefaultIntervalXYDataset) in.readObject();↵

35

                in.close();↵

29

                in.close();↵

36

            }↵

30

            }↵

37

            catch (Exception e) {↵

31

            catch (Exception e) {↵

38

                e.printStackTrace();↵

32

                e.printStackTrace();↵

39

            }↵

33

            }↵

40

            assertEquals(c1, c2);

34

            assertEquals(d1, d2);

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.4
Clones location | Clones are in different classes having the same super class
Number of node comparisons | 238

1. {Non-refactorable}

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

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

   1

       DefaultIntervalXYDataset d1 = new DefaultIntervalXYDataset();

   1

       DialCap c1 = new DialCap();

   2

       DefaultIntervalXYDataset d2 = null;

   2

       DialCap c2 = null;

   3

       try

   3

       try

   4

       ByteArrayOutputStream buffer = new ByteArrayOutputStream();

   4

       ByteArrayOutputStream buffer = new ByteArrayOutputStream();

   5

       ObjectOutput out = new ObjectOutputStream(buffer);

   5

       ObjectOutput out = new ObjectOutputStream(buffer);

   6

       out.writeObject(c1);

   6 | out.writeObject(c1);
   6 | out.writeObject(d1);

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   c1 | d1 | VARIABLE_NAME_MISMATCH
   org.jfree.chart.plot.dial.DialCap | org.jfree.data.xy.DefaultIntervalXYDataset | VARIABLE_TYPE_MISMATCH

   Preondition Violations

   Type org.jfree.chart.plot.dial.DialCap of variable c1 does not match with type org.jfree.data.xy.DefaultIntervalXYDataset of variable d1
   - Make classes org.jfree.chart.plot.dial.DialCap and org.jfree.data.xy.DefaultIntervalXYDataset extend a common superclass

   6

       out.writeObject(d1);

   7

       out.close();

   7

       out.close();

   8

       ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));

   8

       ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));

   9 | d2 = (DefaultIntervalXYDataset)in.readObject();

   Preondition Violations
   Unmatched statement d2=(DefaultIntervalXYDataset)in.readObject(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
   Unmatched statement d2=(DefaultIntervalXYDataset)in.readObject(); 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

   9

       d2 = (DefaultIntervalXYDataset)in.readObject();

   9

       c2 = (DialCap)in.readObject();

   9 | c2 = (DialCap)in.readObject();

   Preondition Violations
   Unmatched statement c2=(DialCap)in.readObject(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
   Unmatched statement c2=(DialCap)in.readObject(); 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

   10

       in.close();

   10

       in.close();

   11

       assertEquals(c1, c2);

   11 | assertEquals(c1, c2);
   11 | assertEquals(d1, d2);

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   c1 | d1 | VARIABLE_NAME_MISMATCH
   org.jfree.chart.plot.dial.DialCap | org.jfree.data.xy.DefaultIntervalXYDataset | VARIABLE_TYPE_MISMATCH

   Preondition Violations

   Type org.jfree.chart.plot.dial.DialCap of variable c1 does not match with type org.jfree.data.xy.DefaultIntervalXYDataset of variable d1
   - Make classes org.jfree.chart.plot.dial.DialCap and org.jfree.data.xy.DefaultIntervalXYDataset extend a common superclass

   11

       assertEquals(d1, d2);

   12 | d1 = createSampleDataset1();

   Preondition Violations
   Unmatched statement d1=createSampleDataset1(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted

   12

       d1 = createSampleDataset1();

   12

       c1 = new DialCap();

   12 | c1 = new DialCap();

   Preondition Violations
   Unmatched statement c1=new DialCap(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted

   13

       c1.setFillPaint(new GradientPaint(1.0f, 2.0f, Color.blue, 3.0f, 4.0f, Color.green));

   14

       c1.setOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.white, 3.0f, 4.0f, Color.gray));

   15

       c1.setOutlineStroke(new BasicStroke(2.0f));

   16

       c2 = null;

   16 | c2 = null;

   Preondition Violations
   Unmatched statement c2=null; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted

   17

       try

   13

       try

   18

       ByteArrayOutputStream buffer = new ByteArrayOutputStream();

   14

       ByteArrayOutputStream buffer = new ByteArrayOutputStream();

   19

       ObjectOutput out = new ObjectOutputStream(buffer);

   15

       ObjectOutput out = new ObjectOutputStream(buffer);

   20

       out.writeObject(c1);

   20 | out.writeObject(c1);
   16 | out.writeObject(d1);

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   c1 | d1 | VARIABLE_NAME_MISMATCH
   org.jfree.chart.plot.dial.DialCap | org.jfree.data.xy.DefaultIntervalXYDataset | VARIABLE_TYPE_MISMATCH

   Preondition Violations

   Type org.jfree.chart.plot.dial.DialCap of variable c1 does not match with type org.jfree.data.xy.DefaultIntervalXYDataset of variable d1
   - Make classes org.jfree.chart.plot.dial.DialCap and org.jfree.data.xy.DefaultIntervalXYDataset extend a common superclass

   16

       out.writeObject(d1);

   21

       out.close();

   17

       out.close();

   22

       ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));

   18

       ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));

   19 | d2 = (DefaultIntervalXYDataset)in.readObject();

   Preondition Violations
   Unmatched statement d2=(DefaultIntervalXYDataset)in.readObject(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
   Unmatched statement d2=(DefaultIntervalXYDataset)in.readObject(); 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

   19

       d2 = (DefaultIntervalXYDataset)in.readObject();

   23

       c2 = (DialCap)in.readObject();

   23 | c2 = (DialCap)in.readObject();

   Preondition Violations
   Unmatched statement c2=(DialCap)in.readObject(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
   Unmatched statement c2=(DialCap)in.readObject(); 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

   24

       in.close();

   20

       in.close();

   25

       assertEquals(c1, c2);

   25 | assertEquals(c1, c2);
   21 | assertEquals(d1, d2);

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   c1 | d1 | VARIABLE_NAME_MISMATCH
   org.jfree.chart.plot.dial.DialCap | org.jfree.data.xy.DefaultIntervalXYDataset | VARIABLE_TYPE_MISMATCH

   Preondition Violations

   Type org.jfree.chart.plot.dial.DialCap of variable c1 does not match with type org.jfree.data.xy.DefaultIntervalXYDataset of variable d1
   - Make classes org.jfree.chart.plot.dial.DialCap and org.jfree.data.xy.DefaultIntervalXYDataset extend a common superclass

   21

       assertEquals(d1, d2);

   Precondition Violations (16)
   Row | Violation
   --- | ---
   1 | Type org.jfree.chart.plot.dial.DialCap of variable c1 does not match with type org.jfree.data.xy.DefaultIntervalXYDataset of variable d1
   2 | Unmatched statement d2=(DefaultIntervalXYDataset)in.readObject(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
   3 | Unmatched statement d2=(DefaultIntervalXYDataset)in.readObject(); 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 | Unmatched statement c2=(DialCap)in.readObject(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
   5 | Unmatched statement c2=(DialCap)in.readObject(); 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 | Type org.jfree.chart.plot.dial.DialCap of variable c1 does not match with type org.jfree.data.xy.DefaultIntervalXYDataset of variable d1
   7 | Unmatched statement d1=createSampleDataset1(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
   8 | Unmatched statement c1=new DialCap(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
   9 | Unmatched statement c2=null; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
   10 | Type org.jfree.chart.plot.dial.DialCap of variable c1 does not match with type org.jfree.data.xy.DefaultIntervalXYDataset of variable d1
   11 | Unmatched statement d2=(DefaultIntervalXYDataset)in.readObject(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
   12 | Unmatched statement d2=(DefaultIntervalXYDataset)in.readObject(); 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 | Unmatched statement c2=(DialCap)in.readObject(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
   14 | Unmatched statement c2=(DialCap)in.readObject(); 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
   15 | Type org.jfree.chart.plot.dial.DialCap of variable c1 does not match with type org.jfree.data.xy.DefaultIntervalXYDataset of variable d1
   16 | Clone fragment #1 returns variables in, in , while Clone fragment #2 returns variables in, in