PaintMap m1 = new PaintMap(); m1.put("K1", Color.red); m1.put("K2", new GradientPaint(1.0f, 2.0f, Color.green, 3.0f, 4.0f, Color.yellow)); PaintMap m2 = null; try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(m1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( buffer.toByteArray())); m2 = (PaintMap) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(m1, m2);
Stroke s = new BasicStroke(1.23f); LegendGraphic g1 = new LegendGraphic(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), Color.black); g1.setOutlineStroke(s); LegendGraphic g2 = null; try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(g1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray()) ); g2 = (LegendGraphic) in.readObject(); in.close(); } catch (Exception e) { System.out.println(e.toString()); } assertTrue(g1.equals(g2));
Clone fragments detected by clone detection tool
File path: /jfreechart-1.0.10/tests/org/jfree/chart/junit/PaintMapTests.java File path: /jfreechart-1.0.10/tests/org/jfree/chart/title/junit/LegendGraphicTests.java
Method name: void testSerialization2() Method name: void testSerialization()
Number of AST nodes: 13 Number of AST nodes: 13
1
PaintMap m1 = new PaintMap();
2
        m1.put("K1", Color.red);
3
        m1.put("K2", new GradientPaint
1
Stroke s = new BasicStroke(1.23f);
4
(1.0f, 2.0f, Color.green, 3.0f, 4.0f, 
2
        LegendGraphic g1 = new LegendGraphic(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), 
5
                Color.yellow));
6
        PaintMap m
3
Color.black);
4
        g1.setOutlineStroke(s);
7
2 = null;
5
        LegendGraphic g2 = null;
8
        try {
6
        try {
9
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
7
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
10
            ObjectOutput out = new ObjectOutputStream(buffer);
8
            ObjectOutput out = new ObjectOutputStream(buffer);
11
            out.writeObject(m1);
9
            out.writeObject(g1);
12
            out.close();
10
            out.close();
13
            ObjectInput in = new ObjectInputStream(
11
            ObjectInput in = new ObjectInputStream(
14
new ByteArrayInputStream(
12
                new ByteArrayInputStream(
15
                    buffer.toByteArray())
13
buffer.toByteArray())
16
);
14
            );
17
            m2 = (PaintMap) in.readObject();
15
            g2 = (LegendGraphic) in.readObject();
18
            in.close();
16
            in.close();
19
        }
17
        }
20
        catch (Exception e) {
18
        catch (Exception e) {
21
            e.printStackTrace();
19
            System.out.println(e.toString());
22
        }
20
        }
23
        assertEquals(m1, m2);
21
        assertTrue(g1.equals(g2));
Summary
Number of common nesting structure subtrees1
Number of refactorable cases0
Number of non-refactorable cases1
Time elapsed for finding largest common nesting structure subtrees (ms)0.3
Clones locationClones are in different classes having the same super class
Number of node comparisons89
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements8
    Number of unmapped statements in the first code fragment5
    Number of unmapped statements in the second code fragment5
    Time elapsed for statement mapping (ms)21.2
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
                                                                          
    1
    Stroke s = new BasicStroke(1.23f);
    1
    PaintMap m1 = new PaintMap();
    1
    PaintMap m1 = new PaintMap();
    Preondition Violations
    Unmatched statement PaintMap m1=new PaintMap(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                                
                                                                                                                                                                                          
    2
    LegendGraphic g1 = new LegendGraphic(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), Color.black);
    Preondition Violations
    Unmatched statement LegendGraphic g1=new LegendGraphic(new Rectangle2D.Double(1.0,2.0,3.0,4.0),Color.black); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    2
    LegendGraphic g1 = new LegendGraphic(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), Color.black);
    2
    m1.put("K1", Color.red);
    2
    m1.put("K1", Color.red);
    Preondition Violations
    Unmatched statement m1.put("K1",Color.red); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                        
                                                        
    3
    g1.setOutlineStroke(s);
    Preondition Violations
    Unmatched statement g1.setOutlineStroke(s); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    3
    g1.setOutlineStroke(s);
    3
    m1.put("K2", new GradientPaint(1.0f, 2.0f, Color.green, 3.0f, 4.0f, Color.yellow));
    3
    m1.put("K2", new GradientPaint(1.0f, 2.0f, Color.green, 3.0f, 4.0f, Color.yellow));
    Preondition Violations
    Unmatched statement m1.put("K2",new GradientPaint(1.0f,2.0f,Color.green,3.0f,4.0f,Color.yellow)); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                                                                                                                                    
                                                      
    4
    LegendGraphic g2 = null;
    4
    PaintMap m2 = null;
                                            
    5
    try
    5
    try
    5
    try
    Differences
    Expression1Expression2Difference
    printStackTraceprintlnMETHOD_INVOCATION_NAME_MISMATCH
    eSystem.outAST_TYPE_MISMATCH
    e.printStackTrace()System.out.println(e.toString())ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression e.printStackTrace() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression System.out.println(e.toString()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression e.printStackTrace() is a void method call, and thus it cannot be parameterized
    Expression System.out.println(e.toString()) is a void method call, and thus it cannot be parameterized
    Expression e cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression e.printStackTrace() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression System.out.println(e.toString()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression e.printStackTrace() is a void method call, and thus it cannot be parameterized
    Expression System.out.println(e.toString()) is a void method call, and thus it cannot be parameterized
    5
    try
    6
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    6
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    7
    ObjectOutput out = new ObjectOutputStream(buffer);
    7
    ObjectOutput out = new ObjectOutputStream(buffer);
    8
    out.writeObject(m1);
    8
    out.writeObject(m1);
    8
    out.writeObject(g1);
    Differences
    Expression1Expression2Difference
    m1g1VARIABLE_NAME_MISMATCH
    org.jfree.chart.PaintMaporg.jfree.chart.title.LegendGraphicVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.jfree.chart.PaintMap of variable m1 does not match with type org.jfree.chart.title.LegendGraphic of variable g1
    • Make classes org.jfree.chart.PaintMap and org.jfree.chart.title.LegendGraphic extend a common superclass
    8
    out.writeObject(g1);
    9
    out.close();
    9
    out.close();
    10
    ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
    10
    ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
                                                                                
    11
    g2 = (LegendGraphic)in.readObject();
    Preondition Violations
    Unmatched statement g2=(LegendGraphic)in.readObject(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    Unmatched statement g2=(LegendGraphic)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
    11
    g2 = (LegendGraphic)in.readObject();
    11
    m2 = (PaintMap)in.readObject();
    11
    m2 = (PaintMap)in.readObject();
    Preondition Violations
    Unmatched statement m2=(PaintMap)in.readObject(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    Unmatched statement m2=(PaintMap)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
                                                                      
    12
    in.close();
    12
    in.close();
    13
    assertEquals(m1, m2);
    13
    assertEquals(m1, m2);
    13
    assertTrue(g1.equals(g2));
    Differences
    Expression1Expression2Difference
    assertEqualsassertTrueMETHOD_INVOCATION_NAME_MISMATCH
    assertEquals(m1,m2)assertTrue(g1.equals(g2))ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression assertEquals(m1,m2) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertTrue(g1.equals(g2)) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals(m1,m2) is a void method call, and thus it cannot be parameterized
    Expression assertTrue(g1.equals(g2)) is a void method call, and thus it cannot be parameterized
    Expression assertEquals(m1,m2) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertTrue(g1.equals(g2)) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals(m1,m2) is a void method call, and thus it cannot be parameterized
    Expression assertTrue(g1.equals(g2)) is a void method call, and thus it cannot be parameterized
    13
    assertTrue(g1.equals(g2));
    Precondition Violations (27)
    Row Violation
    1Unmatched statement PaintMap m1=new PaintMap(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    2Unmatched statement LegendGraphic g1=new LegendGraphic(new Rectangle2D.Double(1.0,2.0,3.0,4.0),Color.black); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    3Unmatched statement m1.put("K1",Color.red); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    4Unmatched statement g1.setOutlineStroke(s); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    5Unmatched statement m1.put("K2",new GradientPaint(1.0f,2.0f,Color.green,3.0f,4.0f,Color.yellow)); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    6Expression e.printStackTrace() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7Expression System.out.println(e.toString()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    8Expression e.printStackTrace() is a void method call, and thus it cannot be parameterized
    9Expression System.out.println(e.toString()) is a void method call, and thus it cannot be parameterized
    10Expression e cannot be parameterized, because it has dependencies to/from statements that will be extracted
    11Expression e.printStackTrace() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    12Expression System.out.println(e.toString()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    13Expression e.printStackTrace() is a void method call, and thus it cannot be parameterized
    14Expression System.out.println(e.toString()) is a void method call, and thus it cannot be parameterized
    15Type org.jfree.chart.PaintMap of variable m1 does not match with type org.jfree.chart.title.LegendGraphic of variable g1
    16Unmatched statement g2=(LegendGraphic)in.readObject(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    17Unmatched statement g2=(LegendGraphic)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
    18Unmatched statement m2=(PaintMap)in.readObject(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    19Unmatched statement m2=(PaintMap)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
    20Expression assertEquals(m1,m2) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    21Expression assertTrue(g1.equals(g2)) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    22Expression assertEquals(m1,m2) is a void method call, and thus it cannot be parameterized
    23Expression assertTrue(g1.equals(g2)) is a void method call, and thus it cannot be parameterized
    24Expression assertEquals(m1,m2) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    25Expression assertTrue(g1.equals(g2)) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    26Expression assertEquals(m1,m2) is a void method call, and thus it cannot be parameterized
    27Expression assertTrue(g1.equals(g2)) is a void method call, and thus it cannot be parameterized