Program: 53874
Project: 53874
Buggy source:
/** 
 * This is slightly different from the normal Java language. Specifically, we explicitly handle synthetic fields that are part of nested/local classes. It boils down to the fact that we really HAVE to assign synthetic arguments to synthetic fields BEFORE calling the superclass constructor (because it might call you back polymorphically). In straight Java that glue code is a semantic error, because a this/super call must be the first statement of your constructor. On the upside, optimizations work the same on our synthetic fields as with any user fields. The order of emulation is: - assign all synthetic fields from synthetic args - call our super constructor emulation method - call our instance initializer emulation method - run user code
 */
void processConstructor(ConstructorDeclaration x){
  JConstructor ctor=(JConstructor)typeMap.get(x.binding);
  try {
    processHasAnnotations(ctor,x.annotations);
    SourceInfo info=ctor.getSourceInfo();
    currentMethod=ctor;
    currentMethodBody=ctor.getBody();
    currentMethodScope=x.scope;
    boolean hasExplicitThis=(x.constructorCall != null) && !x.constructorCall.isSuperAccess();
    JClassType enclosingType=ctor.getEnclosingType();
    JBlock block=currentMethodBody.getBlock();
    currentOuterThisRefParams=Maps.create();
    if (!hasExplicitThis) {
      ReferenceBinding declaringClass=x.binding.declaringClass;
      if (declaringClass instanceof NestedTypeBinding) {
        Iterator<JParameter> paramIt=currentMethod.getParams().iterator();
        NestedTypeBinding nestedBinding=(NestedTypeBinding)declaringClass;
        if (nestedBinding.enclosingInstances != null) {
          for (          SyntheticArgumentBinding arg : nestedBinding.enclosingInstances) {
            JParameter param=paramIt.next();
            if (arg.matchingField != null) {
              JField field=(JField)typeMap.get(arg);
              block.addStmt(JProgram.createAssignmentStmt(info,createVariableRef(info,field),createVariableRef(info,param)));
              currentOuterThisRefParams=Maps.put(currentOuterThisRefParams,field,param);
            }
          }
        }
        paramIt=getSyntheticLocalsIterator();
        if (nestedBinding.outerLocalVariables != null) {
          for (          SyntheticArgumentBinding arg : nestedBinding.outerLocalVariables) {
            JParameter param=paramIt.next();
            JField field=(JField)typeMap.get(arg);
            block.addStmt(JProgram.createAssignmentStmt(info,createVariableRef(info,field),createVariableRef(info,param)));
          }
        }
      }
    }
    if (x.constructorCall != null) {
      JMethodCall superOrThisCall=(JMethodCall)dispatch("String_Node_Str",x.constructorCall);
      if (enclosingType.isEnumOrSubclass() != null) {
        JVariableRef enumNameRef=createVariableRef(superOrThisCall.getSourceInfo(),ctor.getParams().get(0));
        superOrThisCall.addArg(0,enumNameRef);
        JVariableRef enumOrdinalRef=createVariableRef(superOrThisCall.getSourceInfo(),ctor.getParams().get(1));
        superOrThisCall.addArg(1,enumOrdinalRef);
      }
      superOrThisCall.setStaticDispatchOnly();
      block.addStmt(superOrThisCall.makeStatement());
    }
    JExpression thisRef=createThisRef(info,enclosingType);
    if (!hasExplicitThis) {
      JMethod initMethod=enclosingType.getMethods().get(1);
      JMethodCall initCall=new JMethodCall(info,thisRef,initMethod);
      block.addStmt(initCall.makeStatement());
    }
    block.addStmts(processStatements(x.statements));
    currentOuterThisRefParams=null;
    currentMethodScope=null;
    currentMethod=null;
  }
 catch (  Throwable e) {
    throw translateException(ctor,e);
  }
}

Fixed version (ground truth):
/** 
 * This is slightly different from the normal Java language. Specifically, we explicitly handle synthetic fields that are part of nested/local classes. It boils down to the fact that we really HAVE to assign synthetic arguments to synthetic fields BEFORE calling the superclass constructor (because it might call you back polymorphically). In straight Java that glue code is a semantic error, because a this/super call must be the first statement of your constructor. On the upside, optimizations work the same on our synthetic fields as with any user fields. The order of emulation is: - assign all synthetic fields from synthetic args - call our super constructor emulation method - call our instance initializer emulation method - run user code
 */
void processConstructor(ConstructorDeclaration x){
  JConstructor ctor=(JConstructor)typeMap.get(x.binding);
  try {
    processHasAnnotations(ctor,x.annotations);
    SourceInfo info=ctor.getSourceInfo();
    currentMethod=ctor;
    currentMethodBody=ctor.getBody();
    currentMethodScope=x.scope;
    boolean hasExplicitThis=(x.constructorCall != null) && !x.constructorCall.isSuperAccess();
    JClassType enclosingType=ctor.getEnclosingType();
    JBlock block=currentMethodBody.getBlock();
    currentOuterThisRefParams=Maps.create();
    ReferenceBinding declaringClass=x.binding.declaringClass;
    if (declaringClass instanceof NestedTypeBinding) {
      Iterator<JParameter> paramIt=currentMethod.getParams().iterator();
      NestedTypeBinding nestedBinding=(NestedTypeBinding)declaringClass;
      if (nestedBinding.enclosingInstances != null) {
        for (        SyntheticArgumentBinding arg : nestedBinding.enclosingInstances) {
          JParameter param=paramIt.next();
          JField field=(JField)typeMap.get(arg);
          if (!hasExplicitThis) {
            block.addStmt(JProgram.createAssignmentStmt(info,createVariableRef(info,field),createVariableRef(info,param)));
          }
          currentOuterThisRefParams=Maps.put(currentOuterThisRefParams,field,param);
        }
      }
      if (!hasExplicitThis) {
        paramIt=getSyntheticLocalsIterator();
        if (nestedBinding.outerLocalVariables != null) {
          for (          SyntheticArgumentBinding arg : nestedBinding.outerLocalVariables) {
            JParameter param=paramIt.next();
            JField field=(JField)typeMap.get(arg);
            block.addStmt(JProgram.createAssignmentStmt(info,createVariableRef(info,field),createVariableRef(info,param)));
          }
        }
      }
    }
    if (x.constructorCall != null) {
      JMethodCall superOrThisCall=(JMethodCall)dispatch("String_Node_Str",x.constructorCall);
      if (enclosingType.isEnumOrSubclass() != null) {
        JVariableRef enumNameRef=createVariableRef(superOrThisCall.getSourceInfo(),ctor.getParams().get(0));
        superOrThisCall.addArg(0,enumNameRef);
        JVariableRef enumOrdinalRef=createVariableRef(superOrThisCall.getSourceInfo(),ctor.getParams().get(1));
        superOrThisCall.addArg(1,enumOrdinalRef);
      }
      superOrThisCall.setStaticDispatchOnly();
      block.addStmt(superOrThisCall.makeStatement());
    }
    JExpression thisRef=createThisRef(info,enclosingType);
    if (!hasExplicitThis) {
      JMethod initMethod=enclosingType.getMethods().get(1);
      JMethodCall initCall=new JMethodCall(info,thisRef,initMethod);
      block.addStmt(initCall.makeStatement());
    }
    block.addStmts(processStatements(x.statements));
    currentOuterThisRefParams=null;
    currentMethodScope=null;
    currentMethod=null;
  }
 catch (  Throwable e) {
    throw translateException(ctor,e);
  }
}