InputStream is = this.getInputStream(); try { StringBuffer sb = new StringBuffer(); if (timeout == null || timeout.intValue() == 0) { while (sb.toString().indexOf(s) == -1) { sb.append((char) is.read()); } } else { Calendar endTime = Calendar.getInstance(); endTime.add(Calendar.SECOND, timeout.intValue()); while (sb.toString().indexOf(s) == -1) { while (Calendar.getInstance().before(endTime) && is.available() == 0) { Thread.sleep(250); } if (is.available() == 0) { throw new BuildException( "Response timed-out waiting for \"" + s + '\"', getLocation()); } sb.append((char) is.read()); } } log(sb.toString(), Project.MSG_INFO); } catch (BuildException be) { throw be; } catch (Exception e) { throw new BuildException(e, getLocation()); }
try { StringBuffer sb = new StringBuffer(); if (timeout == null || timeout.intValue() == 0) { while (sb.toString().indexOf(s) == -1) { sb.append((char) is.read()); } } else { Calendar endTime = Calendar.getInstance(); endTime.add(Calendar.SECOND, timeout.intValue()); while (sb.toString().indexOf(s) == -1) { while (Calendar.getInstance().before(endTime) && is.available() == 0) { Thread.sleep(250); } if (is.available() == 0) { log("Read before running into timeout: " + sb.toString(), Project.MSG_DEBUG); throw new BuildException( "Response timed-out waiting for \"" + s + '\"', getLocation()); } sb.append((char) is.read()); } } log(sb.toString(), Project.MSG_INFO); } catch (BuildException be) { throw be; } catch (Exception e) { throw new BuildException(e, getLocation()); }
Clone fragments detected by clone detection tool
File path: /apache-ant-1.7.0/src/org/apache/tools/ant/taskdefs/optional/net/RExecTask.java File path: /apache-ant-1.7.0/src/org/apache/tools/ant/taskdefs/optional/net/TelnetTask.java
Method name: void waitForString(String, Integer) Method name: void waitForString(String, Integer)
Number of AST nodes: 15 Number of AST nodes: 15
1
InputStream is = this.getInputStream();
2
            try {
1
try {
3
                StringBuffer sb = new StringBuffer();
2
                StringBuffer sb = new StringBuffer();
4
                if (timeout == null || timeout.intValue() == 0) {
3
                if (timeout == null || timeout.intValue() == 0) {
5
                    while (sb.toString().indexOf(s) == -1) {
4
                    while (sb.toString().indexOf(s) == -1) {
6
                        sb.append((char) is.read());
5
                        sb.append((char) is.read());
7
                    }
6
                    }
8
                } else {
7
                } else {
9
                    Calendar endTime = Calendar.getInstance();
8
                    Calendar endTime = Calendar.getInstance();
10
                    endTime.add(Calendar.SECOND, timeout.intValue());
9
                    endTime.add(Calendar.SECOND, timeout.intValue());
11
                    while (sb.toString().indexOf(s) == -1) {
10
                    while (sb.toString().indexOf(s) == -1) {
12
                        while (Calendar.getInstance().before(endTime)
11
                        while (Calendar.getInstance().before(endTime)
13
                            && is.available() == 0) {
12
                               && is.available() == 0) {
14
                            Thread.sleep(250);
13
                            Thread.sleep(250);
15
                        }
14
                        }
16
                        if (is.available() == 0) {
15
                        if (is.available() == 0) {
16
                            log("Read before running into timeout: "
17
                                + sb.toString(), Project.MSG_DEBUG);
17
                            throw new BuildException(
18
                            throw new BuildException(
18
                                "Response timed-out waiting for \"" + s + '\"',
19
                                "Response timed-out waiting for \"" + s + '\"',
19
                                getLocation());
20
                                getLocation());
20
                        }
21
                        }
21
                        sb.append((char) is.read());
22
                        sb.append((char) is.read());
22
                    }
23
                    }
23
                }
24
                }
24
                log(sb.toString(), Project.MSG_INFO);
25
                log(sb.toString(), Project.MSG_INFO);
25
            } catch (BuildException be) {
26
            } catch (BuildException be) {
26
                throw be;
27
                throw be;
27
            } catch (Exception e) {
28
            } catch (Exception e) {
28
                throw new BuildException(e, getLocation());
29
                throw new BuildException(e, getLocation());
29
            }
30
            }
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)3.7
Clones locationClones are in different classes having the same super class
Number of node comparisons47
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements14
    Number of unmapped statements in the first code fragment1
    Number of unmapped statements in the second code fragment1
    Time elapsed for statement mapping (ms)6.4
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    1
    InputStream is = this.getInputStream();
                                                                                    
    2
    try
    2
    try
    3
    StringBuffer sb = new StringBuffer();
    3
    StringBuffer sb = new StringBuffer();
    4
    if (timeout == null || timeout.intValue() == 0)
    4
    if (timeout == null || timeout.intValue() == 0)
    5
    while (sb.toString().indexOf(s) == -1)
    5
    while (sb.toString().indexOf(s) == -1)
    6
    sb.append((char)is.read());
    6
    sb.append((char)is.read());
    else
    else
    7
    Calendar endTime = Calendar.getInstance();
    7
    Calendar endTime = Calendar.getInstance();
    8
    endTime.add(Calendar.SECOND, timeout.intValue());
    8
    endTime.add(Calendar.SECOND, timeout.intValue());
    9
    while (sb.toString().indexOf(s) == -1)
    9
    while (sb.toString().indexOf(s) == -1)
    10
    while (Calendar.getInstance().before(endTime) && is.available() == 0)
    10
    while (Calendar.getInstance().before(endTime) && is.available() == 0)
    11
    Thread.sleep(250);
    11
    Thread.sleep(250);
    12
    if (is.available() == 0)
    12
    if (is.available() == 0)
                                                                                                                                                                    
    13
    log("Read before running into timeout: " + sb.toString(), Project.MSG_DEBUG);
    Preondition Violations
    Unmatched statement log("Read before running into timeout: " + sb.toString(),Project.MSG_DEBUG); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    13
    log("Read before running into timeout: " + sb.toString(), Project.MSG_DEBUG);
    13
    throw new BuildException("Response timed-out waiting for \"" + s + '\"', getLocation());
    14
    throw new BuildException("Response timed-out waiting for \"" + s + '\"', getLocation());
    14
    sb.append((char)is.read());
    15
    sb.append((char)is.read());
    15
    log(sb.toString(), Project.MSG_INFO);
    16
    log(sb.toString(), Project.MSG_INFO);
    Precondition Violations (2)
    Row Violation
    1Unmatched statement log("Read before running into timeout: " + sb.toString(),Project.MSG_DEBUG); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2Clone fragment #1 returns variables , while Clone fragment #2 returns variables sb