do { int n = channel.read(buf); if (n != 0 || !blocking || !(channel instanceof SelectableChannel) || !buf.hasRemaining()) { return n; } try { awaitReadable(channel); } catch (InterruptedException ex) { throw new InterruptedIOException(ex.getMessage()); } } while (true);
do { int n = channel.write(buf); if (n != 0 || !blocking || !(channel instanceof SelectableChannel) || !buf.hasRemaining()) { return n; } try { awaitWritable(channel); } catch (InterruptedException ex) { throw new InterruptedIOException(ex.getMessage()); } } while (true);
Clone fragments detected by clone detection tool
File path: /jruby-1.4.0/src/org/jruby/util/io/BlockingIO.java File path: /jruby-1.4.0/src/org/jruby/util/io/BlockingIO.java
Method name: int read(ReadableByteChannel, ByteBuffer, boolean) Method name: int write(WritableByteChannel, ByteBuffer, boolean)
Number of AST nodes: 6 Number of AST nodes: 6
1
do {
1
do {
2
            int n = channel.read(buf);
2
            int n = channel.write(buf);
3
            if (n != 0 || !blocking || !(channel instanceof SelectableChannel) || !buf.hasRemaining()) {
3
            if (n != 0 || !blocking || !(channel instanceof SelectableChannel) || !buf.hasRemaining()) {
4
                return n;
4
                return n;
5
            }
5
            }
6
            try {
6
            try {
7
                awaitReadable(channel);
7
                awaitWritable(channel);
8
            } catch (InterruptedException ex) {
8
            } catch (InterruptedException ex) {
9
                throw new InterruptedIOException(ex.getMessage());
9
                throw new InterruptedIOException(ex.getMessage());
10
            }
10
            }
11
        } while (true);
11
        } while (true);
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.5
Clones locationClones are declared in the same class
Number of node comparisons17
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements6
    Number of unmapped statements in the first code fragment0
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)1.8
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    6
    do while(true)
    6
    do while(true)
    1
    int n = channel.read(buf);
    1
    int n = channel.read(buf);
    1
    int n = channel.write(buf);
    Differences
    Expression1Expression2Difference
    readwriteMETHOD_INVOCATION_NAME_MISMATCH
    java.nio.channels.ReadableByteChanneljava.nio.channels.WritableByteChannelVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Expression channel.read(buf) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression channel.write(buf) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Type java.nio.channels.ReadableByteChannel of variable channel does not match with type java.nio.channels.WritableByteChannel of variable channel
    • Make classes java.nio.channels.ReadableByteChannel and java.nio.channels.WritableByteChannel extend a common superclass
    1
    int n = channel.write(buf);
    2
    if (n != 0 || !blocking || !(channel instanceof SelectableChannel) || !buf.hasRemaining())
    2
    if (n != 0 || !blocking || !(channel instanceof SelectableChannel) || !buf.hasRemaining())
    2
    if (n != 0 || !blocking || !(channel instanceof SelectableChannel) || !buf.hasRemaining())
    Differences
    Expression1Expression2Difference
    java.nio.channels.ReadableByteChanneljava.nio.channels.WritableByteChannelVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type java.nio.channels.ReadableByteChannel of variable channel does not match with type java.nio.channels.WritableByteChannel of variable channel
    • Make classes java.nio.channels.ReadableByteChannel and java.nio.channels.WritableByteChannel extend a common superclass
    2
    if (n != 0 || !blocking || !(channel instanceof SelectableChannel) || !buf.hasRemaining())
    3
    return n;
    3
    return n;
    4
    try
    4
    try
    5
    awaitReadable(channel);
    5
    awaitReadable(channel);
    5
    awaitWritable(channel);
    Differences
    Expression1Expression2Difference
    awaitReadableawaitWritableMETHOD_INVOCATION_NAME_MISMATCH
    java.nio.channels.ReadableByteChanneljava.nio.channels.WritableByteChannelVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Expression awaitReadable(channel) is a method call throwing exception(s) that should be caught by a try block that will be extracted
    Expression awaitWritable(channel) is a method call throwing exception(s) that should be caught by a try block that will be extracted
    Expression awaitReadable(channel) is a void method call, and thus it cannot be parameterized
    Expression awaitWritable(channel) is a void method call, and thus it cannot be parameterized
    Type java.nio.channels.ReadableByteChannel of variable channel does not match with type java.nio.channels.WritableByteChannel of variable channel
    • Make classes java.nio.channels.ReadableByteChannel and java.nio.channels.WritableByteChannel extend a common superclass
    5
    awaitWritable(channel);
    Precondition Violations (9)
    Row Violation
    1Expression channel.read(buf) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    2Expression channel.write(buf) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3Type java.nio.channels.ReadableByteChannel of variable channel does not match with type java.nio.channels.WritableByteChannel of variable channel
    4Type java.nio.channels.ReadableByteChannel of variable channel does not match with type java.nio.channels.WritableByteChannel of variable channel
    5Expression awaitReadable(channel) is a method call throwing exception(s) that should be caught by a try block that will be extracted
    6Expression awaitWritable(channel) is a method call throwing exception(s) that should be caught by a try block that will be extracted
    7Expression awaitReadable(channel) is a void method call, and thus it cannot be parameterized
    8Expression awaitWritable(channel) is a void method call, and thus it cannot be parameterized
    9Type java.nio.channels.ReadableByteChannel of variable channel does not match with type java.nio.channels.WritableByteChannel of variable channel