Ruby runtime = recv.getRuntime(); POSIX posix = runtime.getPosix(); try { // try to read grent to fail fast posix.getgrent(); if(block.isGiven()) { ThreadContext context = runtime.getCurrentContext(); posix.setgrent(); Group gr; while((gr = posix.getgrent()) != null) { block.yield(context, setupGroup(runtime, gr)); } posix.endgrent(); } Group gr = posix.getgrent(); if (gr != null) { return setupGroup(runtime, gr); } else { return runtime.getNil(); } } catch (Exception e) { if (runtime.getDebug().isTrue()) { runtime.getWarnings().warn(ID.NOT_IMPLEMENTED, "Etc.group is not supported by JRuby on this platform", e); } return runtime.getNil(); }
Ruby runtime = recv.getRuntime(); POSIX posix = runtime.getPosix(); try { // call getpwent to fail early if unsupported posix.getpwent(); if(block.isGiven()) { ThreadContext context = runtime.getCurrentContext(); posix.setpwent(); Passwd pw; while((pw = posix.getpwent()) != null) { block.yield(context, setupPasswd(runtime, pw)); } posix.endpwent(); } Passwd pw = posix.getpwent(); if (pw != null) { return setupPasswd(runtime, pw); } else { return runtime.getNil(); } } catch (Exception e) { if (runtime.getDebug().isTrue()) { runtime.getWarnings().warn(ID.NOT_IMPLEMENTED, "Etc.passwd is not supported by JRuby on this platform", e); } return runtime.getNil(); }
Clone fragments detected by clone detection tool
File path: /jruby-1.4.0/src/org/jruby/RubyEtc.java File path: /jruby-1.4.0/src/org/jruby/RubyEtc.java
Method name: IRubyObject group(IRubyObject, Block) Method name: IRubyObject passwd(IRubyObject, Block)
Number of AST nodes: 15 Number of AST nodes: 15
1
Ruby runtime = recv.getRuntime();
1
Ruby runtime = recv.getRuntime();
2
        POSIX posix = runtime.getPosix();
2
        POSIX posix = runtime.getPosix();
3
        try {
3
        try {
4
            // try to read grent to fail fast
4
            // call getpwent to fail early if unsupported
5
            posix.getgrent();
5
            posix.getpwent();
6
            if(block.isGiven()) {
6
            if(block.isGiven()) {
7
                ThreadContext context = runtime.getCurrentContext();
7
                ThreadContext context = runtime.getCurrentContext();
8
                posix.setgrent();
8
                posix.setpwent();
9
                Group gr;
9
                Passwd pw;
10
                while((gr = posix.getgrent()) != null) {
10
                while((pw = posix.getpwent()) != null) {
11
                    block.yield(context, setupGroup(runtime, gr));
11
                    block.yield(context, setupPasswd(runtime, pw));
12
                }
12
                }
13
                posix.endgrent();
13
                posix.endpwent();
14
            }
14
            }
15
            Group gr = posix.getgrent();
15
            Passwd pw = posix.getpwent();
16
            if (gr != null) {
16
            if (pw != null) {
17
                return setupGroup(runtime, gr);
17
                return setupPasswd(runtime, pw);
18
            } else {
18
            } else {
19
                return runtime.getNil();
19
                return runtime.getNil();
20
            }
20
            }
21
        } catch (Exception e) {
21
        } catch (Exception e) {
22
            if (runtime.getDebug().isTrue()) {
22
            if (runtime.getDebug().isTrue()) {
23
                runtime.getWarnings().warn(ID.NOT_IMPLEMENTED, "Etc.group is not supported by JRuby on this platform", e);
23
                runtime.getWarnings().warn(ID.NOT_IMPLEMENTED, "Etc.passwd is not supported by JRuby on this platform", e);
24
            }
24
            }
25
            return runtime.getNil();
25
            return runtime.getNil();
26
        }
26
        }
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)2.7
Clones locationClones are declared in the same class
Number of node comparisons51
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements10
    Number of unmapped statements in the first code fragment5
    Number of unmapped statements in the second code fragment5
    Time elapsed for statement mapping (ms)6.4
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    1
    Ruby runtime = recv.getRuntime();
    1
    Ruby runtime = recv.getRuntime();
    2
    POSIX posix = runtime.getPosix();
    2
    POSIX posix = runtime.getPosix();
    3
    try
    3
    try
    3
    try
    Differences
    Expression1Expression2Difference
    "Etc.group is not supported by JRuby on this platform""Etc.passwd is not supported by JRuby on this platform"LITERAL_VALUE_MISMATCH
    3
    try
                                            
    4
    posix.getpwent();
    4
    posix.getgrent();
                                            
    5
    if (block.isGiven())
    5
    if (block.isGiven())
    6
    ThreadContext context = runtime.getCurrentContext();
    6
    ThreadContext context = runtime.getCurrentContext();
    7
    posix.setgrent();
    7
    posix.setgrent();
    7
    posix.setpwent();
    Differences
    Expression1Expression2Difference
    setgrentsetpwentMETHOD_INVOCATION_NAME_MISMATCH
    Preondition Violations
    Expression posix.setgrent() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression posix.setpwent() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7
    posix.setpwent();
                              
    8
    Passwd pw;
    8
    Group gr;
                            
    9
    while ((gr = posix.getgrent()) != null)
    9
    while ((gr = posix.getgrent()) != null)
    9
    while ((pw = posix.getpwent()) != null)
    Differences
    Expression1Expression2Difference
    grpwVARIABLE_NAME_MISMATCH
    org.jruby.ext.posix.Grouporg.jruby.ext.posix.PasswdVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.jruby.ext.posix.Group of variable gr does not match with type org.jruby.ext.posix.Passwd of variable pw
    • Make classes org.jruby.ext.posix.Group and org.jruby.ext.posix.Passwd extend a common superclass
    9
    while ((pw = posix.getpwent()) != null)
                                                                                                      
    10
    block.yield(context, setupPasswd(runtime, pw));
    Preondition Violations
    Unmatched statement block.yield(context,setupPasswd(runtime,pw)); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    10
    block.yield(context, setupPasswd(runtime, pw));
    10
    block.yield(context, setupGroup(runtime, gr));
    10
    block.yield(context, setupGroup(runtime, gr));
    Preondition Violations
    Unmatched statement block.yield(context,setupGroup(runtime,gr)); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                    
    11
    posix.endgrent();
    11
    posix.endgrent();
    11
    posix.endpwent();
    Differences
    Expression1Expression2Difference
    endgrentendpwentMETHOD_INVOCATION_NAME_MISMATCH
    Preondition Violations
    Expression posix.endgrent() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression posix.endpwent() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    11
    posix.endpwent();
                                                                  
    12
    Passwd pw = posix.getpwent();
    Preondition Violations
    Unmatched statement Passwd pw=posix.getpwent(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    12
    Passwd pw = posix.getpwent();
    12
    Group gr = posix.getgrent();
    12
    Group gr = posix.getgrent();
    Preondition Violations
    Unmatched statement Group gr=posix.getgrent(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                
    13
    if (gr != null)
    13
    if (gr != null)
    13
    if (pw != null)
    Differences
    Expression1Expression2Difference
    grpwVARIABLE_NAME_MISMATCH
    org.jruby.ext.posix.Grouporg.jruby.ext.posix.PasswdVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.jruby.ext.posix.Group of variable gr does not match with type org.jruby.ext.posix.Passwd of variable pw
    • Make classes org.jruby.ext.posix.Group and org.jruby.ext.posix.Passwd extend a common superclass
    13
    if (pw != null)
                                                                          
    14
    return setupPasswd(runtime, pw);
    14
    return setupGroup(runtime, gr);
                                                                        
    else
    else
    15
    return runtime.getNil();
    15
    return runtime.getNil();
    Precondition Violations (11)
    Row Violation
    1Expression posix.setgrent() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    2Expression posix.setpwent() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3Type org.jruby.ext.posix.Group of variable gr does not match with type org.jruby.ext.posix.Passwd of variable pw
    4Unmatched statement block.yield(context,setupPasswd(runtime,pw)); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    5Unmatched statement block.yield(context,setupGroup(runtime,gr)); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6Expression posix.endgrent() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7Expression posix.endpwent() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    8Unmatched statement Passwd pw=posix.getpwent(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    9Unmatched statement Group gr=posix.getgrent(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    10Type org.jruby.ext.posix.Group of variable gr does not match with type org.jruby.ext.posix.Passwd of variable pw
    11Clone fragment #1 returns variables posix, runtime, context, gr , while Clone fragment #2 returns variables posix, runtime, context, pw