Program: 72149
Project: 72149
Buggy source:
/** 
 * A statement of the form <pre> for ( T v : arrayexpr ) stmt; </pre> (where arrayexpr is of an array type) gets translated to <pre> for ( { arraytype #arr = arrayexpr; int #len = array.length; int #i = 0; }; #i < #len; i$++ ) { T v = arr$[#i]; stmt; } </pre> where #arr, #len, and #i are freshly named synthetic local variables.
 */
private void visitArrayForeachLoop(JCEnhancedForLoop tree){
  make_at(tree.expr.pos());
  VarSymbol arraycache=new VarSymbol(0,names.fromString("String_Node_Str" + target.syntheticNameChar()),tree.expr.type,currentMethodSym);
  JCStatement arraycachedef=make.VarDef(arraycache,tree.expr);
  VarSymbol lencache=new VarSymbol(0,names.fromString("String_Node_Str" + target.syntheticNameChar()),syms.intType,currentMethodSym);
  JCStatement lencachedef=make.VarDef(lencache,make.Select(make.Ident(arraycache),syms.lengthVar));
  VarSymbol index=new VarSymbol(0,names.fromString("String_Node_Str" + target.syntheticNameChar()),syms.intType,currentMethodSym);
  JCVariableDecl indexdef=make.VarDef(index,make.Literal(INT,0));
  indexdef.init.type=indexdef.type=syms.intType.constType(0);
  List<JCStatement> loopinit=List.of(arraycachedef,lencachedef,indexdef);
  JCBinary cond=makeBinary(LT,make.Ident(index),make.Ident(lencache));
  JCExpressionStatement step=make.Exec(makeUnary(PREINC,make.Ident(index)));
  Type elemtype=types.elemtype(tree.expr.type);
  JCExpression loopvarinit=make.Indexed(make.Ident(arraycache),make.Ident(index)).setType(elemtype);
  JCVariableDecl loopvardef=(JCVariableDecl)make.VarDef(tree.var.mods,tree.var.name,tree.var.vartype,loopvarinit).setType(tree.var.type);
  loopvardef.sym=tree.var.sym;
  JCBlock body=make.Block(0,List.of(loopvardef,tree.body));
  result=translate(make.ForLoop(loopinit,cond,List.of(step),body));
  patchTargets(body,tree,result);
}

Fixed version (ground truth):
/** 
 * A statement of the form <pre> for ( T v : arrayexpr ) stmt; </pre> (where arrayexpr is of an array type) gets translated to <pre>  {@code}for (  arraytype #arr = arrayexpr; int #len = array.length; int #i = 0; }; #i < #len; i$++ ) { T v = arr$[#i]; stmt; } }</pre> where #arr, #len, and #i are freshly named synthetic local variables.
 */
private void visitArrayForeachLoop(JCEnhancedForLoop tree){
  make_at(tree.expr.pos());
  VarSymbol arraycache=new VarSymbol(0,names.fromString("String_Node_Str" + target.syntheticNameChar()),tree.expr.type,currentMethodSym);
  JCStatement arraycachedef=make.VarDef(arraycache,tree.expr);
  VarSymbol lencache=new VarSymbol(0,names.fromString("String_Node_Str" + target.syntheticNameChar()),syms.intType,currentMethodSym);
  JCStatement lencachedef=make.VarDef(lencache,make.Select(make.Ident(arraycache),syms.lengthVar));
  VarSymbol index=new VarSymbol(0,names.fromString("String_Node_Str" + target.syntheticNameChar()),syms.intType,currentMethodSym);
  JCVariableDecl indexdef=make.VarDef(index,make.Literal(INT,0));
  indexdef.init.type=indexdef.type=syms.intType.constType(0);
  List<JCStatement> loopinit=List.of(arraycachedef,lencachedef,indexdef);
  JCBinary cond=makeBinary(LT,make.Ident(index),make.Ident(lencache));
  JCExpressionStatement step=make.Exec(makeUnary(PREINC,make.Ident(index)));
  Type elemtype=types.elemtype(tree.expr.type);
  JCExpression loopvarinit=make.Indexed(make.Ident(arraycache),make.Ident(index)).setType(elemtype);
  JCVariableDecl loopvardef=(JCVariableDecl)make.VarDef(tree.var.mods,tree.var.name,tree.var.vartype,loopvarinit).setType(tree.var.type);
  loopvardef.sym=tree.var.sym;
  JCBlock body=make.Block(0,List.of(loopvardef,tree.body));
  result=translate(make.ForLoop(loopinit,cond,List.of(step),body));
  patchTargets(body,tree,result);
}