Program: 19492
Project: 19492
Buggy source:
/** 
 * Creates module objects from a list of module specifications.
 * @param specs A list of module specifications, not null or empty. The specformat is: <code>name:num-js-files[:[dep,...][:]]</code>. Module names must not contain the ':' character.
 * @param inputs A list of JS file paths, not null
 * @return An array of module objects
 */
List<JSModule> createJsModules(List<String> specs,List<SourceFile> inputs) throws FlagUsageException, IOException {
  if (isInTestMode()) {
    return modulesSupplierForTesting.get();
  }
  Preconditions.checkState(specs != null);
  Preconditions.checkState(!specs.isEmpty());
  Preconditions.checkState(inputs != null);
  List<String> moduleNames=new ArrayList<>(specs.size());
  Map<String,JSModule> modulesByName=new LinkedHashMap<>();
  Map<String,Integer> modulesFileCountMap=new LinkedHashMap<>();
  int numJsFilesExpected=0, minJsFilesRequired=0;
  boolean isFirstModule=true;
  for (  String spec : specs) {
    String[] parts=spec.split("String_Node_Str");
    if (parts.length < 2 || parts.length > 4) {
      throw new FlagUsageException("String_Node_Str" + "String_Node_Str" + spec);
    }
    String name=parts[0];
    checkModuleName(name);
    if (modulesByName.containsKey(name)) {
      throw new FlagUsageException("String_Node_Str" + name);
    }
    JSModule module=new JSModule(name);
    if (parts.length > 2) {
      String depList=parts[2];
      if (depList.length() > 0) {
        String[] deps=depList.split("String_Node_Str");
        for (        String dep : deps) {
          JSModule other=modulesByName.get(dep);
          if (other == null) {
            throw new FlagUsageException("String_Node_Str" + name + "String_Node_Str"+ dep+ "String_Node_Str");
          }
          module.addDependency(other);
        }
      }
    }
    int numJsFiles=-1;
    try {
      numJsFiles=Integer.parseInt(parts[1]);
    }
 catch (    NumberFormatException ignored) {
      numJsFiles=-1;
    }
    if (numJsFiles < 0) {
      if (parts.length == 2 && "String_Node_Str".equals(parts[1])) {
        if (isFirstModule) {
          numJsFilesExpected=-1;
        }
 else {
          throw new FlagUsageException("String_Node_Str" + parts[1] + "String_Node_Str"+ name+ "String_Node_Str"+ "String_Node_Str");
        }
      }
 else {
        throw new FlagUsageException("String_Node_Str" + parts[1] + "String_Node_Str"+ name);
      }
    }
 else {
      minJsFilesRequired+=numJsFiles;
    }
    if (numJsFilesExpected >= 0) {
      numJsFilesExpected+=numJsFiles;
    }
    moduleNames.add(0,name);
    modulesFileCountMap.put(name,numJsFiles);
    modulesByName.put(name,module);
  }
  final int totalNumJsFiles=inputs.size();
  if (numJsFilesExpected >= 0 || minJsFilesRequired > totalNumJsFiles) {
    if (minJsFilesRequired > totalNumJsFiles) {
      numJsFilesExpected=minJsFilesRequired;
    }
    if (numJsFilesExpected > totalNumJsFiles) {
      throw new FlagUsageException("String_Node_Str" + numJsFilesExpected + "String_Node_Str"+ totalNumJsFiles);
    }
 else     if (numJsFilesExpected < totalNumJsFiles) {
      throw new FlagUsageException("String_Node_Str" + numJsFilesExpected + "String_Node_Str"+ totalNumJsFiles);
    }
  }
  int numJsFilesLeft=totalNumJsFiles, moduleIndex=0;
  for (  String moduleName : moduleNames) {
    int numJsFiles=modulesFileCountMap.get(moduleName);
    JSModule module=modulesByName.get(moduleName);
    if (moduleIndex == moduleNames.size() - 1 && numJsFiles == -1) {
      numJsFiles=numJsFilesLeft;
    }
    List<SourceFile> moduleFiles=inputs.subList(numJsFilesLeft - numJsFiles,numJsFilesLeft);
    for (    SourceFile input : moduleFiles) {
      module.add(input);
    }
    numJsFilesLeft-=numJsFiles;
    moduleIndex++;
  }
  return new ArrayList<>(modulesByName.values());
}

Fixed version (ground truth):
/** 
 * Creates module objects from a list of js module specifications.
 * @param specs A list of js module specifications, not null or empty.
 * @param inputs A list of JS file paths, not null
 * @return An array of module objects
 */
List<JSModule> createJsModules(List<JsModuleSpec> specs,List<SourceFile> inputs) throws FlagUsageException, IOException {
  if (isInTestMode()) {
    return modulesSupplierForTesting.get();
  }
  Preconditions.checkState(specs != null);
  Preconditions.checkState(!specs.isEmpty());
  Preconditions.checkState(inputs != null);
  List<String> moduleNames=new ArrayList<>(specs.size());
  Map<String,JSModule> modulesByName=new LinkedHashMap<>();
  Map<String,Integer> modulesFileCountMap=new LinkedHashMap<>();
  int numJsFilesExpected=0, minJsFilesRequired=0;
  for (  JsModuleSpec spec : specs) {
    checkModuleName(spec.name);
    if (modulesByName.containsKey(spec.name)) {
      throw new FlagUsageException("String_Node_Str" + spec.name);
    }
    JSModule module=new JSModule(spec.name);
    for (    String dep : spec.deps) {
      JSModule other=modulesByName.get(dep);
      if (other == null) {
        throw new FlagUsageException("String_Node_Str" + spec.name + "String_Node_Str"+ dep+ "String_Node_Str");
      }
      module.addDependency(other);
    }
    if (spec.numJsFiles < 0) {
      numJsFilesExpected=-1;
    }
 else {
      minJsFilesRequired+=spec.numJsFiles;
    }
    if (numJsFilesExpected >= 0) {
      numJsFilesExpected+=spec.numJsFiles;
    }
    moduleNames.add(0,spec.name);
    modulesFileCountMap.put(spec.name,spec.numJsFiles);
    modulesByName.put(spec.name,module);
  }
  final int totalNumJsFiles=inputs.size();
  if (numJsFilesExpected >= 0 || minJsFilesRequired > totalNumJsFiles) {
    if (minJsFilesRequired > totalNumJsFiles) {
      numJsFilesExpected=minJsFilesRequired;
    }
    if (numJsFilesExpected > totalNumJsFiles) {
      throw new FlagUsageException("String_Node_Str" + numJsFilesExpected + "String_Node_Str"+ totalNumJsFiles);
    }
 else     if (numJsFilesExpected < totalNumJsFiles) {
      throw new FlagUsageException("String_Node_Str" + numJsFilesExpected + "String_Node_Str"+ totalNumJsFiles);
    }
  }
  int numJsFilesLeft=totalNumJsFiles, moduleIndex=0;
  for (  String moduleName : moduleNames) {
    int numJsFiles=modulesFileCountMap.get(moduleName);
    JSModule module=modulesByName.get(moduleName);
    if (moduleIndex == moduleNames.size() - 1 && numJsFiles == -1) {
      numJsFiles=numJsFilesLeft;
    }
    List<SourceFile> moduleFiles=inputs.subList(numJsFilesLeft - numJsFiles,numJsFilesLeft);
    for (    SourceFile input : moduleFiles) {
      module.add(input);
    }
    numJsFilesLeft-=numJsFiles;
    moduleIndex++;
  }
  return new ArrayList<>(modulesByName.values());
}