Program: 39533
Project: 39533
Buggy source:
/** 
 * @param script
 * @param eventBehaviors
 * @param behaviorContext
 * @return A javascript function definition for the specified event thatcombines the given eventScript and any "behavior" script attached to the event.
 */
protected static String buildFunction(String eventScript,List<ClientBehavior> eventBehaviors,ClientBehaviorContext behaviorContext){
  if ((null != eventScript) && eventScript.isEmpty()) {
    eventScript=null;
  }
  ArrayList<String> behaviorScripts=null;
  if (null != eventBehaviors && !eventBehaviors.isEmpty()) {
    behaviorScripts=new ArrayList<String>(eventBehaviors.size());
    for (    ClientBehavior behavior : eventBehaviors) {
      String script=behavior.getScript(behaviorContext);
      if (null != script) {
        if (!(behavior instanceof BehaviorBase)) {
          UIComponent comp=behaviorContext.getComponent();
          if (comp instanceof DojoWidget) {
            if (comp instanceof ActionSource2) {
              script=script.replaceAll("String_Node_Str","String_Node_Str" + comp.getClientId() + "String_Node_Str");
            }
 else {
              String jsfNode=((DojoWidget)comp).getJsfNode();
              if (jsfNode != null && jsfNode.length() > 0) {
                script=script.replaceAll("String_Node_Str","String_Node_Str" + jsfNode);
              }
            }
          }
        }
        behaviorScripts.add(script);
      }
    }
  }
  StringBuilder functionDeclaration=new StringBuilder("String_Node_Str");
  if ((null != eventScript && (null != behaviorScripts && !behaviorScripts.isEmpty())) || (null != behaviorScripts && behaviorScripts.size() > 1)) {
    functionDeclaration.append("String_Node_Str");
    boolean needComma=false;
    if (null != eventScript) {
      functionDeclaration.append("String_Node_Str").append(eventScript).append("String_Node_Str");
      needComma=true;
    }
    for (    String script : behaviorScripts) {
      if (needComma) {
        functionDeclaration.append(',');
      }
 else {
        needComma=true;
      }
      functionDeclaration.append("String_Node_Str").append(script).append("String_Node_Str");
    }
    functionDeclaration.append("String_Node_Str");
  }
 else   if (null != eventScript) {
    functionDeclaration.append(eventScript);
  }
 else   if (null != behaviorScripts && !behaviorScripts.isEmpty()) {
    functionDeclaration.append(behaviorScripts.get(0));
  }
 else {
    return null;
  }
  functionDeclaration.append('}');
  return functionDeclaration.toString();
}

Fixed version (ground truth):
/** 
 * @param script
 * @param eventBehaviors
 * @param behaviorContext
 * @return A javascript function definition for the specified event thatcombines the given eventScript and any "behavior" script attached to the event.
 */
protected static String buildFunction(String eventScript,List<ClientBehavior> eventBehaviors,ClientBehaviorContext behaviorContext){
  if ((null != eventScript) && eventScript.isEmpty()) {
    eventScript=null;
  }
  ArrayList<String> behaviorScripts=null;
  boolean containsAjaxBehavior=false;
  if (null != eventBehaviors && !eventBehaviors.isEmpty()) {
    behaviorScripts=new ArrayList<String>(eventBehaviors.size());
    for (    ClientBehavior behavior : eventBehaviors) {
      String script=behavior.getScript(behaviorContext);
      if (null != script) {
        if (!(behavior instanceof BehaviorBase)) {
          UIComponent comp=behaviorContext.getComponent();
          if (comp instanceof DojoWidget) {
            if (comp instanceof ActionSource2) {
              script=script.replaceAll("String_Node_Str","String_Node_Str" + comp.getClientId() + "String_Node_Str");
            }
 else {
              String jsfNode=((DojoWidget)comp).getJsfNode();
              if (jsfNode != null && jsfNode.length() > 0) {
                script=script.replaceAll("String_Node_Str","String_Node_Str" + jsfNode);
              }
            }
          }
        }
        if (behavior instanceof AjaxBehavior) {
          containsAjaxBehavior=true;
        }
        behaviorScripts.add(script);
      }
    }
  }
  StringBuilder functionDeclaration=new StringBuilder("String_Node_Str");
  if ((null != eventScript && (null != behaviorScripts && !behaviorScripts.isEmpty())) || (null != behaviorScripts && behaviorScripts.size() > 1)) {
    functionDeclaration.append("String_Node_Str");
    if (!containsAjaxBehavior) {
      functionDeclaration.append("String_Node_Str");
    }
    functionDeclaration.append("String_Node_Str");
    boolean needComma=false;
    if (null != eventScript) {
      functionDeclaration.append("String_Node_Str").append(eventScript).append("String_Node_Str");
      needComma=true;
    }
    for (    String script : behaviorScripts) {
      if (needComma) {
        functionDeclaration.append(',');
      }
 else {
        needComma=true;
      }
      functionDeclaration.append("String_Node_Str").append(script).append("String_Node_Str");
    }
    functionDeclaration.append("String_Node_Str");
  }
 else   if (null != eventScript) {
    functionDeclaration.append(eventScript);
  }
 else   if (null != behaviorScripts && !behaviorScripts.isEmpty()) {
    functionDeclaration.append(behaviorScripts.get(0));
  }
 else {
    return null;
  }
  if (containsAjaxBehavior) {
    functionDeclaration.append("String_Node_Str");
  }
  functionDeclaration.append('}');
  return functionDeclaration.toString();
}