Program: 136149
Project: 136149
Buggy source:
/** 
 * Parses console outputs produced during the run of SANY and transform them into error object, which are stored inside the specification object <br> <b>Note:</b> this method is based on the status of the spec (  {@link Spec#getStatus()}) and cleans up the error objects   {@link ParseHandler#parseErrors} and {@link ParseHandler#semanticErrors}
 * @param spec specification handle
 */
private void processParsingErrors(Spec spec,IProgressMonitor monitor){
switch (spec.getStatus()) {
case IParseConstants.SYNTAX_ERROR:
    String[] output=ToolIO.getAllMessages();
  int nextMsg=0;
while ((nextMsg < output.length) && (output[nextMsg].indexOf("String_Node_Str") != -1)) {
  nextMsg++;
}
if ((nextMsg != 0) && (nextMsg != output.length)) {
int parsingModuleIndex=output[nextMsg - 1].indexOf("String_Node_Str") + 15;
IFile module=spec.findModule(output[nextMsg - 1].substring(parsingModuleIndex,output[nextMsg - 1].indexOf("String_Node_Str",parsingModuleIndex + 1)));
int[] coordinates=null;
String message=output[nextMsg];
if ((message.indexOf("String_Node_Str") != -1) || (message.indexOf("String_Node_Str") != -1)) {
  int[] val=findLineAndColumn(0,message);
  int beginLine=val[0];
  int beginColumn=val[1];
  int endLine=0;
  int endColumn=0;
  val=findLineAndColumn(val[2],message);
  if ((val[0] > beginLine) || ((val[0] == beginLine) && (val[1] >= beginColumn))) {
    endLine=val[0];
    endColumn=val[1];
  }
  coordinates=new int[]{beginLine,beginColumn,endLine,endColumn};
  TLAMarkerHelper.installProblemMarkerOnModule(module,IMarker.SEVERITY_ERROR,coordinates,message,monitor);
}
 else {
  if (parseErrors != null) {
    String[] aborts=parseErrors.getAborts();
    if (aborts.length > 0) {
      message=aborts[0];
    }
  }
  if (message != null && message.indexOf("String_Node_Str") == -1) {
    coordinates=new int[]{-1,-1,-1,-1};
  }
 else {
    throw new RuntimeException("String_Node_Str");
  }
  if (module == null) {
    TLAMarkerHelper.installProblemMarkerOnSpec(spec,IMarker.SEVERITY_ERROR,coordinates,message,monitor);
  }
 else {
    TLAMarkerHelper.installProblemMarkerOnModule(module,IMarker.SEVERITY_ERROR,coordinates,message,monitor);
  }
}
}
 else {
throw new RuntimeException("String_Node_Str" + "String_Node_Str");
}
break;
case IParseConstants.SEMANTIC_ERROR:
case IParseConstants.SEMANTIC_WARNING:
if (semanticErrors != null) {
String[][] errors={semanticErrors.getAborts(),semanticErrors.getErrors(),semanticErrors.getWarnings()};
int[] holderType={IMarker.SEVERITY_ERROR,IMarker.SEVERITY_ERROR,IMarker.SEVERITY_WARNING};
for (int j=0; j < 3; j++) {
for (int i=0; i < errors[j].length; i++) {
encodeSematicErrorFromString(spec,errors[j][i],holderType[j],monitor);
}
}
}
 else {
throw new RuntimeException("String_Node_Str" + "String_Node_Str");
}
break;
case IParseConstants.COULD_NOT_FIND_MODULE:
TLAMarkerHelper.installProblemMarkerOnSpec(spec,IMarker.SEVERITY_ERROR,new int[]{-1,-1,-1,-1},"String_Node_Str",monitor);
break;
case IParseConstants.PARSED:
break;
default :
throw new RuntimeException("String_Node_Str" + spec.getStatus());
}
cleanUp();
}

Fixed version (ground truth):
/** 
 * First try to get the information from parser's printed output.<br> Here's what I've found out about messages when there's a parsing error. The message with the error looks like one of the following: <br> - "Lexical error at line n, column n." + message<br> <br> - "***Parse Error***"\n + Message + "at line n, column n" <br> + Message<br> <br> - "Parse Error\n\n Precedence conflict between<br> ops /\ in block line n, col m to line m, col<br> of module Foo and \/ " + message<br> <br> The preceding message is<br> <br> "Parsing module Naturals in file<br> C:\\users\lamport ...\Naturals.tla"<br> <br> which is produced by a call to ToolIO.out.println in<br> ParseUnit.parseFile<br> <br> When such a message is produced, the parseErrors just contains<br> a single abort that is useless. However, the preceding kind of<br> error message isn't produced for the following kinds of errors:<br> <br> 1. A module's file can't be read.<br> 2. There's a circular EXTENDS/INSTANCES dependency.<br> 3. The module name is different from the file name.<br> <br> The abort is "Unknown location\n\n" + message, where message<br> is:<br> <br> 1. "Cannot find source file for module Foo"<br> 2. "Circular dependency among .tla files; dependency cycle..."<br> 3. "File name 'Foo' does not match the name 'Foobar"" of the<br> top level module it contains."<br> In the first two errors, the last "Parsing module" message does not contain the name of the module with the error, and there seems to be no way to figure out in what module the error is.<br> The first type of message also includes the following rare variants.<br> <br> - "Error: Failed to open output file Foo\n ..." which occurs if there's an IOException.<br> - "Error: source file 'Foo' has apparently been deleted." which occurs I have no idea when<br> There's also<br> - "Could not parse module Foo from file FooBar"<br> I have no idea when that is produced.
 */
private void processParsingErrors(Spec spec,IProgressMonitor monitor){
switch (spec.getStatus()) {
case IParseConstants.SYNTAX_ERROR:
    String[] output=ToolIO.getAllMessages();
  int nextMsg=0;
while ((nextMsg < output.length) && (output[nextMsg].indexOf("String_Node_Str") != -1)) {
  nextMsg++;
}
if ((nextMsg != 0) && (nextMsg != output.length)) {
int parsingModuleIndex=output[nextMsg - 1].indexOf("String_Node_Str") + 15;
IFile module=spec.findModuleFile(output[nextMsg - 1].substring(parsingModuleIndex,output[nextMsg - 1].indexOf("String_Node_Str",parsingModuleIndex + 1)));
int[] coordinates=null;
String message=output[nextMsg];
if ((message.indexOf("String_Node_Str") != -1) || (message.indexOf("String_Node_Str") != -1)) {
  int[] val=findLineAndColumn(0,message);
  int beginLine=val[0];
  int beginColumn=val[1];
  int endLine=0;
  int endColumn=0;
  val=findLineAndColumn(val[2],message);
  if ((val[0] > beginLine) || ((val[0] == beginLine) && (val[1] >= beginColumn))) {
    endLine=val[0];
    endColumn=val[1];
  }
  coordinates=new int[]{beginLine,beginColumn,endLine,endColumn};
  TLAMarkerHelper.installProblemMarkerOnModule(module,IMarker.SEVERITY_ERROR,coordinates,message,monitor);
}
 else {
  if (parseErrors != null) {
    String[] aborts=parseErrors.getAborts();
    if (aborts.length > 0) {
      message=aborts[0];
    }
  }
  if (message != null && message.indexOf("String_Node_Str") == -1) {
    coordinates=new int[]{-1,-1,-1,-1};
  }
 else {
    throw new RuntimeException("String_Node_Str");
  }
  if (module == null) {
    TLAMarkerHelper.installProblemMarkerOnSpec(spec,IMarker.SEVERITY_ERROR,coordinates,message,monitor);
  }
 else {
    TLAMarkerHelper.installProblemMarkerOnModule(module,IMarker.SEVERITY_ERROR,coordinates,message,monitor);
  }
}
}
 else {
throw new RuntimeException("String_Node_Str" + "String_Node_Str");
}
break;
case IParseConstants.SEMANTIC_ERROR:
case IParseConstants.SEMANTIC_WARNING:
if (semanticErrors != null) {
String[][] errors={semanticErrors.getAborts(),semanticErrors.getErrors(),semanticErrors.getWarnings()};
int[] holderType={IMarker.SEVERITY_ERROR,IMarker.SEVERITY_ERROR,IMarker.SEVERITY_WARNING};
for (int j=0; j < 3; j++) {
for (int i=0; i < errors[j].length; i++) {
encodeSematicErrorFromString(spec,errors[j][i],holderType[j],monitor);
}
}
}
 else {
throw new RuntimeException("String_Node_Str" + "String_Node_Str");
}
break;
case IParseConstants.COULD_NOT_FIND_MODULE:
TLAMarkerHelper.installProblemMarkerOnSpec(spec,IMarker.SEVERITY_ERROR,new int[]{-1,-1,-1,-1},"String_Node_Str",monitor);
break;
case IParseConstants.PARSED:
break;
default :
throw new RuntimeException("String_Node_Str" + spec.getStatus());
}
cleanUp();
}