Program: 12061
Project: 12061
Buggy source:
private void pullUpLocallyAccessedFields(Set<VariableDeclaration> accessedLocalFieldsG1,Set<VariableDeclaration> accessedLocalFieldsG2,ListRewrite bodyDeclarationsRewrite,Set<ITypeBinding> requiredImportTypeBindings){
  ASTRewrite sourceRewriter=cloneInfo.sourceRewriter;
  AST ast=cloneInfo.ast;
  TypeDeclaration sourceTypeDeclaration=cloneInfo.sourceTypeDeclaration;
  for (  VariableDeclaration localFieldG1 : accessedLocalFieldsG1) {
    FieldDeclaration originalFieldDeclarationG1=(FieldDeclaration)localFieldG1.getParent();
    for (    VariableDeclaration localFieldG2 : accessedLocalFieldsG2) {
      FieldDeclaration originalFieldDeclarationG2=(FieldDeclaration)localFieldG2.getParent();
      if (localFieldG1.getName().getIdentifier().equals(localFieldG2.getName().getIdentifier())) {
        if (originalFieldDeclarationG1.getType().resolveBinding().isEqualTo(originalFieldDeclarationG2.getType().resolveBinding())) {
          boolean avoidPullUpDueToSerialization1=implementsSerializableInterface(sourceTypeDeclarations.get(0).resolveBinding()) && (localFieldG1.resolveBinding().getModifiers() & Modifier.TRANSIENT) == 0;
          boolean avoidPullUpDueToSerialization2=implementsSerializableInterface(sourceTypeDeclarations.get(1).resolveBinding()) && (localFieldG2.resolveBinding().getModifiers() & Modifier.TRANSIENT) == 0;
          if (!avoidPullUpDueToSerialization1 && !avoidPullUpDueToSerialization2) {
            if (!sourceTypeDeclarations.get(0).resolveBinding().isEqualTo(sourceTypeDeclaration.resolveBinding())) {
              fieldDeclarationsToBePulledUp.get(0).add(localFieldG1);
            }
            if (!sourceTypeDeclarations.get(1).resolveBinding().isEqualTo(sourceTypeDeclaration.resolveBinding())) {
              fieldDeclarationsToBePulledUp.get(1).add(localFieldG2);
            }
            if (!sourceTypeDeclarations.get(0).resolveBinding().isEqualTo(sourceTypeDeclaration.resolveBinding()) && !sourceTypeDeclarations.get(1).resolveBinding().isEqualTo(sourceTypeDeclaration.resolveBinding())) {
              Set<ITypeBinding> typeBindings=new LinkedHashSet<ITypeBinding>();
              typeBindings.add(localFieldG1.resolveBinding().getType());
              getSimpleTypeBindings(typeBindings,requiredImportTypeBindings);
              VariableDeclarationFragment fragment=ast.newVariableDeclarationFragment();
              sourceRewriter.set(fragment,VariableDeclarationFragment.NAME_PROPERTY,ast.newSimpleName(localFieldG1.getName().getIdentifier()),null);
              if (localFieldG1.getInitializer() != null && localFieldG2.getInitializer() != null) {
                Expression initializer1=localFieldG1.getInitializer();
                Expression initializer2=localFieldG2.getInitializer();
                if (initializer1.subtreeMatch(new ASTMatcher(),initializer2)) {
                  sourceRewriter.set(fragment,VariableDeclarationFragment.INITIALIZER_PROPERTY,ASTNode.copySubtree(ast,initializer1),null);
                }
              }
              FieldDeclaration newFieldDeclaration=ast.newFieldDeclaration(fragment);
              sourceRewriter.set(newFieldDeclaration,FieldDeclaration.TYPE_PROPERTY,originalFieldDeclarationG1.getType(),null);
              if (originalFieldDeclarationG1.getJavadoc() != null) {
                sourceRewriter.set(newFieldDeclaration,FieldDeclaration.JAVADOC_PROPERTY,originalFieldDeclarationG1.getJavadoc(),null);
              }
              ListRewrite newFieldDeclarationModifiersRewrite=sourceRewriter.getListRewrite(newFieldDeclaration,FieldDeclaration.MODIFIERS2_PROPERTY);
              newFieldDeclarationModifiersRewrite.insertLast(ast.newModifier(Modifier.ModifierKeyword.PROTECTED_KEYWORD),null);
              List<IExtendedModifier> originalModifiers=originalFieldDeclarationG1.modifiers();
              for (              IExtendedModifier extendedModifier : originalModifiers) {
                if (extendedModifier.isModifier()) {
                  Modifier modifier=(Modifier)extendedModifier;
                  if (modifier.isFinal()) {
                    newFieldDeclarationModifiersRewrite.insertLast(ast.newModifier(Modifier.ModifierKeyword.FINAL_KEYWORD),null);
                  }
 else                   if (modifier.isStatic()) {
                    newFieldDeclarationModifiersRewrite.insertLast(ast.newModifier(Modifier.ModifierKeyword.STATIC_KEYWORD),null);
                  }
 else                   if (modifier.isTransient()) {
                    newFieldDeclarationModifiersRewrite.insertLast(ast.newModifier(Modifier.ModifierKeyword.TRANSIENT_KEYWORD),null);
                  }
 else                   if (modifier.isVolatile()) {
                    newFieldDeclarationModifiersRewrite.insertLast(ast.newModifier(Modifier.ModifierKeyword.VOLATILE_KEYWORD),null);
                  }
                }
              }
              bodyDeclarationsRewrite.insertLast(newFieldDeclaration,null);
            }
          }
 else {
            fieldDeclarationsToBeParameterized.get(0).add(localFieldG1);
            fieldDeclarationsToBeParameterized.get(1).add(localFieldG2);
          }
          break;
        }
      }
    }
  }
}

Fixed version (ground truth):
private void pullUpLocallyAccessedFields(Set<VariableDeclaration> accessedLocalFieldsG1,Set<VariableDeclaration> accessedLocalFieldsG2,ListRewrite bodyDeclarationsRewrite,Set<ITypeBinding> requiredImportTypeBindings){
  ASTRewrite sourceRewriter=cloneInfo.sourceRewriter;
  AST ast=cloneInfo.ast;
  TypeDeclaration sourceTypeDeclaration=cloneInfo.sourceTypeDeclaration;
  for (  VariableDeclaration localFieldG1 : accessedLocalFieldsG1) {
    FieldDeclaration originalFieldDeclarationG1=(FieldDeclaration)localFieldG1.getParent();
    for (    VariableDeclaration localFieldG2 : accessedLocalFieldsG2) {
      FieldDeclaration originalFieldDeclarationG2=(FieldDeclaration)localFieldG2.getParent();
      if (localFieldG1.getName().getIdentifier().equals(localFieldG2.getName().getIdentifier())) {
        if (originalFieldDeclarationG1.getType().resolveBinding().isEqualTo(originalFieldDeclarationG2.getType().resolveBinding())) {
          boolean avoidPullUpDueToSerialization1=avoidPullUpFieldDueToSerialization(sourceTypeDeclarations.get(0),localFieldG1);
          boolean avoidPullUpDueToSerialization2=avoidPullUpFieldDueToSerialization(sourceTypeDeclarations.get(1),localFieldG2);
          if (!avoidPullUpDueToSerialization1 && !avoidPullUpDueToSerialization2) {
            if (!sourceTypeDeclarations.get(0).resolveBinding().isEqualTo(sourceTypeDeclaration.resolveBinding())) {
              fieldDeclarationsToBePulledUp.get(0).add(localFieldG1);
            }
            if (!sourceTypeDeclarations.get(1).resolveBinding().isEqualTo(sourceTypeDeclaration.resolveBinding())) {
              fieldDeclarationsToBePulledUp.get(1).add(localFieldG2);
            }
            if (!sourceTypeDeclarations.get(0).resolveBinding().isEqualTo(sourceTypeDeclaration.resolveBinding()) && !sourceTypeDeclarations.get(1).resolveBinding().isEqualTo(sourceTypeDeclaration.resolveBinding())) {
              Set<ITypeBinding> typeBindings=new LinkedHashSet<ITypeBinding>();
              typeBindings.add(localFieldG1.resolveBinding().getType());
              getSimpleTypeBindings(typeBindings,requiredImportTypeBindings);
              VariableDeclarationFragment fragment=ast.newVariableDeclarationFragment();
              sourceRewriter.set(fragment,VariableDeclarationFragment.NAME_PROPERTY,ast.newSimpleName(localFieldG1.getName().getIdentifier()),null);
              if (localFieldG1.getInitializer() != null && localFieldG2.getInitializer() != null) {
                Expression initializer1=localFieldG1.getInitializer();
                Expression initializer2=localFieldG2.getInitializer();
                if (initializer1.subtreeMatch(new ASTMatcher(),initializer2)) {
                  sourceRewriter.set(fragment,VariableDeclarationFragment.INITIALIZER_PROPERTY,ASTNode.copySubtree(ast,initializer1),null);
                }
              }
              FieldDeclaration newFieldDeclaration=ast.newFieldDeclaration(fragment);
              sourceRewriter.set(newFieldDeclaration,FieldDeclaration.TYPE_PROPERTY,originalFieldDeclarationG1.getType(),null);
              if (originalFieldDeclarationG1.getJavadoc() != null) {
                sourceRewriter.set(newFieldDeclaration,FieldDeclaration.JAVADOC_PROPERTY,originalFieldDeclarationG1.getJavadoc(),null);
              }
              ListRewrite newFieldDeclarationModifiersRewrite=sourceRewriter.getListRewrite(newFieldDeclaration,FieldDeclaration.MODIFIERS2_PROPERTY);
              newFieldDeclarationModifiersRewrite.insertLast(ast.newModifier(Modifier.ModifierKeyword.PROTECTED_KEYWORD),null);
              List<IExtendedModifier> originalModifiers=originalFieldDeclarationG1.modifiers();
              for (              IExtendedModifier extendedModifier : originalModifiers) {
                if (extendedModifier.isModifier()) {
                  Modifier modifier=(Modifier)extendedModifier;
                  if (modifier.isFinal()) {
                    newFieldDeclarationModifiersRewrite.insertLast(ast.newModifier(Modifier.ModifierKeyword.FINAL_KEYWORD),null);
                  }
 else                   if (modifier.isStatic()) {
                    newFieldDeclarationModifiersRewrite.insertLast(ast.newModifier(Modifier.ModifierKeyword.STATIC_KEYWORD),null);
                  }
 else                   if (modifier.isTransient()) {
                    newFieldDeclarationModifiersRewrite.insertLast(ast.newModifier(Modifier.ModifierKeyword.TRANSIENT_KEYWORD),null);
                  }
 else                   if (modifier.isVolatile()) {
                    newFieldDeclarationModifiersRewrite.insertLast(ast.newModifier(Modifier.ModifierKeyword.VOLATILE_KEYWORD),null);
                  }
                }
              }
              bodyDeclarationsRewrite.insertLast(newFieldDeclaration,null);
            }
          }
 else {
            fieldDeclarationsToBeParameterized.get(0).add(localFieldG1);
            fieldDeclarationsToBeParameterized.get(1).add(localFieldG2);
            Set<ITypeBinding> typeBindings=new LinkedHashSet<ITypeBinding>();
            typeBindings.add(localFieldG1.resolveBinding().getType());
            getSimpleTypeBindings(typeBindings,requiredImportTypeBindings);
          }
          break;
        }
      }
    }
  }
}