Program: 27059
Project: 27059
Buggy source:
public void writeSaveDefinition(JavaWriter javaWriter,boolean isModelContainerDefinition,boolean isContentValues,AtomicInteger columnCount) throws IOException {
  if (columnType == Column.FOREIGN_KEY && isModel) {
    if (isModelContainer) {
      javaWriter.emitSingleLineComment("String_Node_Str");
    }
 else {
      javaWriter.emitSingleLineComment("String_Node_Str");
    }
    if (isModelContainerDefinition) {
      String modelContainerName=ModelUtils.getVariable(true) + columnFieldName;
      javaWriter.emitStatement("String_Node_Str",modelContainerName,ModelUtils.getVariable(true),ModelUtils.getVariable(true),columnFieldName,columnFieldType);
      if (saveModelForeignKey) {
        javaWriter.emitStatement("String_Node_Str",modelContainerName);
      }
      for (      ForeignKeyReference foreignKeyReference : foreignKeyReferences) {
        AdapterQueryBuilder adapterQueryBuilder=new AdapterQueryBuilder();
        if (!isContentValues) {
          adapterQueryBuilder.appendBindSQLiteStatement(columnCount.intValue(),ModelUtils.getClassFromAnnotation(foreignKeyReference));
        }
 else {
          adapterQueryBuilder.appendContentValues().appendPut(foreignKeyReference.columnName());
        }
        adapterQueryBuilder.appendCast(ModelUtils.getClassFromAnnotation(foreignKeyReference)).append(modelContainerName).append("String_Node_Str").appendGetValue(foreignKeyReference.foreignColumnName()).append("String_Node_Str");
        javaWriter.emitStatement(adapterQueryBuilder.getQuery());
        columnCount.incrementAndGet();
      }
    }
 else {
      String modelStatement=ModelUtils.getModelStatement(columnFieldName);
      javaWriter.beginControlFlow("String_Node_Str",modelStatement);
      if (saveModelForeignKey) {
        javaWriter.emitStatement("String_Node_Str",modelStatement);
      }
      List<AdapterQueryBuilder> elseNullPuts=new ArrayList<>();
      for (      ForeignKeyReference foreignKeyReference : foreignKeyReferences) {
        TypeMirror castedClass=ModelUtils.getTypeMirrorFromAnnotation(foreignKeyReference);
        ModelUtils.writeContentValueStatement(javaWriter,isContentValues,columnCount.intValue(),foreignKeyReference.columnName(),columnName,castedClass.toString(),foreignKeyReference.foreignColumnName(),foreignKeyReference.foreignColumnName(),false,isModelContainer,true,false,columnFieldType,castedClass.getKind().isPrimitive(),false);
        AdapterQueryBuilder adapterQueryBuilder=new AdapterQueryBuilder();
        if (isContentValues) {
          adapterQueryBuilder.appendContentValues();
          adapterQueryBuilder.append("String_Node_Str").appendParenthesisEnclosed("String_Node_Str" + foreignKeyReference.columnName() + "String_Node_Str");
        }
 else {
          adapterQueryBuilder.append("String_Node_Str");
          adapterQueryBuilder.append("String_Node_Str").appendParenthesisEnclosed(columnCount);
        }
        elseNullPuts.add(adapterQueryBuilder);
        columnCount.incrementAndGet();
      }
      javaWriter.nextControlFlow("String_Node_Str");
      for (      AdapterQueryBuilder queryBuilder : elseNullPuts) {
        javaWriter.emitStatement(queryBuilder.getQuery());
      }
      javaWriter.endControlFlow();
    }
    javaWriter.emitSingleLineComment("String_Node_Str");
    javaWriter.emitEmptyLine();
  }
 else {
    String newFieldType=null;
    if (hasTypeConverter) {
      TypeConverterDefinition typeConverterDefinition=manager.getTypeConverterDefinition(modelType);
      if (typeConverterDefinition == null) {
        manager.getMessager().printMessage(Diagnostic.Kind.ERROR,String.format("String_Node_Str",modelType));
      }
 else {
        newFieldType=typeConverterDefinition.getDbElement().asType().toString();
      }
    }
 else {
      newFieldType=columnFieldType;
    }
    String getType=columnFieldType;
    boolean isPrimitive=element.asType().getKind().isPrimitive();
    if (isPrimitive) {
      getType=manager.getTypeUtils().boxedClass((PrimitiveType)element.asType()).asType().toString();
    }
    if (isModelContainerDefinition) {
      if (element.asType().getKind().isPrimitive() && !hasTypeConverter) {
        newFieldType=manager.getTypeUtils().boxedClass((PrimitiveType)element.asType()).asType().toString();
      }
    }
    ModelUtils.writeContentValueStatement(javaWriter,isContentValues,columnCount.intValue(),columnName,columnName,newFieldType,columnFieldName,containerKeyName,isModelContainerDefinition,isModelContainer,false,hasTypeConverter,getType,isPrimitive,isBlob);
    columnCount.incrementAndGet();
  }
}

Fixed version (ground truth):
public void writeSaveDefinition(JavaWriter javaWriter,boolean isModelContainerDefinition,boolean isContentValues,AtomicInteger columnCount) throws IOException {
  if (columnType == Column.FOREIGN_KEY && isModel) {
    if (isModelContainer) {
      javaWriter.emitSingleLineComment("String_Node_Str");
    }
 else {
      javaWriter.emitSingleLineComment("String_Node_Str");
    }
    if (isModelContainerDefinition) {
      String modelContainerName=ModelUtils.getVariable(true) + columnFieldName;
      javaWriter.emitStatement("String_Node_Str",modelContainerName,ModelUtils.getVariable(true),ModelUtils.getVariable(true),columnFieldName,columnFieldType);
      if (saveModelForeignKey) {
        javaWriter.emitStatement("String_Node_Str",modelContainerName);
      }
      for (      ForeignKeyReference foreignKeyReference : foreignKeyReferences) {
        AdapterQueryBuilder adapterQueryBuilder=new AdapterQueryBuilder();
        AdapterQueryBuilder ifBuilder=new AdapterQueryBuilder().append(modelContainerName).append("String_Node_Str").appendGetValue(foreignKeyReference.foreignColumnName());
        javaWriter.beginControlFlow("String_Node_Str",ifBuilder.getQuery());
        if (!isContentValues) {
          adapterQueryBuilder.appendBindSQLiteStatement(columnCount.intValue(),ModelUtils.getClassFromAnnotation(foreignKeyReference));
        }
 else {
          adapterQueryBuilder.appendContentValues().appendPut(foreignKeyReference.columnName());
        }
        adapterQueryBuilder.appendCast(ModelUtils.getClassFromAnnotation(foreignKeyReference)).append(modelContainerName).append("String_Node_Str").appendGetValue(foreignKeyReference.foreignColumnName()).append("String_Node_Str");
        javaWriter.emitStatement(adapterQueryBuilder.getQuery());
        javaWriter.nextControlFlow("String_Node_Str");
        AdapterQueryBuilder elseNull=new AdapterQueryBuilder();
        if (isContentValues) {
          elseNull.appendContentValues();
          elseNull.append("String_Node_Str").appendParenthesisEnclosed("String_Node_Str" + foreignKeyReference.columnName() + "String_Node_Str");
        }
 else {
          elseNull.append("String_Node_Str");
          elseNull.append("String_Node_Str").appendParenthesisEnclosed(columnCount);
        }
        javaWriter.emitStatement(elseNull.getQuery());
        javaWriter.endControlFlow();
        columnCount.incrementAndGet();
      }
    }
 else {
      String modelStatement=ModelUtils.getModelStatement(columnFieldName);
      javaWriter.beginControlFlow("String_Node_Str",modelStatement);
      if (saveModelForeignKey) {
        javaWriter.emitStatement("String_Node_Str",modelStatement);
      }
      List<AdapterQueryBuilder> elseNullPuts=new ArrayList<>();
      for (      ForeignKeyReference foreignKeyReference : foreignKeyReferences) {
        TypeMirror castedClass=ModelUtils.getTypeMirrorFromAnnotation(foreignKeyReference);
        ModelUtils.writeContentValueStatement(javaWriter,isContentValues,columnCount.intValue(),foreignKeyReference.columnName(),columnName,castedClass.toString(),foreignKeyReference.foreignColumnName(),foreignKeyReference.foreignColumnName(),false,isModelContainer,true,false,columnFieldType,castedClass.getKind().isPrimitive(),false);
        AdapterQueryBuilder adapterQueryBuilder=new AdapterQueryBuilder();
        if (isContentValues) {
          adapterQueryBuilder.appendContentValues();
          adapterQueryBuilder.append("String_Node_Str").appendParenthesisEnclosed("String_Node_Str" + foreignKeyReference.columnName() + "String_Node_Str");
        }
 else {
          adapterQueryBuilder.append("String_Node_Str");
          adapterQueryBuilder.append("String_Node_Str").appendParenthesisEnclosed(columnCount);
        }
        elseNullPuts.add(adapterQueryBuilder);
        columnCount.incrementAndGet();
      }
      javaWriter.nextControlFlow("String_Node_Str");
      for (      AdapterQueryBuilder queryBuilder : elseNullPuts) {
        javaWriter.emitStatement(queryBuilder.getQuery());
      }
      javaWriter.endControlFlow();
    }
    javaWriter.emitSingleLineComment("String_Node_Str");
    javaWriter.emitEmptyLine();
  }
 else {
    String newFieldType=null;
    if (hasTypeConverter) {
      TypeConverterDefinition typeConverterDefinition=manager.getTypeConverterDefinition(modelType);
      if (typeConverterDefinition == null) {
        manager.getMessager().printMessage(Diagnostic.Kind.ERROR,String.format("String_Node_Str",modelType));
      }
 else {
        newFieldType=typeConverterDefinition.getDbElement().asType().toString();
      }
    }
 else {
      newFieldType=columnFieldType;
    }
    String getType=columnFieldType;
    boolean isPrimitive=element.asType().getKind().isPrimitive();
    if (isPrimitive) {
      getType=manager.getTypeUtils().boxedClass((PrimitiveType)element.asType()).asType().toString();
    }
    if (isModelContainerDefinition) {
      if (element.asType().getKind().isPrimitive() && !hasTypeConverter) {
        newFieldType=manager.getTypeUtils().boxedClass((PrimitiveType)element.asType()).asType().toString();
      }
    }
    ModelUtils.writeContentValueStatement(javaWriter,isContentValues,columnCount.intValue(),columnName,columnName,newFieldType,columnFieldName,containerKeyName,isModelContainerDefinition,isModelContainer,false,hasTypeConverter,getType,isPrimitive,isBlob);
    columnCount.incrementAndGet();
  }
}