Program: 135924
Project: 135924
Buggy source:
/** 
 * Processes the specification and collects information to be used by tools. The processing tries to use any customized module (Java class) to override the corresponding TLA+ module.
 */
protected final void processSpec(SpecObj spec){
  if (spec == null) {
    spec=new SpecObj(this.rootFile,resolver);
    if (TLCGlobals.tool) {
      MP.printMessage(EC.TLC_SANY_START);
    }
    try {
      SANY.frontEndMain(spec,this.rootFile,ToolIO.out);
    }
 catch (    FrontEndException e) {
      Assert.fail(EC.TLC_PARSING_FAILED2,e);
    }
    if (TLCGlobals.tool) {
      MP.printMessage(EC.TLC_SANY_END);
    }
  }
  if (!spec.initErrors.isSuccess() || !spec.parseErrors.isSuccess() || !spec.semanticErrors.isSuccess()) {
    Assert.fail(EC.TLC_PARSING_FAILED);
  }
  this.moduleTbl=spec.getExternalModuleTable();
  UniqueString rootName=UniqueString.uniqueStringOf(this.rootFile);
  this.rootModule=this.moduleTbl.getModuleNode(rootName);
  OpDeclNode[] varDecls=this.rootModule.getVariableDecls();
  this.variablesNodes=new OpDeclNode[varDecls.length];
  UniqueString[] varNames=new UniqueString[varDecls.length];
  for (int i=0; i < varDecls.length; i++) {
    this.variablesNodes[i]=varDecls[i];
    varNames[i]=varDecls[i].getName();
    varNames[i].setLoc(i);
  }
  TLCState.setVariables(this.variablesNodes);
  UniqueString.setVariableCount(varDecls.length);
  this.defns.setDefnCount(varDecls.length);
  this.defns.put("String_Node_Str",ValTrue);
  this.defns.put("String_Node_Str",ValFalse);
  Value[] elems=new Value[2];
  elems[0]=ValFalse;
  elems[1]=ValTrue;
  this.defns.put("String_Node_Str",new SetEnumValue(elems,true));
  Class stringModule=this.tlaClass.loadClass("String_Node_Str");
  if (stringModule == null) {
    Assert.fail(EC.TLC_STRING_MODULE_NOT_FOUND);
  }
  Method[] ms=stringModule.getDeclaredMethods();
  for (int i=0; i < ms.length; i++) {
    int mod=ms[i].getModifiers();
    if (Modifier.isStatic(mod)) {
      String name=TLARegistry.mapName(ms[i].getName());
      int acnt=ms[i].getParameterTypes().length;
      MethodValue mv=new MethodValue(ms[i]);
      Value val=(acnt == 0) ? mv.apply(EmptyArgs,EvalControl.Clear) : mv;
      this.defns.put(name,val);
    }
  }
  ModuleNode[] mods=this.moduleTbl.getModuleNodes();
  HashSet modSet=new HashSet();
  for (int i=0; i < mods.length; i++) {
    this.processConstants(mods[i]);
    modSet.add(mods[i].getName().toString());
  }
  AssumeNode[] assumes=this.rootModule.getAssumptions();
  this.assumptions=new ExprNode[assumes.length];
  this.assumptionIsAxiom=new boolean[assumes.length];
  for (int i=0; i < assumes.length; i++) {
    this.assumptions[i]=assumes[i].getAssume();
    this.assumptionIsAxiom[i]=assumes[i].getIsAxiom();
  }
  Hashtable constants=this.initializeConstants();
  Hashtable overrides=this.config.getOverrides();
  OpDeclNode[] rootConsts=this.rootModule.getConstantDecls();
  for (int i=0; i < rootConsts.length; i++) {
    UniqueString name=rootConsts[i].getName();
    Object val=constants.get(name.toString());
    if (val == null && !overrides.containsKey(name.toString())) {
      Assert.fail(EC.TLC_CONFIG_VALUE_NOT_ASSIGNED_TO_CONSTANT_PARAM,name.toString());
    }
    rootConsts[i].setToolObject(TLCGlobals.ToolId,val);
    this.defns.put(name,val);
  }
  OpDefNode[] rootOpDefs=this.rootModule.getOpDefs();
  for (int i=0; i < rootOpDefs.length; i++) {
    UniqueString name=rootOpDefs[i].getName();
    Object val=constants.get(name.toString());
    if (val == null) {
      this.defns.put(name,rootOpDefs[i]);
    }
 else {
      rootOpDefs[i].setToolObject(TLCGlobals.ToolId,val);
      this.defns.put(name,val);
    }
  }
  Hashtable modConstants=this.initializeModConstants();
  for (int i=0; i < mods.length; i++) {
    UniqueString modName=mods[i].getName();
    Hashtable mConsts=(Hashtable)modConstants.get(modName.toString());
    if (mConsts != null) {
      OpDefNode[] opDefs=mods[i].getOpDefs();
      for (int j=0; j < opDefs.length; j++) {
        UniqueString name=opDefs[j].getName();
        Object val=mConsts.get(name.toString());
        if (val != null) {
          opDefs[j].getBody().setToolObject(TLCGlobals.ToolId,val);
        }
      }
    }
  }
  for (int i=0; i < mods.length; i++) {
    UniqueString modName=mods[i].getName();
    Class userModule=this.tlaClass.loadClass(modName.toString());
    if (userModule != null) {
      Hashtable javaDefs=new Hashtable();
      Method[] mds=userModule.getDeclaredMethods();
      for (int j=0; j < mds.length; j++) {
        int mdf=mds[j].getModifiers();
        if (Modifier.isPublic(mdf) && Modifier.isStatic(mdf)) {
          String name=TLARegistry.mapName(mds[j].getName());
          UniqueString uname=UniqueString.uniqueStringOf(name);
          int acnt=mds[j].getParameterTypes().length;
          MethodValue mv=new MethodValue(mds[j]);
          boolean isConstant=(acnt == 0) && Modifier.isFinal(mdf);
          Value val=isConstant ? mv.apply(EmptyArgs,EvalControl.Clear) : mv;
          javaDefs.put(uname,val);
        }
      }
      OpDefNode[] opDefs=mods[i].getOpDefs();
      for (int j=0; j < opDefs.length; j++) {
        UniqueString uname=opDefs[j].getName();
        Object val=javaDefs.get(uname);
        if (val != null) {
          opDefs[j].getBody().setToolObject(TLCGlobals.ToolId,val);
          this.defns.put(uname,val);
        }
      }
    }
  }
  HashSet overriden=new HashSet();
  for (int i=0; i < rootConsts.length; i++) {
    UniqueString lhs=rootConsts[i].getName();
    String rhs=(String)overrides.get(lhs.toString());
    if (rhs != null) {
      if (overrides.containsKey(rhs)) {
        Assert.fail(EC.TLC_CONFIG_RHS_ID_APPEARED_AFTER_LHS_ID,rhs);
      }
      Object myVal=this.defns.get(rhs);
      if (myVal == null) {
        Assert.fail(EC.TLC_CONFIG_WRONG_SUBSTITUTION,new String[]{lhs.toString(),rhs});
      }
      rootConsts[i].setToolObject(TLCGlobals.ToolId,myVal);
      this.defns.put(lhs,myVal);
      overriden.add(lhs.toString());
    }
  }
  for (int i=0; i < rootOpDefs.length; i++) {
    UniqueString lhs=rootOpDefs[i].getName();
    String rhs=(String)overrides.get(lhs.toString());
    if (rhs != null) {
      if (overrides.containsKey(rhs)) {
        Assert.fail(EC.TLC_CONFIG_RHS_ID_APPEARED_AFTER_LHS_ID,rhs);
      }
      Object myVal=this.defns.get(rhs);
      if (myVal == null) {
        Assert.fail(EC.TLC_CONFIG_WRONG_SUBSTITUTION,new String[]{lhs.toString(),rhs});
      }
      if ((myVal instanceof OpDefNode) && rootOpDefs[i].getNumberOfArgs() != ((OpDefNode)myVal).getNumberOfArgs()) {
        Assert.fail(EC.TLC_CONFIG_WRONG_SUBSTITUTION_NUMBER_OF_ARGS,new String[]{lhs.toString(),rhs});
      }
      rootOpDefs[i].setToolObject(TLCGlobals.ToolId,myVal);
      this.defns.put(lhs,myVal);
      overriden.add(lhs.toString());
    }
  }
  Enumeration keys=overrides.keys();
  while (keys.hasMoreElements()) {
    Object key=keys.nextElement();
    if (!overriden.contains(key)) {
      Assert.fail(EC.TLC_CONFIG_ID_DOES_NOT_APPEAR_IN_SPEC,key.toString());
    }
  }
  Hashtable modOverrides=this.config.getModOverrides();
  for (int i=0; i < mods.length; i++) {
    UniqueString modName=mods[i].getName();
    Hashtable mDefs=(Hashtable)modOverrides.get(modName.toString());
    HashSet modOverriden=new HashSet();
    if (mDefs != null) {
      OpDefNode[] opDefs=mods[i].getOpDefs();
      for (int j=0; j < opDefs.length; j++) {
        UniqueString lhs=opDefs[j].getName();
        String rhs=(String)mDefs.get(lhs.toString());
        if (rhs != null) {
          if (mDefs.containsKey(rhs)) {
            Assert.fail(EC.TLC_CONFIG_RHS_ID_APPEARED_AFTER_LHS_ID,rhs);
          }
          Object myVal=this.defns.get(rhs);
          if (myVal == null) {
            Assert.fail(EC.TLC_CONFIG_WRONG_SUBSTITUTION,new String[]{lhs.toString(),rhs});
          }
          if ((myVal instanceof OpDefNode) && opDefs[j].getNumberOfArgs() != ((OpDefNode)myVal).getNumberOfArgs()) {
            Assert.fail(EC.TLC_CONFIG_WRONG_SUBSTITUTION_NUMBER_OF_ARGS,new String[]{lhs.toString(),rhs});
          }
          opDefs[j].getBody().setToolObject(TLCGlobals.ToolId,myVal);
          modOverriden.add(lhs.toString());
        }
      }
      Enumeration mkeys=mDefs.keys();
      while (mkeys.hasMoreElements()) {
        Object mkey=mkeys.nextElement();
        if (!modOverriden.contains(mkey)) {
          Assert.fail(EC.TLC_CONFIG_ID_DOES_NOT_APPEAR_IN_SPEC,mkey.toString());
        }
      }
    }
  }
  Enumeration modKeys=modOverrides.keys();
  while (modKeys.hasMoreElements()) {
    Object modName=modKeys.nextElement();
    if (!modSet.contains(modName)) {
      Assert.fail(EC.TLC_NO_MODULES,modName.toString());
    }
  }
}

Fixed version (ground truth):
/** 
 * Processes the specification and collects information to be used by tools. The processing tries to use any customized module (Java class) to override the corresponding TLA+ module.
 */
protected final void processSpec(SpecObj spec){
  if (spec == null) {
    spec=new SpecObj(this.rootFile,resolver);
    if (TLCGlobals.tool) {
      MP.printMessage(EC.TLC_SANY_START);
    }
    try {
      SANY.frontEndMain(spec,this.rootFile,ToolIO.out);
    }
 catch (    FrontEndException e) {
      Assert.fail(EC.TLC_PARSING_FAILED2,e);
    }
    if (TLCGlobals.tool) {
      MP.printMessage(EC.TLC_SANY_END);
    }
    MP.printMessage(EC.TLC_STARTING);
  }
  if (!spec.initErrors.isSuccess() || !spec.parseErrors.isSuccess() || !spec.semanticErrors.isSuccess()) {
    Assert.fail(EC.TLC_PARSING_FAILED);
  }
  this.moduleTbl=spec.getExternalModuleTable();
  UniqueString rootName=UniqueString.uniqueStringOf(this.rootFile);
  this.rootModule=this.moduleTbl.getModuleNode(rootName);
  OpDeclNode[] varDecls=this.rootModule.getVariableDecls();
  this.variablesNodes=new OpDeclNode[varDecls.length];
  UniqueString[] varNames=new UniqueString[varDecls.length];
  for (int i=0; i < varDecls.length; i++) {
    this.variablesNodes[i]=varDecls[i];
    varNames[i]=varDecls[i].getName();
    varNames[i].setLoc(i);
  }
  TLCState.setVariables(this.variablesNodes);
  UniqueString.setVariableCount(varDecls.length);
  this.defns.setDefnCount(varDecls.length);
  this.defns.put("String_Node_Str",ValTrue);
  this.defns.put("String_Node_Str",ValFalse);
  Value[] elems=new Value[2];
  elems[0]=ValFalse;
  elems[1]=ValTrue;
  this.defns.put("String_Node_Str",new SetEnumValue(elems,true));
  Class stringModule=this.tlaClass.loadClass("String_Node_Str");
  if (stringModule == null) {
    Assert.fail(EC.TLC_STRING_MODULE_NOT_FOUND);
  }
  Method[] ms=stringModule.getDeclaredMethods();
  for (int i=0; i < ms.length; i++) {
    int mod=ms[i].getModifiers();
    if (Modifier.isStatic(mod)) {
      String name=TLARegistry.mapName(ms[i].getName());
      int acnt=ms[i].getParameterTypes().length;
      MethodValue mv=new MethodValue(ms[i]);
      Value val=(acnt == 0) ? mv.apply(EmptyArgs,EvalControl.Clear) : mv;
      this.defns.put(name,val);
    }
  }
  ModuleNode[] mods=this.moduleTbl.getModuleNodes();
  HashSet modSet=new HashSet();
  for (int i=0; i < mods.length; i++) {
    this.processConstants(mods[i]);
    modSet.add(mods[i].getName().toString());
  }
  AssumeNode[] assumes=this.rootModule.getAssumptions();
  this.assumptions=new ExprNode[assumes.length];
  this.assumptionIsAxiom=new boolean[assumes.length];
  for (int i=0; i < assumes.length; i++) {
    this.assumptions[i]=assumes[i].getAssume();
    this.assumptionIsAxiom[i]=assumes[i].getIsAxiom();
  }
  Hashtable constants=this.initializeConstants();
  Hashtable overrides=this.config.getOverrides();
  OpDeclNode[] rootConsts=this.rootModule.getConstantDecls();
  for (int i=0; i < rootConsts.length; i++) {
    UniqueString name=rootConsts[i].getName();
    Object val=constants.get(name.toString());
    if (val == null && !overrides.containsKey(name.toString())) {
      Assert.fail(EC.TLC_CONFIG_VALUE_NOT_ASSIGNED_TO_CONSTANT_PARAM,name.toString());
    }
    rootConsts[i].setToolObject(TLCGlobals.ToolId,val);
    this.defns.put(name,val);
  }
  OpDefNode[] rootOpDefs=this.rootModule.getOpDefs();
  for (int i=0; i < rootOpDefs.length; i++) {
    UniqueString name=rootOpDefs[i].getName();
    Object val=constants.get(name.toString());
    if (val == null) {
      this.defns.put(name,rootOpDefs[i]);
    }
 else {
      rootOpDefs[i].setToolObject(TLCGlobals.ToolId,val);
      this.defns.put(name,val);
    }
  }
  Hashtable modConstants=this.initializeModConstants();
  for (int i=0; i < mods.length; i++) {
    UniqueString modName=mods[i].getName();
    Hashtable mConsts=(Hashtable)modConstants.get(modName.toString());
    if (mConsts != null) {
      OpDefNode[] opDefs=mods[i].getOpDefs();
      for (int j=0; j < opDefs.length; j++) {
        UniqueString name=opDefs[j].getName();
        Object val=mConsts.get(name.toString());
        if (val != null) {
          opDefs[j].getBody().setToolObject(TLCGlobals.ToolId,val);
        }
      }
    }
  }
  for (int i=0; i < mods.length; i++) {
    UniqueString modName=mods[i].getName();
    Class userModule=this.tlaClass.loadClass(modName.toString());
    if (userModule != null) {
      Hashtable javaDefs=new Hashtable();
      Method[] mds=userModule.getDeclaredMethods();
      for (int j=0; j < mds.length; j++) {
        int mdf=mds[j].getModifiers();
        if (Modifier.isPublic(mdf) && Modifier.isStatic(mdf)) {
          String name=TLARegistry.mapName(mds[j].getName());
          UniqueString uname=UniqueString.uniqueStringOf(name);
          int acnt=mds[j].getParameterTypes().length;
          MethodValue mv=new MethodValue(mds[j]);
          boolean isConstant=(acnt == 0) && Modifier.isFinal(mdf);
          Value val=isConstant ? mv.apply(EmptyArgs,EvalControl.Clear) : mv;
          javaDefs.put(uname,val);
        }
      }
      OpDefNode[] opDefs=mods[i].getOpDefs();
      for (int j=0; j < opDefs.length; j++) {
        UniqueString uname=opDefs[j].getName();
        Object val=javaDefs.get(uname);
        if (val != null) {
          opDefs[j].getBody().setToolObject(TLCGlobals.ToolId,val);
          this.defns.put(uname,val);
        }
      }
    }
  }
  HashSet overriden=new HashSet();
  for (int i=0; i < rootConsts.length; i++) {
    UniqueString lhs=rootConsts[i].getName();
    String rhs=(String)overrides.get(lhs.toString());
    if (rhs != null) {
      if (overrides.containsKey(rhs)) {
        Assert.fail(EC.TLC_CONFIG_RHS_ID_APPEARED_AFTER_LHS_ID,rhs);
      }
      Object myVal=this.defns.get(rhs);
      if (myVal == null) {
        Assert.fail(EC.TLC_CONFIG_WRONG_SUBSTITUTION,new String[]{lhs.toString(),rhs});
      }
      rootConsts[i].setToolObject(TLCGlobals.ToolId,myVal);
      this.defns.put(lhs,myVal);
      overriden.add(lhs.toString());
    }
  }
  for (int i=0; i < rootOpDefs.length; i++) {
    UniqueString lhs=rootOpDefs[i].getName();
    String rhs=(String)overrides.get(lhs.toString());
    if (rhs != null) {
      if (overrides.containsKey(rhs)) {
        Assert.fail(EC.TLC_CONFIG_RHS_ID_APPEARED_AFTER_LHS_ID,rhs);
      }
      Object myVal=this.defns.get(rhs);
      if (myVal == null) {
        Assert.fail(EC.TLC_CONFIG_WRONG_SUBSTITUTION,new String[]{lhs.toString(),rhs});
      }
      if ((myVal instanceof OpDefNode) && rootOpDefs[i].getNumberOfArgs() != ((OpDefNode)myVal).getNumberOfArgs()) {
        Assert.fail(EC.TLC_CONFIG_WRONG_SUBSTITUTION_NUMBER_OF_ARGS,new String[]{lhs.toString(),rhs});
      }
      rootOpDefs[i].setToolObject(TLCGlobals.ToolId,myVal);
      this.defns.put(lhs,myVal);
      overriden.add(lhs.toString());
    }
  }
  Enumeration keys=overrides.keys();
  while (keys.hasMoreElements()) {
    Object key=keys.nextElement();
    if (!overriden.contains(key)) {
      Assert.fail(EC.TLC_CONFIG_ID_DOES_NOT_APPEAR_IN_SPEC,key.toString());
    }
  }
  Hashtable modOverrides=this.config.getModOverrides();
  for (int i=0; i < mods.length; i++) {
    UniqueString modName=mods[i].getName();
    Hashtable mDefs=(Hashtable)modOverrides.get(modName.toString());
    HashSet modOverriden=new HashSet();
    if (mDefs != null) {
      OpDefNode[] opDefs=mods[i].getOpDefs();
      for (int j=0; j < opDefs.length; j++) {
        UniqueString lhs=opDefs[j].getName();
        String rhs=(String)mDefs.get(lhs.toString());
        if (rhs != null) {
          if (mDefs.containsKey(rhs)) {
            Assert.fail(EC.TLC_CONFIG_RHS_ID_APPEARED_AFTER_LHS_ID,rhs);
          }
          Object myVal=this.defns.get(rhs);
          if (myVal == null) {
            Assert.fail(EC.TLC_CONFIG_WRONG_SUBSTITUTION,new String[]{lhs.toString(),rhs});
          }
          if ((myVal instanceof OpDefNode) && opDefs[j].getNumberOfArgs() != ((OpDefNode)myVal).getNumberOfArgs()) {
            Assert.fail(EC.TLC_CONFIG_WRONG_SUBSTITUTION_NUMBER_OF_ARGS,new String[]{lhs.toString(),rhs});
          }
          opDefs[j].getBody().setToolObject(TLCGlobals.ToolId,myVal);
          modOverriden.add(lhs.toString());
        }
      }
      Enumeration mkeys=mDefs.keys();
      while (mkeys.hasMoreElements()) {
        Object mkey=mkeys.nextElement();
        if (!modOverriden.contains(mkey)) {
          Assert.fail(EC.TLC_CONFIG_ID_DOES_NOT_APPEAR_IN_SPEC,mkey.toString());
        }
      }
    }
  }
  Enumeration modKeys=modOverrides.keys();
  while (modKeys.hasMoreElements()) {
    Object modName=modKeys.nextElement();
    if (!modSet.contains(modName)) {
      Assert.fail(EC.TLC_NO_MODULES,modName.toString());
    }
  }
}