bos.write(CRLF); bos.close(); outputStream.write(bos.toByteArray()); // Read the response ByteArrayOutputStream response = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int length = 0; while(( length = inputStream.read(buffer)) != -1) { response.write(buffer, 0, length); } response.close(); byte[] mirroredResponse = getMirroredResponse(response.toByteArray()); // Check that the request and response matches checkArraysHaveSameContent(bos.toByteArray(), mirroredResponse); // Close the connection clientSocket.close(); // Connect to the http server, and do a simple http get, with // a pause in the middle of transmitting the header clientSocket = new Socket("localhost", HTTP_SERVER_PORT); outputStream = clientSocket.getOutputStream(); inputStream = clientSocket.getInputStream(); // Write to the socket bos = new ByteArrayOutputStream(); // Headers bos.write("GET / HTTP 1.1".getBytes(ISO_8859_1));
bos.write(postBody); bos.close(); // Write the headers and body outputStream.write(bos.toByteArray()); // Read the response ByteArrayOutputStream response = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int length = 0; while((length = inputStream.read(buffer)) != -1) { response.write(buffer, 0, length); } response.close(); byte[] mirroredResponse = getMirroredResponse(response.toByteArray()); // Check that the request and response matches checkArraysHaveSameContent(bos.toByteArray(), mirroredResponse); // Close the connection clientSocket.close(); // Connect to the http server, and do a simple http post, with // a pause after transmitting the headers clientSocket = new Socket("localhost", HTTP_SERVER_PORT); outputStream = clientSocket.getOutputStream(); inputStream = clientSocket.getInputStream(); // Write to the socket bos = new ByteArrayOutputStream(); // Headers bos.write("GET / HTTP 1.1".getBytes(ISO_8859_1));
Clone fragments detected by clone detection tool
File path: /jakarta-jmeter-2.3.2/test/src/org/apache/jmeter/protocol/http/control/TestHTTPMirrorThread.java File path: /jakarta-jmeter-2.3.2/test/src/org/apache/jmeter/protocol/http/control/TestHTTPMirrorThread.java
Method name: void testGetRequest() Method name: void testPostRequest()
Number of AST nodes: 17 Number of AST nodes: 17
1
bos.write(CRLF);
1
bos.write(postBody);
2
        bos.close();
2
        bos.close();
3
        // Write the headers and body
3
        outputStream.write(bos.toByteArray());
4
        outputStream.write(bos.toByteArray());
4
        
5
        // Read the response
5
        // Read the response
6
        ByteArrayOutputStream response = new ByteArrayOutputStream();        
6
        ByteArrayOutputStream response = new ByteArrayOutputStream();        
7
        byte[] buffer = new byte[1024];
7
        byte[] buffer = new byte[1024];
8
        int length = 0;
8
        int length = 0;
9
        while(( length = inputStream.read(buffer)) != -1) {
9
        while((length = inputStream.read(buffer)) != -1) {
10
        	response.write(buffer, 0, length);
10
        	response.write(buffer, 0, length);
11
        }
11
        }
12
        response.close();
12
        response.close();
13
        byte[] mirroredResponse = getMirroredResponse(response.toByteArray());   		
13
        byte[] mirroredResponse = getMirroredResponse(response.toByteArray());   		
14
        // Check that the request and response matches
14
        // Check that the request and response matches
15
        checkArraysHaveSameContent(bos.toByteArray(), mirroredResponse);
15
        checkArraysHaveSameContent(bos.toByteArray(), mirroredResponse);
16
        // Close the connection
16
        // Close the connection
17
        clientSocket.close();
17
        clientSocket.close();
18
        // Connect to the http server, and do a simple http get, with
18
        // Connect to the http server, and do a simple http post, with
19
        // a pause in the middle of transmitting the header
19
        // a pause after transmitting the headers
20
        clientSocket = new Socket("localhost", HTTP_SERVER_PORT);
20
        clientSocket = new Socket("localhost", HTTP_SERVER_PORT);
21
        outputStream = clientSocket.getOutputStream();
21
        outputStream = clientSocket.getOutputStream();
22
        inputStream = clientSocket.getInputStream();
22
        inputStream = clientSocket.getInputStream();
23
        
23
        
24
        // Write to the socket
24
        // Write to the socket
25
        bos = new ByteArrayOutputStream();
25
        bos = new ByteArrayOutputStream();
26
        // Headers
26
        // Headers
27
        bos.write("GET / HTTP 1.1".getBytes(ISO_8859_1));
27
        bos.write("GET / HTTP 1.1".getBytes(ISO_8859_1));
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.2
Clones locationClones are declared in the same class
Number of node comparisons202
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements17
    Number of unmapped statements in the first code fragment0
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)13.8
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    9
    bos.write(CRLF);
    9
    bos.write(CRLF);
    19
    bos.close();
    Differences
    Expression1Expression2Difference
    writecloseMETHOD_INVOCATION_NAME_MISMATCH
    bos.write(CRLF)bos.close()ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression bos.write(CRLF) is a void method call, and thus it cannot be parameterized
    Expression bos.close() is a void method call, and thus it cannot be parameterized
    Expression bos.write(CRLF) is a void method call, and thus it cannot be parameterized
    Expression bos.close() is a void method call, and thus it cannot be parameterized
    19
    bos.close();
    10
    bos.close();
    10
    bos.close();
    26
    response.close();
    Differences
    Expression1Expression2Difference
    bosresponseVARIABLE_NAME_MISMATCH
    Preondition Violations
    Expression response cannot be parameterized, because it has dependencies to/from statements that will be extracted
    26
    response.close();
    11
    outputStream.write(bos.toByteArray());
    20
    outputStream.write(bos.toByteArray());
    12
    ByteArrayOutputStream response = new ByteArrayOutputStream();
    21
    ByteArrayOutputStream response = new ByteArrayOutputStream();
    13
    byte[] buffer = new byte[1024];
    22
    byte[] buffer = new byte[1024];
    14
    int length = 0;
    23
    int length = 0;
    15
    while ((length = inputStream.read(buffer)) != -1)
    24
    while ((length = inputStream.read(buffer)) != -1)
    16
    response.write(buffer, 0, length);
    25
    response.write(buffer, 0, length);
    17
    response.close();
    17
    response.close();
    18
    bos.write(postBody);
    Differences
    Expression1Expression2Difference
    closewriteMETHOD_INVOCATION_NAME_MISMATCH
    responsebosVARIABLE_NAME_MISMATCH
    response.close()bos.write(postBody)ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression response.close() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression response.close() is a void method call, and thus it cannot be parameterized
    Expression bos.write(postBody) is a void method call, and thus it cannot be parameterized
    Expression response cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression response.close() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression response.close() is a void method call, and thus it cannot be parameterized
    Expression bos.write(postBody) is a void method call, and thus it cannot be parameterized
    18
    bos.write(postBody);
    18
    byte[] mirroredResponse = getMirroredResponse(response.toByteArray());
    27
    byte[] mirroredResponse = getMirroredResponse(response.toByteArray());
    19
    checkArraysHaveSameContent(bos.toByteArray(), mirroredResponse);
    28
    checkArraysHaveSameContent(bos.toByteArray(), mirroredResponse);
    20
    clientSocket.close();
    29
    clientSocket.close();
    21
    clientSocket = new Socket("localhost", HTTP_SERVER_PORT);
    30
    clientSocket = new Socket("localhost", HTTP_SERVER_PORT);
    22
    outputStream = clientSocket.getOutputStream();
    31
    outputStream = clientSocket.getOutputStream();
    23
    inputStream = clientSocket.getInputStream();
    32
    inputStream = clientSocket.getInputStream();
    24
    bos = new ByteArrayOutputStream();
    33
    bos = new ByteArrayOutputStream();
    25
    bos.write("GET / HTTP 1.1".getBytes(ISO_8859_1));
    34
    bos.write("GET / HTTP 1.1".getBytes(ISO_8859_1));
    Precondition Violations (13)
    Row Violation
    1Expression bos.write(CRLF) is a void method call, and thus it cannot be parameterized
    2Expression bos.close() is a void method call, and thus it cannot be parameterized
    3Expression bos.write(CRLF) is a void method call, and thus it cannot be parameterized
    4Expression bos.close() is a void method call, and thus it cannot be parameterized
    5Expression response cannot be parameterized, because it has dependencies to/from statements that will be extracted
    6Expression response.close() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7Expression response.close() is a void method call, and thus it cannot be parameterized
    8Expression bos.write(postBody) is a void method call, and thus it cannot be parameterized
    9Expression response cannot be parameterized, because it has dependencies to/from statements that will be extracted
    10Expression response.close() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    11Expression response.close() is a void method call, and thus it cannot be parameterized
    12Expression bos.write(postBody) is a void method call, and thus it cannot be parameterized
    13Clone fragment #1 returns variables bos, outputStream, response, buffer, inputStream, mirroredResponse, clientSocket , while Clone fragment #2 returns variables bos, outputStream, response, buffer, inputStream, mirroredResponse, clientSocket