Program: 72154
Project: 72154
Buggy source:
/** 
 * A statement of the form <pre> for ( T v : coll ) stmt ; </pre> (where coll implements Iterable<? extends T>) gets translated to <pre> for ( Iterator<? extends T> #i = coll.iterator(); #i.hasNext(); ) { T v = (T) #i.next(); stmt; } </pre> where #i is a freshly named synthetic local variable.
 */
private void visitIterableForeachLoop(JCEnhancedForLoop tree){
  make_at(tree.expr.pos());
  Type iteratorTarget=syms.objectType;
  Type iterableType=types.asSuper(types.upperBound(tree.expr.type),syms.iterableType.tsym);
  if (iterableType.getTypeArguments().nonEmpty())   iteratorTarget=types.erasure(iterableType.getTypeArguments().head);
  Type eType=tree.expr.type;
  tree.expr.type=types.erasure(eType);
  if (eType.tag == TYPEVAR && eType.getUpperBound().isCompound())   tree.expr=make.TypeCast(types.erasure(iterableType),tree.expr);
  Symbol iterator=lookupMethod(tree.expr.pos(),names.iterator,types.erasure(syms.iterableType),List.<Type>nil());
  VarSymbol itvar=new VarSymbol(0,names.fromString("String_Node_Str" + target.syntheticNameChar()),types.erasure(iterator.type.getReturnType()),currentMethodSym);
  JCStatement init=make.VarDef(itvar,make.App(make.Select(tree.expr,iterator)));
  Symbol hasNext=lookupMethod(tree.expr.pos(),names.hasNext,itvar.type,List.<Type>nil());
  JCMethodInvocation cond=make.App(make.Select(make.Ident(itvar),hasNext));
  Symbol next=lookupMethod(tree.expr.pos(),names.next,itvar.type,List.<Type>nil());
  JCExpression vardefinit=make.App(make.Select(make.Ident(itvar),next));
  if (tree.var.type.isPrimitive())   vardefinit=make.TypeCast(types.upperBound(iteratorTarget),vardefinit);
 else   vardefinit=make.TypeCast(tree.var.type,vardefinit);
  JCVariableDecl indexDef=(JCVariableDecl)make.VarDef(tree.var.mods,tree.var.name,tree.var.vartype,vardefinit).setType(tree.var.type);
  indexDef.sym=tree.var.sym;
  JCBlock body=make.Block(0,List.of(indexDef,tree.body));
  body.endpos=TreeInfo.endPos(tree.body);
  result=translate(make.ForLoop(List.of(init),cond,List.<JCExpressionStatement>nil(),body));
  patchTargets(body,tree,result);
}

Fixed version (ground truth):
/** 
 * A statement of the form <pre> for ( T v : coll ) stmt ; </pre> (where coll implements   {@code Iterable<? extends T>}) gets translated to <pre>  {@code}for ( Iterator<? extends T> #i = coll.iterator(); #i.hasNext(); )  T v = (T) #i.next(); stmt; } }</pre> where #i is a freshly named synthetic local variable.
 */
private void visitIterableForeachLoop(JCEnhancedForLoop tree){
  make_at(tree.expr.pos());
  Type iteratorTarget=syms.objectType;
  Type iterableType=types.asSuper(types.upperBound(tree.expr.type),syms.iterableType.tsym);
  if (iterableType.getTypeArguments().nonEmpty())   iteratorTarget=types.erasure(iterableType.getTypeArguments().head);
  Type eType=tree.expr.type;
  tree.expr.type=types.erasure(eType);
  if (eType.tag == TYPEVAR && eType.getUpperBound().isCompound())   tree.expr=make.TypeCast(types.erasure(iterableType),tree.expr);
  Symbol iterator=lookupMethod(tree.expr.pos(),names.iterator,types.erasure(syms.iterableType),List.<Type>nil());
  VarSymbol itvar=new VarSymbol(0,names.fromString("String_Node_Str" + target.syntheticNameChar()),types.erasure(iterator.type.getReturnType()),currentMethodSym);
  JCStatement init=make.VarDef(itvar,make.App(make.Select(tree.expr,iterator)));
  Symbol hasNext=lookupMethod(tree.expr.pos(),names.hasNext,itvar.type,List.<Type>nil());
  JCMethodInvocation cond=make.App(make.Select(make.Ident(itvar),hasNext));
  Symbol next=lookupMethod(tree.expr.pos(),names.next,itvar.type,List.<Type>nil());
  JCExpression vardefinit=make.App(make.Select(make.Ident(itvar),next));
  if (tree.var.type.isPrimitive())   vardefinit=make.TypeCast(types.upperBound(iteratorTarget),vardefinit);
 else   vardefinit=make.TypeCast(tree.var.type,vardefinit);
  JCVariableDecl indexDef=(JCVariableDecl)make.VarDef(tree.var.mods,tree.var.name,tree.var.vartype,vardefinit).setType(tree.var.type);
  indexDef.sym=tree.var.sym;
  JCBlock body=make.Block(0,List.of(indexDef,tree.body));
  body.endpos=TreeInfo.endPos(tree.body);
  result=translate(make.ForLoop(List.of(init),cond,List.<JCExpressionStatement>nil(),body));
  patchTargets(body,tree,result);
}