Program: 136043
Project: 136043
Buggy source:
/** 
 * Creates an error object <br>This is a factory method
 * @param tlcRegion a region marking the error information in the document
 * @param tlcOutputDocument the document containing the error description
 * @return the TLC Error representing the error
 */
private TLCError createError(TLCRegion tlcRegion,IDocument tlcOutputDocument){
  TLCError topError=new TLCError();
  if (tlcRegion instanceof TLCRegionContainer) {
    TLCRegionContainer container=(TLCRegionContainer)tlcRegion;
    ITypedRegion[] regions=container.getSubRegions();
    Assert.isTrue(regions.length < 3,"String_Node_Str");
    for (int i=0; i < regions.length; i++) {
      if (regions[i] instanceof TLCRegion) {
        TLCError cause=createError((TLCRegion)regions[i],tlcOutputDocument);
        topError.setCause(cause);
      }
 else {
        String errorMessage;
        try {
          errorMessage=tlcOutputDocument.get(tlcRegion.getOffset(),tlcRegion.getLength());
          Document errorDocument=new Document();
          errorDocument.set(errorMessage);
          boolean markerInstalled=false;
          IFile mcFile=ModelHelper.getModelTLAFile(config);
          FileEditorInput mcFileEditorInput=new FileEditorInput((IFile)mcFile);
          FileDocumentProvider mcFileDocumentProvider=new FileDocumentProvider();
          mcFileDocumentProvider.connect(mcFileEditorInput);
          IDocument mcDocument=mcFileDocumentProvider.getDocument(mcFileEditorInput);
          FindReplaceDocumentAdapter mcSearcher=new FindReplaceDocumentAdapter(mcDocument);
          IRegion[] ids=ModelHelper.findIds(errorMessage);
          Hashtable[] props=new Hashtable[ids.length];
          for (int j=0; j < ids.length; j++) {
            String id=errorDocument.get(ids[j].getOffset(),ids[j].getLength());
            int[] coordinates=ModelHelper.calculateCoordinates(mcDocument,mcSearcher,id);
            if (ModelHelper.EMPTY_LOCATION.equals(coordinates)) {
              throw new CoreException(new Status(IStatus.ERROR,TLCUIActivator.PLUGIN_ID,"String_Node_Str" + id + "String_Node_Str"));
            }
            props[j]=ModelHelper.createMarkerDescription(config,mcDocument,mcSearcher,errorMessage,IMarker.SEVERITY_ERROR,coordinates);
            String attributeName=(String)props[j].get(ModelHelper.TLC_MODEL_ERROR_MARKER_ATTRIBUTE_NAME);
            Integer attributeIndex=(Integer)props[j].get(ModelHelper.TLC_MODEL_ERROR_MARKER_ATTRIBUTE_IDX);
            if (attributeName != null) {
              String idReplacement=null;
              if (ModelHelper.isListAttribute(attributeName)) {
                List attributeValue=(List)config.getAttribute(attributeName,new ArrayList());
                int attributeNumber=(attributeIndex != null) ? attributeIndex.intValue() : 0;
                if (IModelConfigurationConstants.MODEL_PARAMETER_CONSTANTS.equals(attributeName) || IModelConfigurationConstants.MODEL_PARAMETER_CONSTANTS.equals(attributeName)) {
                  idReplacement="String_Node_Str";
                }
 else {
                  List valueList=ModelHelper.deserializeFormulaList(attributeValue);
                  Formula value=(Formula)valueList.get(attributeNumber);
                  idReplacement=value.getFormula();
                }
              }
 else {
                idReplacement=config.getAttribute(attributeName,ModelHelper.EMPTY_STRING);
              }
              errorMessage=errorMessage.substring(0,errorMessage.indexOf(id)) + idReplacement + errorMessage.substring(errorMessage.indexOf(id) + id.length());
            }
 else {
              throw new CoreException(new Status(IStatus.ERROR,TLCUIActivator.PLUGIN_ID,"String_Node_Str" + id + "String_Node_Str"));
            }
          }
          IRegion[] locations=ModelHelper.findLocations(errorMessage);
          String[] regionContent=new String[locations.length];
          for (int j=0; j < locations.length; j++) {
            String locationString=errorDocument.get(locations[j].getOffset(),locations[j].getLength());
            Location location=Location.parseLocation(locationString);
            if (location.source().equals(mcFile.getName())) {
              IRegion region=ModelHelper.locationToRegion(mcDocument,location);
              regionContent[j]=mcDocument.get(region.getOffset(),region.getLength());
            }
          }
          for (int j=0; j < props.length; j++) {
            props[j].put(IMarker.MESSAGE,errorMessage);
            ModelHelper.installModelProblemMarker(config.getFile(),props[j],ModelHelper.TLC_MODEL_ERROR_MARKER_TLC);
            markerInstalled=true;
          }
          if (!markerInstalled) {
            Hashtable prop=ModelHelper.createMarkerDescription(errorMessage,IMarker.SEVERITY_ERROR);
            ModelHelper.installModelProblemMarker(config.getFile(),prop,ModelHelper.TLC_MODEL_ERROR_MARKER_TLC);
          }
          topError.setMessage(errorMessage);
          topError.setErrorCode(tlcRegion.getMessageCode());
        }
 catch (        BadLocationException e) {
          TLCUIActivator.logError("String_Node_Str",e);
        }
catch (        CoreException e) {
          TLCUIActivator.logError("String_Node_Str",e);
        }
      }
    }
  }
  return topError;
}

Fixed version (ground truth):
/** 
 * Creates an error object <br>This is a factory method
 * @param tlcRegion a region marking the error information in the document
 * @param tlcOutputDocument the document containing the error description
 * @return the TLC Error representing the error
 */
private TLCError createError(TLCRegion tlcRegion,IDocument tlcOutputDocument){
  TLCError topError=new TLCError();
  if (tlcRegion instanceof TLCRegionContainer) {
    TLCRegionContainer container=(TLCRegionContainer)tlcRegion;
    ITypedRegion[] regions=container.getSubRegions();
    Assert.isTrue(regions.length < 3,"String_Node_Str");
    for (int i=0; i < regions.length; i++) {
      if (regions[i] instanceof TLCRegion) {
        TLCError cause=createError((TLCRegion)regions[i],tlcOutputDocument);
        topError.setCause(cause);
      }
 else {
        String errorMessage;
        try {
          errorMessage=tlcOutputDocument.get(tlcRegion.getOffset(),tlcRegion.getLength());
          Document errorDocument=new Document();
          errorDocument.set(errorMessage);
          boolean markerInstalled=false;
          IFile mcFile=ModelHelper.getModelTLAFile(config);
          FileEditorInput mcFileEditorInput=new FileEditorInput((IFile)mcFile);
          FileDocumentProvider mcFileDocumentProvider=new FileDocumentProvider();
          mcFileDocumentProvider.connect(mcFileEditorInput);
          IDocument mcDocument=mcFileDocumentProvider.getDocument(mcFileEditorInput);
          FindReplaceDocumentAdapter mcSearcher=new FindReplaceDocumentAdapter(mcDocument);
          IRegion[] ids=ModelHelper.findIds(errorMessage);
          Hashtable[] props=new Hashtable[ids.length];
          for (int j=0; j < ids.length; j++) {
            String id=errorDocument.get(ids[j].getOffset(),ids[j].getLength());
            int[] coordinates=ModelHelper.calculateCoordinates(mcDocument,mcSearcher,id);
            if (ModelHelper.EMPTY_LOCATION.equals(coordinates)) {
              throw new CoreException(new Status(IStatus.ERROR,TLCUIActivator.PLUGIN_ID,"String_Node_Str" + id + "String_Node_Str"));
            }
            props[j]=ModelHelper.createMarkerDescription(config,mcDocument,mcSearcher,errorMessage,IMarker.SEVERITY_ERROR,coordinates);
            String attributeName=(String)props[j].get(ModelHelper.TLC_MODEL_ERROR_MARKER_ATTRIBUTE_NAME);
            Integer attributeIndex=(Integer)props[j].get(ModelHelper.TLC_MODEL_ERROR_MARKER_ATTRIBUTE_IDX);
            if (attributeName != null) {
              String idReplacement=null;
              if (ModelHelper.isListAttribute(attributeName)) {
                List attributeValue=(List)config.getAttribute(attributeName,new ArrayList());
                int attributeNumber=(attributeIndex != null) ? attributeIndex.intValue() : 0;
                if (IModelConfigurationConstants.MODEL_PARAMETER_CONSTANTS.equals(attributeName) || IModelConfigurationConstants.MODEL_PARAMETER_CONSTANTS.equals(attributeName)) {
                  idReplacement="String_Node_Str";
                }
 else {
                  List valueList=ModelHelper.deserializeFormulaList(attributeValue);
                  Formula value=(Formula)valueList.get(attributeNumber);
                  idReplacement=value.getFormula();
                }
              }
 else {
                idReplacement=config.getAttribute(attributeName,ModelHelper.EMPTY_STRING);
              }
              errorMessage=errorMessage.substring(0,errorMessage.indexOf(id)) + idReplacement + errorMessage.substring(errorMessage.indexOf(id) + id.length());
            }
 else {
              throw new CoreException(new Status(IStatus.ERROR,TLCUIActivator.PLUGIN_ID,"String_Node_Str" + id + "String_Node_Str"));
            }
          }
          IRegion[] locations=ModelHelper.findLocations(errorMessage);
          String[] regionContent=new String[locations.length];
          for (int j=0; j < locations.length; j++) {
            String locationString=errorDocument.get(locations[j].getOffset(),locations[j].getLength());
            Location location=Location.parseLocation(locationString);
            if (location.source().equals(mcFile.getName().substring(0,mcFile.getName().length() - "String_Node_Str".length()))) {
              IRegion region=ModelHelper.locationToRegion(mcDocument,location);
              regionContent[j]=mcDocument.get(region.getOffset(),region.getLength());
              errorMessage=errorMessage.replace(locationString,regionContent[j]);
            }
          }
          for (int j=0; j < props.length; j++) {
            props[j].put(IMarker.MESSAGE,errorMessage);
            ModelHelper.installModelProblemMarker(config.getFile(),props[j],ModelHelper.TLC_MODEL_ERROR_MARKER_TLC);
            markerInstalled=true;
          }
          if (!markerInstalled) {
            Hashtable prop=ModelHelper.createMarkerDescription(errorMessage,IMarker.SEVERITY_ERROR);
            ModelHelper.installModelProblemMarker(config.getFile(),prop,ModelHelper.TLC_MODEL_ERROR_MARKER_TLC);
          }
          errorMessage=errorMessage.replaceAll("String_Node_Str","String_Node_Str");
          errorMessage=errorMessage.replaceAll("String_Node_Str","String_Node_Str");
          topError.setMessage(errorMessage);
          topError.setErrorCode(tlcRegion.getMessageCode());
        }
 catch (        BadLocationException e) {
          TLCUIActivator.logError("String_Node_Str",e);
        }
catch (        CoreException e) {
          TLCUIActivator.logError("String_Node_Str",e);
        }
      }
    }
  }
  return topError;
}