Buggy code:
public class RealmProxyClassGenerator { private ProcessingEnvironment processingEnvironment ; private ClassMetaData metadata ; private final String className ; private Elements elementUtils ; private Types typeUtils ; private TypeMirror realmObject ; private DeclaredType realmList ; public RealmProxyClassGenerator ( ProcessingEnvironment processingEnvironment , ClassMetaData metadata ) { } private static final Map < String , String > JAVA_TO_REALM_TYPES ; private static final Map < String , String > NULLABLE_JAVA_TYPES ; private static final Map < String , String > JAVA_TO_COLUMN_TYPES ; private static final Map < String , String > CASTING_TYPES ; public void generate ( ) throws IOException , UnsupportedOperationException { } private void emitClassFields ( JavaWriter writer ) throws IOException { } private void emitAccessors ( JavaWriter writer ) throws IOException { } private void emitInitTableMethod ( JavaWriter writer ) throws IOException { } private void emitValidateTableMethod ( JavaWriter writer ) throws IOException { writer . beginMethod ( "void" , "validateTable" , EnumSet . of ( Modifier . PUBLIC , Modifier . STATIC ) , "ImplicitTransaction" , "transaction" ) ; writer . beginControlFlow ( ( ( ( "if(transaction.hasTable(\"" + ( Constants . TABLE_PREFIX ) ) + ( this . className ) ) + "\"))" ) ) ; writer . emitStatement ( "Table<seq2seq4repair_space>table<seq2seq4repair_space>=<seq2seq4repair_space>transaction.getTable(\"%s%s\")" , TABLE_PREFIX , this . className ) ; writer . beginControlFlow ( ( ( "if(table.getColumnCount()<seq2seq4repair_space>!=<seq2seq4repair_space>" + ( metadata . getFields ( ) . size ( ) ) ) + ")" ) ) ; <START_BUG> writer . emitStatement ( "throw<seq2seq4repair_space>new<seq2seq4repair_space>RealmMigrationNeededException(\"Column<seq2seq4repair_space>count<seq2seq4repair_space>does<seq2seq4repair_space>not<seq2seq4repair_space>match\")" ) ; <END_BUG> writer . endControlFlow ( ) ; writer . emitStatement ( "Map<String,<seq2seq4repair_space>ColumnType><seq2seq4repair_space>columnTypes<seq2seq4repair_space>=<seq2seq4repair_space>new<seq2seq4repair_space>HashMap<String,<seq2seq4repair_space>ColumnType>()" ) ; writer . beginControlFlow ( ( ( "for(long<seq2seq4repair_space>i<seq2seq4repair_space>=<seq2seq4repair_space>0;<seq2seq4repair_space>i<seq2seq4repair_space><<seq2seq4repair_space>" + ( metadata . getFields ( ) . size ( ) ) ) + ";<seq2seq4repair_space>i++)" ) ) ; writer . emitStatement ( "columnTypes.put(table.getColumnName(i),<seq2seq4repair_space>table.getColumnType(i))" ) ; writer . endControlFlow ( ) ; for ( VariableElement field : metadata . getFields ( ) ) { String fieldName = field . getSimpleName ( ) . toString ( ) ; String fieldTypeCanonicalName = field . asType ( ) . toString ( ) ; String fieldTypeSimpleName = Utils . getFieldTypeSimpleName ( field ) ; if ( RealmProxyClassGenerator . JAVA_TO_REALM_TYPES . containsKey ( fieldTypeCanonicalName ) ) { writer . beginControlFlow ( "if<seq2seq4repair_space>(!columnTypes.containsKey(\"%s\"))" , fieldName ) ; writer . emitStatement ( "throw<seq2seq4repair_space>new<seq2seq4repair_space>RealmMigrationNeededException(\"Missing<seq2seq4repair_space>field<seq2seq4repair_space>\'%s\'\")" , fieldName ) ; writer . endControlFlow ( ) ; writer . beginControlFlow ( "if<seq2seq4repair_space>(columnTypes.get(\"%s\")<seq2seq4repair_space>!=<seq2seq4repair_space>%s)" , fieldName , RealmProxyClassGenerator . JAVA_TO_COLUMN_TYPES . get ( fieldTypeCanonicalName ) ) ; writer . emitStatement ( "throw<seq2seq4repair_space>new<seq2seq4repair_space>RealmMigrationNeededException(\"Invalid<seq2seq4repair_space>type<seq2seq4repair_space>\'%s\'<seq2seq4repair_space>for<seq2seq4repair_space>field<seq2seq4repair_space>\'%s\'\")" , fieldTypeSimpleName , fieldName ) ; writer . endControlFlow ( ) ; if ( field . equals ( metadata . getPrimaryKey ( ) ) ) { writer . beginControlFlow ( "if<seq2seq4repair_space>(table.getPrimaryKey()<seq2seq4repair_space>!=<seq2seq4repair_space>table.getColumnIndex(\"%s\"))" , fieldName ) ; writer . emitStatement ( "throw<seq2seq4repair_space>new<seq2seq4repair_space>RealmMigrationNeededException(\"Primary<seq2seq4repair_space>key<seq2seq4repair_space>not<seq2seq4repair_space>defined<seq2seq4repair_space>for<seq2seq4repair_space>field<seq2seq4repair_space>\'%s\'\")" , fieldName ) ; writer . endControlFlow ( ) ; } if ( metadata . getIndexedFields ( ) . contains ( field ) ) { writer . beginControlFlow ( "if<seq2seq4repair_space>(!table.hasIndex(table.getColumnIndex(\"%s\")))" , fieldName ) ; writer . emitStatement ( "throw<seq2seq4repair_space>new<seq2seq4repair_space>RealmMigrationNeededException(\"Index<seq2seq4repair_space>not<seq2seq4repair_space>defined<seq2seq4repair_space>for<seq2seq4repair_space>field<seq2seq4repair_space>\'%s\'\")" , fieldName ) ; writer . endControlFlow ( ) ; } } else if ( typeUtils . isAssignable ( field . asType ( ) , realmObject ) ) { writer . beginControlFlow ( "if<seq2seq4repair_space>(!columnTypes.containsKey(\"%s\"))" , fieldName ) ; writer . emitStatement ( "throw<seq2seq4repair_space>new<seq2seq4repair_space>RealmMigrationNeededException(\"Missing<seq2seq4repair_space>field<seq2seq4repair_space>\'%s\'\")" , fieldName ) ; writer . endControlFlow ( ) ; writer . beginControlFlow ( "if<seq2seq4repair_space>(columnTypes.get(\"%s\")<seq2seq4repair_space>!=<seq2seq4repair_space>ColumnType.LINK)" , fieldName ) ; writer . emitStatement ( "throw<seq2seq4repair_space>new<seq2seq4repair_space>RealmMigrationNeededException(\"Invalid<seq2seq4repair_space>type<seq2seq4repair_space>\'%s\'<seq2seq4repair_space>for<seq2seq4repair_space>field<seq2seq4repair_space>\'%s\'\")" , fieldTypeSimpleName , fieldName ) ; writer . endControlFlow ( ) ; writer . beginControlFlow ( "if<seq2seq4repair_space>(!transaction.hasTable(\"%s%s\"))" , TABLE_PREFIX , fieldTypeSimpleName ) ; writer . emitStatement ( "throw<seq2seq4repair_space>new<seq2seq4repair_space>RealmMigrationNeededException(\"Missing<seq2seq4repair_space>class<seq2seq4repair_space>\'%s%s\'<seq2seq4repair_space>for<seq2seq4repair_space>field<seq2seq4repair_space>\'%s\'\")" , TABLE_PREFIX , fieldTypeSimpleName , fieldName ) ; writer . endControlFlow ( ) ; } else if ( typeUtils . isAssignable ( field . asType ( ) , realmList ) ) { String genericType = Utils . getGenericType ( field ) ; writer . beginControlFlow ( "if(!columnTypes.containsKey(\"%s\"))" , fieldName ) ; writer . emitStatement ( "throw<seq2seq4repair_space>new<seq2seq4repair_space>RealmMigrationNeededException(\"Missing<seq2seq4repair_space>field<seq2seq4repair_space>\'%s\'\")" , fieldName ) ; writer . endControlFlow ( ) ; writer . beginControlFlow ( "if(columnTypes.get(\"%s\")<seq2seq4repair_space>!=<seq2seq4repair_space>ColumnType.LINK_LIST)" , fieldName ) ; writer . emitStatement ( "throw<seq2seq4repair_space>new<seq2seq4repair_space>RealmMigrationNeededException(\"Invalid<seq2seq4repair_space>type<seq2seq4repair_space>\'%s\'<seq2seq4repair_space>for<seq2seq4repair_space>field<seq2seq4repair_space>\'%s\'\")" , genericType , fieldName ) ; writer . endControlFlow ( ) ; writer . beginControlFlow ( "if<seq2seq4repair_space>(!transaction.hasTable(\"%s%s\"))" , TABLE_PREFIX , genericType ) ; writer . emitStatement ( "throw<seq2seq4repair_space>new<seq2seq4repair_space>RealmMigrationNeededException(\"Missing<seq2seq4repair_space>class<seq2seq4repair_space>\'%s%s\'<seq2seq4repair_space>for<seq2seq4repair_space>field<seq2seq4repair_space>\'%s\'\")" , TABLE_PREFIX , genericType , fieldName ) ; writer . endControlFlow ( ) ; } } writer . emitEmptyLine ( ) ; writer . emitStatement ( "columnIndices<seq2seq4repair_space>=<seq2seq4repair_space>new<seq2seq4repair_space>HashMap<String,<seq2seq4repair_space>Long>()" ) ; writer . beginControlFlow ( "for<seq2seq4repair_space>(String<seq2seq4repair_space>fieldName<seq2seq4repair_space>:<seq2seq4repair_space>getFieldNames())" ) . emitStatement ( "long<seq2seq4repair_space>index<seq2seq4repair_space>=<seq2seq4repair_space>table.getColumnIndex(fieldName)" ) . beginControlFlow ( "if<seq2seq4repair_space>(index<seq2seq4repair_space>==<seq2seq4repair_space>-1)" ) . emitStatement ( "throw<seq2seq4repair_space>new<seq2seq4repair_space>RealmMigrationNeededException(\"Field<seq2seq4repair_space>\'\"<seq2seq4repair_space>+<seq2seq4repair_space>fieldName<seq2seq4repair_space>+<seq2seq4repair_space>\"\'<seq2seq4repair_space>not<seq2seq4repair_space>found<seq2seq4repair_space>for<seq2seq4repair_space>type<seq2seq4repair_space>%s\")" , metadata . getSimpleClassName ( ) ) . endControlFlow ( ) . emitStatement ( "columnIndices.put(fieldName,<seq2seq4repair_space>index)" ) . endControlFlow ( ) ; for ( VariableElement field : metadata . getFields ( ) ) { writer . emitStatement ( "%s<seq2seq4repair_space>=<seq2seq4repair_space>table.getColumnIndex(\"%s\")" , staticFieldIndexVarName ( field ) , field . getSimpleName ( ) . toString ( ) ) ; } writer . nextControlFlow ( "else" ) ; writer . emitStatement ( "throw<seq2seq4repair_space>new<seq2seq4repair_space>RealmMigrationNeededException(\"The<seq2seq4repair_space>%s<seq2seq4repair_space>class<seq2seq4repair_space>is<seq2seq4repair_space>missing<seq2seq4repair_space>from<seq2seq4repair_space>the<seq2seq4repair_space>schema<seq2seq4repair_space>for<seq2seq4repair_space>this<seq2seq4repair_space>Realm.\")" , metadata . getSimpleClassName ( ) ) ; writer . endControlFlow ( ) ; writer . endMethod ( ) ; writer . emitEmptyLine ( ) ; } private void emitGetTableNameMethod ( JavaWriter writer ) throws IOException { } private void emitGetFieldNamesMethod ( JavaWriter writer ) throws IOException { } private void emitGetColumnIndicesMethod ( JavaWriter writer ) throws IOException { } private void emitCopyOrUpdateMethod ( JavaWriter writer ) throws IOException { } private void emitCopyMethod ( JavaWriter writer ) throws IOException { } private void emitUpdateMethod ( JavaWriter writer ) throws IOException { } private void emitToStringMethod ( JavaWriter writer ) throws IOException { } private void emitHashcodeMethod ( JavaWriter writer ) throws IOException { } private void emitEqualsMethod ( JavaWriter writer ) throws IOException { } private void emitPopulateUsingJsonObjectMethod ( JavaWriter writer ) throws IOException { } private void emitPopulateUsingJsonStreamMethod ( JavaWriter writer ) throws IOException { } private String staticFieldIndexVarName ( VariableElement variableElement ) { } }

Fix:
writer . emitStatement ( "throw<seq2seq4repair_space>new<seq2seq4repair_space>RealmMigrationNeededException(\"Field<seq2seq4repair_space>count<seq2seq4repair_space>does<seq2seq4repair_space>not<seq2seq4repair_space>match\")" ) ;