Program: 29349
Project: 29349
Buggy source:
/** 
 * Renders a   {@link com.google.template.soy.jbcsrc.shared.CompiledTemplate} incrementally.<p>Similar to  {@link #renderIncrementally(Expression,List,Label)}, we need to: <ul> <li>Stash the CompiledTemplate in a field   {@code $currentCallee}, so that if we detach halfway through rendering we don't lose the value. Note, we could use the scope/variable system of   {@link TemplateVariableManager} to manage this value, but we know there willonly ever be 1 live at a time, so we can just manage the single special field ourselves. <li>Either apply all the streaming autoescapers to the current appendable and, stash it in the  {@code $currentAppendable} field for the same reasons as above, or call {@link JbcSrcRuntime#applyEscapers} to apply non-streaming print directives.<li>Invoke  {@link com.google.template.soy.jbcsrc.shared.CompiledTemplate#render} with thestandard detach logic. <li>Clear the two fields once rendering is complete. </ul>
 * @param parametersReattachPoint The label where execution should resume if we need to detachwhile calculating parameters.
 * @param node The call node
 * @param calleeExpression The expression that resolves to a constructed instance of the template
 * @return A statement rendering the template.
 */
private Statement renderCallNode(Label parametersReattachPoint,CallNode node,Expression calleeExpression){
  Statement initAppendable=Statement.NULL_STATEMENT;
  Statement clearAppendable=Statement.NULL_STATEMENT;
  Expression appendable;
  FieldRef currentCalleeField=variables.getCurrentCalleeField();
  if (!areAllPrintDirectivesStreamable(node)) {
    calleeExpression=MethodRef.RUNTIME_APPLY_ESCAPERS.invoke(calleeExpression,getEscapingDirectivesList(node));
    appendable=appendableExpression;
  }
 else {
    AppendableAndOptions wrappedAppendable=applyStreamingEscapingDirectives(node.getEscapingDirectives(),appendableExpression,parameterLookup.getRenderContext());
    FieldRef currentAppendableField=variables.getCurrentAppendable();
    initAppendable=currentAppendableField.putInstanceField(thisVar,wrappedAppendable.appendable());
    appendable=currentAppendableField.accessor(thisVar);
    clearAppendable=currentAppendableField.putInstanceField(thisVar,constantNull(LOGGING_ADVISING_APPENDABLE_TYPE));
    if (wrappedAppendable.closeable()) {
      clearAppendable=Statement.concat(currentAppendableField.accessor(thisVar).checkedCast(BytecodeUtils.CLOSEABLE_TYPE).invokeVoid(MethodRef.CLOSEABLE_CLOSE),clearAppendable);
    }
  }
  Statement initCallee=currentCalleeField.putInstanceField(thisVar,calleeExpression).labelStart(parametersReattachPoint);
  Expression callRender=currentCalleeField.accessor(thisVar).invoke(MethodRef.COMPILED_TEMPLATE_RENDER,appendable,parameterLookup.getRenderContext());
  Statement callCallee=detachState.detachForRender(callRender);
  Statement clearCallee=currentCalleeField.putInstanceField(thisVar,BytecodeUtils.constantNull(COMPILED_TEMPLATE_TYPE));
  return Statement.concat(initAppendable,initCallee,callCallee,clearCallee,clearAppendable);
}

Fixed version (ground truth):
/** 
 * Renders a   {@link com.google.template.soy.jbcsrc.shared.CompiledTemplate} incrementally.<p>Similar to  {@link #renderIncrementally(Expression,List,Label)}, we need to: <ul> <li>Stash the CompiledTemplate in a field   {@code $currentCallee}, so that if we detach halfway through rendering we don't lose the value. Note, we could use the scope/variable system of   {@link TemplateVariableManager} to manage this value, but we know there willonly ever be 1 live at a time, so we can just manage the single special field ourselves. <li>Either apply all the streaming autoescapers to the current appendable and, stash it in the  {@code $currentAppendable} field for the same reasons as above, or call {@link JbcSrcRuntime#applyEscapers} to apply non-streaming print directives.<li>Invoke  {@link com.google.template.soy.jbcsrc.shared.CompiledTemplate#render} with thestandard detach logic. <li>Clear the two fields once rendering is complete. </ul>
 * @param parametersReattachPoint The label where execution should resume if we need to detachwhile calculating parameters.
 * @param node The call node
 * @param calleeExpression The expression that resolves to a constructed instance of the template
 * @return A statement rendering the template.
 */
private Statement renderCallNode(Label parametersReattachPoint,CallNode node,Expression calleeExpression){
  Statement initAppendable=Statement.NULL_STATEMENT;
  Statement clearAppendable=Statement.NULL_STATEMENT;
  Expression appendable;
  FieldRef currentCalleeField=variables.getCurrentCalleeField();
  if (!areAllPrintDirectivesStreamable(node)) {
    calleeExpression=MethodRef.RUNTIME_APPLY_ESCAPERS.invoke(calleeExpression,getEscapingDirectivesList(node));
    appendable=appendableExpression;
  }
 else {
    AppendableAndOptions wrappedAppendable=applyStreamingEscapingDirectives(node.getEscapingDirectives(),appendableExpression,parameterLookup.getRenderContext(),variables);
    FieldRef currentAppendableField=variables.getCurrentAppendable();
    initAppendable=currentAppendableField.putInstanceField(thisVar,wrappedAppendable.appendable());
    appendable=currentAppendableField.accessor(thisVar);
    clearAppendable=currentAppendableField.putInstanceField(thisVar,constantNull(LOGGING_ADVISING_APPENDABLE_TYPE));
    if (wrappedAppendable.closeable()) {
      clearAppendable=Statement.concat(currentAppendableField.accessor(thisVar).checkedCast(BytecodeUtils.CLOSEABLE_TYPE).invokeVoid(MethodRef.CLOSEABLE_CLOSE),clearAppendable);
    }
  }
  Statement initCallee=currentCalleeField.putInstanceField(thisVar,calleeExpression).labelStart(parametersReattachPoint);
  Expression callRender=currentCalleeField.accessor(thisVar).invoke(MethodRef.COMPILED_TEMPLATE_RENDER,appendable,parameterLookup.getRenderContext());
  Statement callCallee=detachState.detachForRender(callRender);
  Statement clearCallee=currentCalleeField.putInstanceField(thisVar,BytecodeUtils.constantNull(COMPILED_TEMPLATE_TYPE));
  return Statement.concat(initAppendable,initCallee,callCallee,clearCallee,clearAppendable);
}