nus-yam/ex-repair huggingface dataset:
Program: 178885
Project: 178885
Buggy source:
/** 
 * {@inheritDoc} 
 */
public V put(K key,V value){
  Node<K,V> currentNode=root;
  while (currentNode instanceof InternalNode) {
    currentNode=currentNode.getChild(key).left();
  }
  if (currentNode != null) {
    LeafNode<K,V> leaf=(LeafNode<K,V>)currentNode;
    if (!leaf.addValue(key,value)) {
      LeafNode<K,V> right=leaf.split().right();
      if (key.compareTo(right.lowerBound()) >= 0) {
        right.addValue(key,value);
      }
 else {
        leaf.addValue(key,value);
      }
      Node<K,V> parentRight=right;
      InternalNode<K,V> parent=(InternalNode<K,V>)right.parent;
      while (parent != null && !parent.addChild(parentRight.lowerBound(),parentRight)) {
        InternalNode<K,V> newRight=parent.split().left();
        K newLB=newRight.lowerBound();
        if (newLB.compareTo(newRight.lowerBound()) >= 0) {
          newRight.addChild(newLB,newRight);
        }
 else {
          parent.addChild(newLB,newRight);
        }
        parent=(InternalNode<K,V>)newRight.parent;
        parentRight=newRight;
      }
      if (parent == null) {
        if (!parent.addChild(parentRight.lowerBound(),parentRight)) {
          InternalNode<K,V> newRoot=new InternalNode<K,V>((InternalNode<K,V>)root,(InternalNode<K,V>)parentRight);
          root.parent=newRoot;
          parentRight.parent=newRoot;
          root=newRoot;
        }
      }
    }
  }
 else {
    root=new LeafNode<K,V>(key,value);
  }
  return null;
}

Fixed version (ground truth):
/** 
 * {@inheritDoc} 
 */
public V put(K key,V value){
  Node<K,V> currentNode=root;
  while (currentNode instanceof InternalNode) {
    currentNode=currentNode.getChild(key).left();
  }
  if (currentNode != null) {
    LeafNode<K,V> leaf=(LeafNode<K,V>)currentNode;
    if (!leaf.addValue(key,value)) {
      LeafNode<K,V> right=leaf.split().right();
      if (key.compareTo(right.lowerBound()) >= 0) {
        right.addValue(key,value);
      }
 else {
        leaf.addValue(key,value);
      }
      Node<K,V> newRight=right;
      InternalNode<K,V> parent=(InternalNode<K,V>)right.parent;
      while (parent != null && !parent.addChild(newRight.lowerBound(),newRight)) {
        InternalNode<K,V> parentRight=parent.split().left();
        K newLB=newRight.lowerBound();
        if (newLB.compareTo(parentRight.lowerBound()) >= 0) {
          parentRight.addChild(newLB,newRight);
          newRight.parent=parentRight;
        }
 else {
          parent.addChild(newLB,newRight);
        }
        parent=(InternalNode<K,V>)parent.parent;
        newRight=parentRight;
      }
      if (parent == null) {
        Node<K,V> newRoot=new InternalNode<K,V>(root,newRight);
        root.parent=newRoot;
        newRight.parent=newRoot;
        root=newRoot;
      }
    }
  }
 else {
    root=new LeafNode<K,V>(key,value);
  }
  return null;
}
Program: 178886
Project: 178886
Buggy source:
/** 
 * Returns the domain axis for a dataset.
 * @param index  the dataset index.
 * @return The axis.
 */
public ValueAxis getDomainAxisForDataset(int index){
  int upper=Math.max(getDatasetCount(),getRendererCount());
  if (index < 0 || index >= upper) {
    throw new IllegalArgumentException("String_Node_Str" + index + "String_Node_Str");
  }
  ValueAxis valueAxis=null;
  List axisIndices=(List)this.datasetToDomainAxesMap.get(new Integer(index));
  if (axisIndices != null) {
    Integer axisIndex=(Integer)axisIndices.get(0);
    valueAxis=getDomainAxis(axisIndex.intValue());
  }
 else {
    valueAxis=getDomainAxis(0);
  }
  return valueAxis;
}

Fixed version (ground truth):
/** 
 * Returns the domain axis for a dataset.
 * @param index  the dataset index.
 * @return The axis.
 */
public ValueAxis getDomainAxisForDataset(int index){
  int upper=Math.max(getDatasetCount(),getRendererCount());
  if (index < 0 || index >= upper) {
    throw new IllegalArgumentException("String_Node_Str" + index + "String_Node_Str");
  }
  ValueAxis valueAxis;
  List axisIndices=(List)this.datasetToDomainAxesMap.get(index);
  if (axisIndices != null) {
    Integer axisIndex=(Integer)axisIndices.get(0);
    valueAxis=getDomainAxis(axisIndex.intValue());
  }
 else {
    valueAxis=getDomainAxis(0);
  }
  return valueAxis;
}
Program: 178888
Project: 178888
Buggy source:
public void add(Object[] elements,IProgressMonitor monitor){
  Object[] filteredObjects=null;
  if (workingSet != null) {
    filteredObjects=UIUtils.filterByWorkingSet(elements,workingSet);
  }
 else {
    filteredObjects=elements;
  }
  elementCollector.add(filteredObjects,monitor);
}

Fixed version (ground truth):
public void add(Object[] elements,IProgressMonitor monitor){
  Object[] filteredObjects=null;
  if (workingSet != null) {
    filteredObjects=UIUtils.filterByWorkingSet(elements,workingSet);
  }
 else {
    filteredObjects=elements;
  }
  elementCollector.add(filteredObjects,monitor);
  try {
    Thread.sleep(100);
  }
 catch (  InterruptedException e) {
  }
}
Program: 178889
Project: 178889
Buggy source:
public static void runWithProgress(IRunnableWithProgress operation,Shell shell,boolean cancelable) throws InvocationTargetException, InterruptedException {
  ProgressMonitorDialog dialog=new ProgressMonitorDialog(shell);
  dialog.setCancelable(cancelable);
  dialog.run(true,false,operation);
}

Fixed version (ground truth):
public static void runWithProgress(IRunnableWithProgress operation,Shell shell,boolean cancelable) throws InvocationTargetException, InterruptedException {
  ProgressMonitorDialog dialog=new ProgressMonitorDialog(shell);
  dialog.setCancelable(cancelable);
  dialog.run(true,cancelable,operation);
}
Program: 178890
Project: 178890
Buggy source:
/** 
 * Constructor.
 * @param file The file where to synchronize the map content.
 * @throws CoreException
 */
public PersistentMap(IFile file) throws CoreException {
  this.file=file;
  if (file.exists()) {
    try {
      map=(HashMap<String,String>)StorageUtils.readFromJSON(file,new HashMap<String,String>().getClass().getCanonicalName());
    }
 catch (    Exception e) {
      e.printStackTrace();
    }
  }
 else {
    map=new HashMap<String,String>();
    synchronize();
  }
}

Fixed version (ground truth):
/** 
 * Constructor.
 * @param file The file where to synchronize the map content.
 * @throws CoreException
 */
public PersistentMap(IFile file) throws CoreException {
  this.file=file;
  if (file.exists()) {
    try {
      map=(Map<String,String>)StorageUtils.readFromJson(file,new TypeToken<Map<String,String>>(){
      }
.getType());
    }
 catch (    Exception e) {
      e.printStackTrace();
    }
  }
 else {
    map=new HashMap<String,String>();
    synchronize();
  }
}
Program: 178891
Project: 178891
Buggy source:
@Override protected Control createDialogArea(Composite parent){
  Composite composite=(Composite)super.createDialogArea(parent);
  GridLayoutFactory.fillDefaults().applyTo(composite);
  CompareViewerPane pane=new CompareViewerPane(composite,SWT.BORDER | SWT.FLAT);
  GridDataFactory.fillDefaults().align(SWT.FILL,SWT.FILL).grab(true,true).applyTo(pane);
  CompareConfiguration cc=new CompareConfiguration();
  if (ancestorPage != null) {
    cc.setAncestorLabel(String.format("String_Node_Str",ancestorPage.getId()));
  }
  cc.setLeftLabel(String.format("String_Node_Str",page.getId()));
  cc.setRightLabel(String.format("String_Node_Str",conflictingPage.getId()));
  viewer=new TextMergeViewer(pane,cc);
  pane.setContent(viewer.getControl());
  GridDataFactory.fillDefaults().align(SWT.FILL,SWT.FILL).grab(true,true).applyTo(viewer.getControl());
  CompareElement left=new CompareElement(page,true);
  CompareElement right=new CompareElement(conflictingPage,false);
  if (ancestorPage != null) {
    CompareElement ancestor=new CompareElement(ancestorPage,false);
    viewer.setInput(new DiffNode(null,Differencer.CONFLICTING,ancestor,left,right));
  }
 else {
    viewer.setInput(new DiffNode(left,right));
  }
  return pane;
}

Fixed version (ground truth):
@Override protected Control createDialogArea(Composite parent){
  Composite composite=(Composite)super.createDialogArea(parent);
  GridLayoutFactory.fillDefaults().applyTo(composite);
  CompareViewerPane pane=new CompareViewerPane(composite,SWT.BORDER | SWT.FLAT);
  GridDataFactory.fillDefaults().align(SWT.FILL,SWT.FILL).grab(true,true).applyTo(pane);
  CompareConfiguration cc=new CompareConfiguration();
  String pageId=StorageUtils.getExtendedPageId(page.getId(),page.getLanguage());
  if (ancestorPage != null) {
    cc.setAncestorLabel(String.format("String_Node_Str",pageId));
  }
  cc.setLeftLabel(String.format("String_Node_Str",pageId));
  cc.setRightLabel(String.format("String_Node_Str",pageId));
  viewer=new TextMergeViewer(pane,cc);
  pane.setContent(viewer.getControl());
  GridDataFactory.fillDefaults().align(SWT.FILL,SWT.FILL).grab(true,true).applyTo(viewer.getControl());
  CompareElement left=new CompareElement(page,true);
  CompareElement right=new CompareElement(conflictingPage,false);
  if (ancestorPage != null) {
    CompareElement ancestor=new CompareElement(ancestorPage,false);
    viewer.setInput(new DiffNode(null,Differencer.CONFLICTING,ancestor,left,right));
  }
 else {
    viewer.setInput(new DiffNode(left,right));
  }
  return pane;
}
Program: 178892
Project: 178892
Buggy source:
@Override protected void doSaveDocument(IProgressMonitor monitor,Object element,IDocument document,boolean overwrite) throws CoreException {
  if (element instanceof PageEditorInput) {
    final PageEditorInput pageEditorInput=(PageEditorInput)element;
    pageEditorInput.getPage().setContent(document.get());
    SafeRunner.run(new XWikiEclipseSafeRunnable(){
      public void run() throws Exception {
      }
    }
);
  }
  super.doSaveDocument(monitor,element,document,overwrite);
}

Fixed version (ground truth):
@Override protected void doSaveDocument(IProgressMonitor monitor,Object element,IDocument document,boolean overwrite) throws CoreException {
  if (element instanceof PageEditorInput) {
    final PageEditorInput pageEditorInput=(PageEditorInput)element;
    pageEditorInput.getPage().setContent(document.get());
    SafeRunner.run(new XWikiEclipseSafeRunnable(){
      public void run() throws Exception {
        final XWikiEclipsePage page=pageEditorInput.getPage().getDataManager().storePage(pageEditorInput.getPage());
        Display.getDefault().syncExec(new Runnable(){
          public void run(){
            pageEditor.setInput(new PageEditorInput(page,pageEditorInput.isReadOnly()));
          }
        }
);
      }
    }
);
  }
  super.doSaveDocument(monitor,element,document,overwrite);
}
Program: 178893
Project: 178893
Buggy source:
public void run() throws Exception {
}

Fixed version (ground truth):
public void run(){
  pageEditor.setInput(new PageEditorInput(page,pageEditorInput.isReadOnly()));
}
Program: 178895
Project: 178895
Buggy source:
public void run(){
  PageEditor.this.updateInfo();
}

Fixed version (ground truth):
public void run(){
  int caretOffset=sourceViewer.getTextWidget().getCaretOffset();
  int topPixel=sourceViewer.getTextWidget().getTopPixel();
  try {
    doSetInput(new PageEditorInput(newPage,input.isReadOnly()));
  }
 catch (  CoreException e) {
    CoreLog.logError("String_Node_Str",e);
  }
  sourceViewer.getTextWidget().setCaretOffset(caretOffset);
  sourceViewer.getTextWidget().setTopPixel(topPixel);
  updateInfo();
  doSave(new NullProgressMonitor());
}
Program: 178897
Project: 178897
Buggy source:
private void handleConflict(){
  PageEditorInput input=(PageEditorInput)getEditorInput();
  XWikiEclipsePage currentPage=input.getPage();
  DataManager dataManager=currentPage.getDataManager();
  if (dataManager.isInConflict(currentPage.getId())) {
    XWikiEclipsePage conflictingPage=dataManager.getConflictingPage(currentPage.getId());
    XWikiEclipsePage conflictAncestorPage=dataManager.getConflictAncestorPage(currentPage.getId());
    PageConflictDialog compareDialog=new PageConflictDialog(Display.getDefault().getActiveShell(),currentPage,conflictingPage,conflictAncestorPage);
    int result=compareDialog.open();
    conflictDialogDisplayed=true;
switch (result) {
case PageConflictDialog.ID_USE_LOCAL:
      break;
case PageConflictDialog.ID_USE_REMOTE:
    break;
default :
  return;
}
conflictDialogDisplayed=false;
}
}

Fixed version (ground truth):
private void handleConflict(){
  PageEditorInput input=(PageEditorInput)getEditorInput();
  XWikiEclipsePage currentPage=input.getPage();
  DataManager dataManager=currentPage.getDataManager();
  String pageId=StorageUtils.getExtendedPageId(currentPage.getId(),currentPage.getLanguage());
  if (dataManager.isInConflict(pageId)) {
    try {
      XWikiEclipsePage conflictingPage=dataManager.getConflictingPage(pageId);
      XWikiEclipsePage conflictAncestorPage=dataManager.getConflictAncestorPage(pageId);
      PageConflictDialog compareDialog=new PageConflictDialog(Display.getDefault().getActiveShell(),currentPage,conflictingPage,conflictAncestorPage);
      int result=compareDialog.open();
      conflictDialogDisplayed=true;
switch (result) {
case PageConflictDialog.ID_USE_LOCAL:
        XWikiEclipsePage newPage=conflictingPage;
      newPage.setContent(currentPage.getContent());
    dataManager.clearConflictingStatus(pageId);
  setInput(new PageEditorInput(newPage,input.isReadOnly()));
doSave(new NullProgressMonitor());
break;
case PageConflictDialog.ID_USE_REMOTE:
dataManager.clearConflictingStatus(pageId);
setInput(new PageEditorInput(conflictingPage,input.isReadOnly()));
doSave(new NullProgressMonitor());
break;
default :
return;
}
conflictDialogDisplayed=false;
}
 catch (Exception e) {
CoreLog.logError("String_Node_Str",e);
}
}
}
Program: 178898
Project: 178898
Buggy source:
public String getName(){
  String name=page.getName() + "String_Node_Str" + page.getVersion()+ "String_Node_Str";
  return name;
}

Fixed version (ground truth):
public String getName(){
  String name=page.getName() + (page.getLanguage().equals("String_Node_Str") ? "String_Node_Str" : "String_Node_Str" + page.getLanguage() + "String_Node_Str");
  return name;
}
Program: 178899
Project: 178899
Buggy source:
public Object execute(ExecutionEvent event) throws ExecutionException {
  String spaceKey=null;
  DataManager dataManager=null;
  ISelection selection=HandlerUtil.getCurrentSelection(event);
  Set selectedObjects=UIUtils.getSelectedObjectsFromSelection(selection);
  if (selectedObjects.size() == 1) {
    Object selectedObject=selectedObjects.iterator().next();
    if (selectedObject instanceof XWikiEclipseSpaceSummary) {
      XWikiEclipseSpaceSummary spaceSummary=(XWikiEclipseSpaceSummary)selectedObject;
      dataManager=spaceSummary.getDataManager();
      spaceKey=spaceSummary.getId();
    }
    if (selectedObject instanceof DataManager) {
      dataManager=(DataManager)selectedObject;
    }
  }
  if (dataManager != null) {
    NewPageWizard wizard=new NewPageWizard(dataManager,spaceKey);
    WizardDialog dialog=new WizardDialog(HandlerUtil.getActiveWorkbenchWindow(event).getShell(),wizard);
    dialog.create();
    dialog.open();
  }
  return null;
}

Fixed version (ground truth):
public Object execute(ExecutionEvent event) throws ExecutionException {
  DataManager dataManager=null;
  NewPageWizardState state=new NewPageWizardState();
  ISelection selection=HandlerUtil.getCurrentSelection(event);
  Set selectedObjects=UIUtils.getSelectedObjectsFromSelection(selection);
  if (selectedObjects.size() == 1) {
    Object selectedObject=selectedObjects.iterator().next();
    if (selectedObject instanceof XWikiEclipseSpaceSummary) {
      XWikiEclipseSpaceSummary spaceSummary=(XWikiEclipseSpaceSummary)selectedObject;
      dataManager=spaceSummary.getDataManager();
      state.setSpace(spaceSummary.getName());
      state.setWiki(spaceSummary.getWiki());
    }
    if (selectedObject instanceof XWikiEclipseWikiSummary) {
      XWikiEclipseWikiSummary wikiSummary=(XWikiEclipseWikiSummary)selectedObject;
      state.setWiki(wikiSummary.getName());
      dataManager=wikiSummary.getDataManager();
    }
    if (selectedObject instanceof DataManager) {
      dataManager=(DataManager)selectedObject;
    }
  }
  if (dataManager != null) {
    NewPageWizard wizard=new NewPageWizard(dataManager,state);
    WizardDialog dialog=new WizardDialog(HandlerUtil.getActiveWorkbenchWindow(event).getShell(),wizard);
    dialog.create();
    dialog.open();
  }
  return null;
}
Program: 178900
Project: 178900
Buggy source:
public List<XWikiEclipseSpaceSummary> getSpaces(XWikiEclipseWikiSummary wiki) throws XWikiEclipseStorageException {
  final List<XWikiEclipseSpaceSummary> result=new ArrayList<XWikiEclipseSpaceSummary>();
  try {
    final IFolder spaceFolder=StorageUtils.createFolder(baseFolder.getFolder(SPACES_DIRECTORY));
    List<IResource> spaceFolderResources=getChildResources(spaceFolder,IResource.DEPTH_ONE);
    for (    IResource spaceFolderResource : spaceFolderResources) {
      if (spaceFolderResource instanceof IFile) {
        IFile wikiFile=(IFile)spaceFolderResource;
        XWikiEclipseSpaceSummary spaceSummary;
        try {
          spaceSummary=(XWikiEclipseSpaceSummary)StorageUtils.readFromJSON(wikiFile,XWikiEclipseSpaceSummary.class.getCanonicalName());
          result.add(spaceSummary);
        }
 catch (        Exception e) {
          e.printStackTrace();
        }
      }
    }
  }
 catch (  CoreException e) {
    throw new XWikiEclipseStorageException(e);
  }
  return result;
}

Fixed version (ground truth):
public List<XWikiEclipseSpaceSummary> getSpaces(XWikiEclipseWikiSummary wiki) throws XWikiEclipseStorageException {
  final List<XWikiEclipseSpaceSummary> result=new ArrayList<XWikiEclipseSpaceSummary>();
  try {
    final IFolder spaceFolder=StorageUtils.createFolder(baseFolder.getFolder(SPACES_DIRECTORY));
    List<IResource> spaceFolderResources=getChildResources(spaceFolder,IResource.DEPTH_ONE);
    for (    IResource spaceFolderResource : spaceFolderResources) {
      if (spaceFolderResource instanceof IFile) {
        IFile wikiFile=(IFile)spaceFolderResource;
        XWikiEclipseSpaceSummary spaceSummary;
        try {
          spaceSummary=(XWikiEclipseSpaceSummary)StorageUtils.readFromJSON(wikiFile,XWikiEclipseSpaceSummary.class.getCanonicalName());
          if (spaceSummary.getWiki().equals(wiki.getWikiId())) {
            result.add(spaceSummary);
          }
        }
 catch (        Exception e) {
          e.printStackTrace();
        }
      }
    }
  }
 catch (  CoreException e) {
    throw new XWikiEclipseStorageException(e);
  }
  return result;
}
Program: 178901
Project: 178901
Buggy source:
/** 
 * @param spaceSummary
 * @return
 */
public List<XWikiEclipsePageSummary> getPageSummaries(XWikiEclipseSpaceSummary spaceSummary) throws XWikiEclipseStorageException {
  final List<XWikiEclipsePageSummary> result=new ArrayList<XWikiEclipsePageSummary>();
  try {
    final IFolder spaceFolder=StorageUtils.createFolder(baseFolder.getFolder(PAGES_DIRECTORY));
    List<IResource> pageFolderResources=getChildResources(spaceFolder,IResource.DEPTH_ONE);
    for (    IResource pageFolderResource : pageFolderResources) {
      if (pageFolderResource instanceof IFile) {
        IFile wikiFile=(IFile)pageFolderResource;
        XWikiEclipsePageSummary pageSummary;
        try {
          pageSummary=(XWikiEclipsePageSummary)StorageUtils.readFromJSON(wikiFile,XWikiEclipsePageSummary.class.getCanonicalName());
          result.add(pageSummary);
        }
 catch (        Exception e) {
          e.printStackTrace();
        }
      }
    }
  }
 catch (  CoreException e) {
    throw new XWikiEclipseStorageException(e);
  }
  return result;
}

Fixed version (ground truth):
/** 
 * @param spaceSummary
 * @return
 */
public List<XWikiEclipsePageSummary> getPageSummaries(XWikiEclipseSpaceSummary spaceSummary) throws XWikiEclipseStorageException {
  final List<XWikiEclipsePageSummary> result=new ArrayList<XWikiEclipsePageSummary>();
  try {
    final IFolder spaceFolder=StorageUtils.createFolder(baseFolder.getFolder(PAGES_DIRECTORY));
    List<IResource> pageFolderResources=getChildResources(spaceFolder,IResource.DEPTH_ONE);
    for (    IResource pageFolderResource : pageFolderResources) {
      if (pageFolderResource instanceof IFile) {
        IFile wikiFile=(IFile)pageFolderResource;
        XWikiEclipsePageSummary pageSummary;
        try {
          pageSummary=(XWikiEclipsePageSummary)StorageUtils.readFromJSON(wikiFile,XWikiEclipsePageSummary.class.getCanonicalName());
          if (pageSummary.getWiki().equals(spaceSummary.getWiki()) && pageSummary.getSpace().equals(spaceSummary.getName())) {
            result.add(pageSummary);
          }
        }
 catch (        Exception e) {
          e.printStackTrace();
        }
      }
    }
  }
 catch (  CoreException e) {
    throw new XWikiEclipseStorageException(e);
  }
  return result;
}
Program: 178906
Project: 178906
Buggy source:
/** 
 * {@inheritDoc}
 * @see org.xwiki.eclipse.model.ModelObject#getXWikiEclipseId()
 */
@Override public String getXWikiEclipseId(){
  return String.format("String_Node_Str",getDataManager().getName(),getAuthor());
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}
 * @see org.xwiki.eclipse.model.ModelObject#getXWikiEclipseId()
 */
@Override public String getXWikiEclipseId(){
  return String.format("String_Node_Str",getDataManager().getName(),getId(),getAuthor());
}
Program: 178907
Project: 178907
Buggy source:
/** 
 * {@inheritDoc}
 * @see org.xwiki.eclipse.storage.IRemoteXWikiDataStorage#getComments(org.xwiki.eclipse.model.XWikiEclipsePageSummary)
 */
@Override public List<XWikiEclipseComment> getComments(XWikiEclipsePageSummary pageSummary){
  List<XWikiEclipseComment> result=new ArrayList<XWikiEclipseComment>();
  List<Comment> comments=this.restRemoteStorage.getComments(pageSummary.getCommentsUrl());
  for (  Comment comment : comments) {
    XWikiEclipseComment c=new XWikiEclipseComment(dataManager);
    c.setAuthor(comment.getAuthor());
    c.setDate(comment.getDate());
    c.setHighlight(comment.getHighlight());
    c.setId(comment.getId());
    c.setText(comment.getText());
    result.add(c);
  }
  return result;
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}
 * @see org.xwiki.eclipse.storage.IRemoteXWikiDataStorage#getComments(org.xwiki.eclipse.model.XWikiEclipsePageSummary)
 */
@Override public List<XWikiEclipseComment> getComments(XWikiEclipsePageSummary pageSummary){
  List<XWikiEclipseComment> result=new ArrayList<XWikiEclipseComment>();
  List<Comment> comments=this.restRemoteStorage.getComments(pageSummary.getCommentsUrl());
  if (comments != null && comments.size() > 0) {
    for (    Comment comment : comments) {
      XWikiEclipseComment c=new XWikiEclipseComment(dataManager);
      c.setAuthor(comment.getAuthor());
      c.setDate(comment.getDate());
      c.setHighlight(comment.getHighlight());
      c.setId(comment.getId());
      c.setText(comment.getText());
      result.add(c);
    }
  }
  return result;
}
Program: 178909
Project: 178909
Buggy source:
@Override public boolean close(){
  boolean warn=false;
  for (  Object o : selectedObjects) {
    if ((o instanceof DataManager) || (o instanceof XWikiEclipseSpaceSummary)) {
      warn=true;
      break;
    }
  }
  if (warn) {
    MessageBox messageBox=new MessageBox(getShell(),SWT.YES | SWT.NO | SWT.ICON_QUESTION);
    messageBox.setMessage(String.format("String_Node_Str"));
    int result=messageBox.open();
    if (result == SWT.YES) {
      return super.close();
    }
 else {
      return false;
    }
  }
  return super.close();
}

Fixed version (ground truth):
@Override public boolean close(){
  if (getReturnCode() == Window.CANCEL) {
    return super.close();
  }
  boolean warn=false;
  for (  Object o : selectedObjects) {
    if ((o instanceof DataManager) || (o instanceof XWikiEclipseSpaceSummary)) {
      warn=true;
      break;
    }
  }
  if (warn) {
    MessageBox messageBox=new MessageBox(getShell(),SWT.YES | SWT.NO | SWT.ICON_QUESTION);
    messageBox.setMessage("String_Node_Str");
    int result=messageBox.open();
    if (result == SWT.YES) {
      return super.close();
    }
 else {
      return false;
    }
  }
  return super.close();
}
Program: 178910
Project: 178910
Buggy source:
private void clearPageStatus(String pageId) throws XWikiEclipseException {
  conflictingPagesDataStorage.removePage(pageId);
  pageToStatusMap.remove(pageId);
}

Fixed version (ground truth):
public void clearPageStatus(String pageId) throws XWikiEclipseException {
  conflictingPagesDataStorage.removePage(pageId);
  pageToStatusMap.remove(pageId);
}
Program: 178911
Project: 178911
Buggy source:
public void removePage(String pageId) throws XWikiEclipseException {
  XWikiPage page=null;
  if (isConnected()) {
    page=remoteXWikiDataStorage.getPage(pageId);
    remoteXWikiDataStorage.removePage(pageId);
  }
 else {
    page=localXWikiDataStorage.getPage(pageId);
  }
  localXWikiDataStorage.removePage(pageId);
  NotificationManager.getDefault().fireCoreEvent(CoreEvent.Type.PAGE_REMOVED,this,new XWikiEclipsePage(this,page));
}

Fixed version (ground truth):
public void removePage(String pageId) throws XWikiEclipseException {
  XWikiPage page=null;
  if (isConnected()) {
    page=remoteXWikiDataStorage.getPage(pageId);
    remoteXWikiDataStorage.removePage(pageId);
  }
 else {
    page=localXWikiDataStorage.getPage(pageId);
  }
  localXWikiDataStorage.removePage(pageId);
  String spaceKey=page.getSpace();
  List<XWikiEclipsePageSummary> pages=null;
  try {
    pages=getPages(spaceKey);
  }
 catch (  XWikiEclipseException e) {
    CoreLog.logError("String_Node_Str" + e.getMessage());
  }
  if (pages != null && pages.size() == 0) {
    localXWikiDataStorage.removeSpace(spaceKey);
  }
  NotificationManager.getDefault().fireCoreEvent(CoreEvent.Type.PAGE_REMOVED,this,new XWikiEclipsePage(this,page));
}
Program: 178912
Project: 178912
Buggy source:
public void removeObject(String pageId,String className,int objectId) throws XWikiEclipseException {
  XWikiPage page=null;
  if (isConnected()) {
    page=remoteXWikiDataStorage.getPage(pageId);
    remoteXWikiDataStorage.removeObject(pageId,className,objectId);
  }
 else {
    page=localXWikiDataStorage.getPage(pageId);
  }
  localXWikiDataStorage.removeObject(pageId,className,objectId);
  NotificationManager.getDefault().fireCoreEvent(CoreEvent.Type.OBJECT_REMOVED,this,new XWikiEclipsePage(this,page));
}

Fixed version (ground truth):
public void removeObject(String pageId,String className,int objectId) throws XWikiEclipseException {
  XWikiObject object=null;
  if (isConnected()) {
    object=remoteXWikiDataStorage.getObject(pageId,className,objectId);
    remoteXWikiDataStorage.removeObject(pageId,className,objectId);
  }
 else {
    object=localXWikiDataStorage.getObject(pageId,className,objectId);
  }
  localXWikiDataStorage.removeObject(pageId,className,objectId);
  NotificationManager.getDefault().fireCoreEvent(CoreEvent.Type.OBJECT_REMOVED,this,new XWikiEclipseObject(this,object,getClass(object.getClassName()).getData(),getPageSummary(object.getPageId()).getData()));
}
Program: 178913
Project: 178913
Buggy source:
public static DataManagerRegistry getDefault(){
  if (sharedInstance == null) {
    sharedInstance=new DataManagerRegistry();
    Job job=new Job("String_Node_Str"){
      @Override protected IStatus run(      IProgressMonitor monitor){
        IProject[] projects=ResourcesPlugin.getWorkspace().getRoot().getProjects();
        for (        IProject project : projects) {
          if (project.isOpen()) {
            try {
              if (hasXWikiEclipseNature(project)) {
                sharedInstance.register(new DataManager(project));
              }
            }
 catch (            CoreException e) {
              CoreLog.logError(String.format("String_Node_Str",project.getName()),e);
            }
          }
        }
        return Status.OK_STATUS;
      }
    }
;
    job.schedule();
    ResourcesPlugin.getWorkspace().addResourceChangeListener(sharedInstance,IResourceChangeEvent.POST_BUILD);
  }
  return sharedInstance;
}

Fixed version (ground truth):
public synchronized static DataManagerRegistry getDefault(){
  if (sharedInstance == null) {
    sharedInstance=new DataManagerRegistry();
    Job job=new Job("String_Node_Str"){
      @Override protected IStatus run(      IProgressMonitor monitor){
        IProject[] projects=ResourcesPlugin.getWorkspace().getRoot().getProjects();
        for (        IProject project : projects) {
          if (project.isOpen()) {
            try {
              if (hasXWikiEclipseNature(project)) {
                sharedInstance.register(new DataManager(project));
              }
            }
 catch (            CoreException e) {
              CoreLog.logError(String.format("String_Node_Str",project.getName()),e);
            }
          }
        }
        return Status.OK_STATUS;
      }
    }
;
    job.schedule();
    ResourcesPlugin.getWorkspace().addResourceChangeListener(sharedInstance,IResourceChangeEvent.POST_BUILD);
  }
  return sharedInstance;
}
Program: 178914
Project: 178914
Buggy source:
/** 
 * Notify an event to all the listeners interested to that event.
 * @param type The event type.
 * @param source The object that generated the event.
 * @param data Additional data associated to the event.
 */
public void fireCoreEvent(CoreEvent.Type type,Object source,Object data){
  CoreEvent coreEvent=new CoreEvent(type,source,data);
  Object[] objects=listenerList.getListeners();
  for (  Object object : objects) {
    ListenerEntry listenerEntry=(ListenerEntry)object;
    if (listenerEntry.getEventTypes().contains(type)) {
      listenerEntry.getListener().handleCoreEvent(coreEvent);
    }
  }
}

Fixed version (ground truth):
/** 
 * Notify an event to all the listeners interested to that event.
 * @param type The event type.
 * @param source The object that generated the event.
 * @param data Additional data associated to the event.
 */
public synchronized void fireCoreEvent(CoreEvent.Type type,Object source,Object data){
  CoreEvent coreEvent=new CoreEvent(type,source,data);
  Object[] objects=listenerList.getListeners();
  for (  Object object : objects) {
    ListenerEntry listenerEntry=(ListenerEntry)object;
    if (listenerEntry.getEventTypes().contains(type)) {
      listenerEntry.getListener().handleCoreEvent(coreEvent);
    }
  }
}
Program: 178915
Project: 178915
Buggy source:
/** 
 * @return The shared instance.
 */
public static NotificationManager getDefault(){
  if (sharedInstance == null) {
    sharedInstance=new NotificationManager();
  }
  return sharedInstance;
}

Fixed version (ground truth):
/** 
 * @return The shared instance.
 */
public synchronized static NotificationManager getDefault(){
  if (sharedInstance == null) {
    sharedInstance=new NotificationManager();
  }
  return sharedInstance;
}
Program: 178916
Project: 178916
Buggy source:
public boolean removePage(final String pageId) throws XWikiEclipseException {
  try {
    ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable(){
      public void run(      IProgressMonitor monitor) throws CoreException {
        try {
          XWikiPage page=getPage(pageId);
          if (page == null) {
            return;
          }
          IFolder indexPageFolder=baseFolder.getFolder(INDEX_DIRECTORY).getFolder(page.getSpace()).getFolder(pageId);
          if (indexPageFolder.exists()) {
            indexPageFolder.delete(true,null);
          }
          IFolder pageFolder=CoreUtils.createFolder(baseFolder.getFolder(PAGES_DIRECTORY));
          IFile pageFile=pageFolder.getFile(getFileNameForPage(pageId));
          if (pageFile.exists()) {
            pageFile.delete(true,null);
          }
        }
 catch (        XWikiEclipseException e) {
          throw new CoreException(new Status(Status.ERROR,CorePlugin.PLUGIN_ID,"String_Node_Str",e));
        }
      }
    }
,null);
    return true;
  }
 catch (  CoreException e) {
    throw new XWikiEclipseException(e);
  }
}

Fixed version (ground truth):
public boolean removePage(final String pageId) throws XWikiEclipseException {
  try {
    ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable(){
      public void run(      IProgressMonitor monitor) throws CoreException {
        try {
          XWikiPage page=getPage(pageId);
          if (page == null) {
            return;
          }
          List<XWikiObjectSummary> objects=getObjects(pageId);
          for (          XWikiObjectSummary object : objects) {
            removeObject(pageId,object.getClassName(),object.getId());
          }
          IFolder indexPageFolder=baseFolder.getFolder(INDEX_DIRECTORY).getFolder(page.getSpace()).getFolder(pageId);
          if (indexPageFolder.exists()) {
            indexPageFolder.delete(true,null);
          }
          IFolder pageFolder=CoreUtils.createFolder(baseFolder.getFolder(PAGES_DIRECTORY));
          IFile pageFile=pageFolder.getFile(getFileNameForPage(pageId));
          if (pageFile.exists()) {
            pageFile.delete(true,null);
          }
        }
 catch (        XWikiEclipseException e) {
          throw new CoreException(new Status(Status.ERROR,CorePlugin.PLUGIN_ID,"String_Node_Str",e));
        }
      }
    }
,null);
    return true;
  }
 catch (  CoreException e) {
    throw new XWikiEclipseException(e);
  }
}
Program: 178917
Project: 178917
Buggy source:
public synchronized boolean exists(String pageId,String className,int objectId){
  return true;
}

Fixed version (ground truth):
public synchronized boolean exists(String pageId,String className,int objectId){
  try {
    XWikiObject object=getObject(pageId,className,objectId);
  }
 catch (  XWikiEclipseException e) {
    return false;
  }
  return true;
}
Program: 178918
Project: 178918
Buggy source:
@Override protected void createActions(){
  super.createActions();
  ResourceBundle bundle=ResourceBundle.getBundle("String_Node_Str");
  setAction("String_Node_Str",new TextOperationAction(bundle,"String_Node_Str",this,ISourceViewer.CONTENTASSIST_PROPOSALS));
}

Fixed version (ground truth):
@Override protected void createActions(){
  super.createActions();
  ResourceBundle bundle=ResourceBundle.getBundle("String_Node_Str");
  Action action=new TextOperationAction(bundle,"String_Node_Str",this,ISourceViewer.CONTENTASSIST_PROPOSALS);
  String id=ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS;
  action.setActionDefinitionId(id);
  setAction("String_Node_Str",action);
  markAsStateDependentAction("String_Node_Str",true);
}
Program: 178919
Project: 178919
Buggy source:
public void setSelectionRange(int start,int length){
  getSourceViewer().getTextWidget().setSelectionRange(start,length);
}

Fixed version (ground truth):
public void setSelectionRange(int start,int length){
  getSourceViewer().getTextWidget().setSelectionRange(start,length);
  getSourceViewer().getTextWidget().showSelection();
}
Program: 178920
Project: 178920
Buggy source:
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer,int offset){
  List<ICompletionProposal> result=new ArrayList<ICompletionProposal>();
  IDocument document=viewer.getDocument();
  String macroPrefix=Utils.getPrefix(document,offset,'#',"String_Node_Str");
  if (macroPrefix != null) {
    for (    String directive : getMacros(document,offset)) {
      if (directive.startsWith(macroPrefix)) {
        int cursorPos;
        if (directive.equals(VelocityDirectiveType.ELSE) || directive.equals(VelocityDirectiveType.END) || directive.equals(VelocityDirectiveType.STOP)) {
          cursorPos=directive.length() - 1;
        }
 else {
          directive+="String_Node_Str";
          cursorPos=directive.length() - 2;
        }
        result.add(new CompletionProposal(directive,offset - macroPrefix.length(),macroPrefix.length(),cursorPos,null,"String_Node_Str" + directive,null,null));
      }
    }
    Collections.sort(result,new Comparator<ICompletionProposal>(){
      public int compare(      ICompletionProposal proposal1,      ICompletionProposal proposal2){
        return proposal1.getDisplayString().compareTo(proposal2.getDisplayString());
      }
      public boolean equals(      Object proposal){
        return false;
      }
    }
);
    return result.toArray(new ICompletionProposal[result.size()]);
  }
  if (result.size() > 0) {
    return result.toArray(new ICompletionProposal[result.size()]);
  }
  return null;
}

Fixed version (ground truth):
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer,int offset){
  List<ICompletionProposal> result=new ArrayList<ICompletionProposal>();
  IDocument document=viewer.getDocument();
  String macroPrefix=Utils.getPrefix(document,offset,"String_Node_Str","String_Node_Str");
  if (macroPrefix != null) {
    for (    String directive : getMacros(document,offset)) {
      if (directive.startsWith(macroPrefix)) {
        int cursorPos;
        if (directive.equals(VelocityDirectiveType.ELSE) || directive.equals(VelocityDirectiveType.END) || directive.equals(VelocityDirectiveType.STOP)) {
          cursorPos=directive.length() - 1;
        }
 else {
          directive+="String_Node_Str";
          cursorPos=directive.length() - 2;
        }
        result.add(new CompletionProposal(directive,offset - macroPrefix.length(),macroPrefix.length(),cursorPos,null,"String_Node_Str" + directive,null,null));
      }
    }
    Collections.sort(result,new Comparator<ICompletionProposal>(){
      public int compare(      ICompletionProposal proposal1,      ICompletionProposal proposal2){
        return proposal1.getDisplayString().compareTo(proposal2.getDisplayString());
      }
      public boolean equals(      Object proposal){
        return false;
      }
    }
);
    return result.toArray(new ICompletionProposal[result.size()]);
  }
  if (result.size() > 0) {
    return result.toArray(new ICompletionProposal[result.size()]);
  }
  return null;
}
Program: 178921
Project: 178921
Buggy source:
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer,int offset){
  IDocument document=viewer.getDocument();
  String variablePrefix=Utils.getPrefix(document,offset,'$',"String_Node_Str");
  if (variablePrefix != null) {
    if (!variablePrefix.contains("String_Node_Str")) {
      List<ICompletionProposal> result=new ArrayList<ICompletionProposal>();
      for (      String variable : getVariables(document,offset)) {
        if (variable.startsWith(variablePrefix)) {
          result.add(new CompletionProposal(variable,offset - variablePrefix.length(),variablePrefix.length(),variable.length(),null,"String_Node_Str" + variable,null,null));
        }
      }
      Collections.sort(result,new Comparator<ICompletionProposal>(){
        public int compare(        ICompletionProposal proposal1,        ICompletionProposal proposal2){
          return proposal1.getDisplayString().compareTo(proposal2.getDisplayString());
        }
        public boolean equals(        Object proposal){
          return false;
        }
      }
);
      return result.toArray(new ICompletionProposal[result.size()]);
    }
 else {
      int index=variablePrefix.indexOf('.');
      XWikiApiType xwikiApiType=XWikiApiType.valueOf(variablePrefix.substring(0,index).toUpperCase());
      XWikiApiCompletionProcessor xwikiAPIProcessor=new XWikiApiCompletionProcessor(xwikiApiType);
      return xwikiAPIProcessor.computeCompletionProposals(viewer,offset);
    }
  }
  return null;
}

Fixed version (ground truth):
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer,int offset){
  IDocument document=viewer.getDocument();
  String variablePrefix=Utils.getPrefix(document,offset,"String_Node_Str","String_Node_Str");
  if (variablePrefix != null) {
    if (!variablePrefix.contains("String_Node_Str")) {
      List<ICompletionProposal> result=new ArrayList<ICompletionProposal>();
      for (      String variable : getVariables(document,offset)) {
        if (variable.startsWith(variablePrefix)) {
          result.add(new CompletionProposal(variable,offset - variablePrefix.length(),variablePrefix.length(),variable.length(),null,"String_Node_Str" + variable,null,null));
        }
      }
      Collections.sort(result,new Comparator<ICompletionProposal>(){
        public int compare(        ICompletionProposal proposal1,        ICompletionProposal proposal2){
          return proposal1.getDisplayString().compareTo(proposal2.getDisplayString());
        }
        public boolean equals(        Object proposal){
          return false;
        }
      }
);
      return result.toArray(new ICompletionProposal[result.size()]);
    }
 else {
      int index=variablePrefix.indexOf('.');
      XWikiApiType xwikiApiType=XWikiApiType.valueOf(variablePrefix.substring(0,index).toUpperCase());
      XWikiApiCompletionProcessor xwikiAPIProcessor=new XWikiApiCompletionProcessor(xwikiApiType);
      return xwikiAPIProcessor.computeCompletionProposals(viewer,offset);
    }
  }
  return null;
}
Program: 178922
Project: 178922
Buggy source:
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer,int offset){
  List<ICompletionProposal> result=new ArrayList<ICompletionProposal>();
  IDocument document=viewer.getDocument();
  String linkPrefix=Utils.getPrefix(document,offset,'[',"String_Node_Str");
  if (linkPrefix != null) {
    List<XWikiEclipsePageSummary> pageSummaries=UIPlugin.getDefault().getAllPageSummariesForDataManager(dataManager);
    for (    XWikiEclipsePageSummary pageSummary : pageSummaries) {
      String pageId=pageSummary.getData().getId();
      if (pageId.startsWith(linkPrefix)) {
        result.add(new CompletionProposal(pageId,offset - linkPrefix.length(),linkPrefix.length(),pageId.length(),null,pageId,null,null));
      }
    }
  }
  if (result.size() > 0) {
    return result.toArray(new ICompletionProposal[result.size()]);
  }
  return null;
}

Fixed version (ground truth):
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer,int offset){
  List<ICompletionProposal> result=new ArrayList<ICompletionProposal>();
  IDocument document=viewer.getDocument();
  String linkPrefix=Utils.getPrefix(document,offset,"String_Node_Str","String_Node_Str");
  if (linkPrefix != null) {
    List<XWikiEclipsePageSummary> pageSummaries=UIPlugin.getDefault().getAllPageSummariesForDataManager(dataManager);
    for (    XWikiEclipsePageSummary pageSummary : pageSummaries) {
      String pageId=pageSummary.getData().getId();
      if (pageId.startsWith(linkPrefix)) {
        result.add(new CompletionProposal(pageId,offset - linkPrefix.length(),linkPrefix.length(),pageId.length(),null,pageId,null,null));
      }
    }
  }
  if (result.size() > 0) {
    return result.toArray(new ICompletionProposal[result.size()]);
  }
  return null;
}
Program: 178923
Project: 178923
Buggy source:
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer,int offset){
  List<ICompletionProposal> result=new ArrayList<ICompletionProposal>();
  IDocument document=viewer.getDocument();
  String linkPrefix=Utils.getPrefix(document,offset,'[',"String_Node_Str");
  String variablePrefix=Utils.getPrefix(document,offset,'$',"String_Node_Str");
  String macroPrefix=Utils.getPrefix(document,offset,'#',"String_Node_Str");
  if (linkPrefix == null && variablePrefix == null && macroPrefix == null) {
    result.add(new CompletionProposal("String_Node_Str",offset,0,1,null,"String_Node_Str",null,null));
    result.add(new CompletionProposal("String_Node_Str",offset,0,2,null,"String_Node_Str",null,null));
    result.add(new CompletionProposal("String_Node_Str",offset,0,2,null,"String_Node_Str",null,null));
    result.add(new CompletionProposal("String_Node_Str",offset,0,2,null,"String_Node_Str",null,null));
    result.add(new CompletionProposal("String_Node_Str",offset,0,2,null,"String_Node_Str",null,null));
    result.add(new CompletionProposal("String_Node_Str",offset,0,2,null,"String_Node_Str",null,null));
    result.add(new CompletionProposal("String_Node_Str",offset,0,2,null,"String_Node_Str",null,null));
  }
  if (result.size() > 0) {
    return result.toArray(new ICompletionProposal[result.size()]);
  }
  return null;
}

Fixed version (ground truth):
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer,int offset){
  List<ICompletionProposal> result=new ArrayList<ICompletionProposal>();
  IDocument document=viewer.getDocument();
  String linkPrefix=Utils.getPrefix(document,offset,"String_Node_Str","String_Node_Str");
  String variablePrefix=Utils.getPrefix(document,offset,"String_Node_Str","String_Node_Str");
  String macroPrefix=Utils.getPrefix(document,offset,"String_Node_Str","String_Node_Str");
  if (linkPrefix == null && variablePrefix == null && macroPrefix == null) {
    result.add(new CompletionProposal("String_Node_Str",offset,0,1,null,"String_Node_Str",null,null));
    result.add(new CompletionProposal("String_Node_Str",offset,0,2,null,"String_Node_Str",null,null));
    result.add(new CompletionProposal("String_Node_Str",offset,0,2,null,"String_Node_Str",null,null));
    result.add(new CompletionProposal("String_Node_Str",offset,0,2,null,"String_Node_Str",null,null));
    result.add(new CompletionProposal("String_Node_Str",offset,0,2,null,"String_Node_Str",null,null));
    result.add(new CompletionProposal("String_Node_Str",offset,0,2,null,"String_Node_Str",null,null));
    result.add(new CompletionProposal("String_Node_Str",offset,0,2,null,"String_Node_Str",null,null));
  }
  if (result.size() > 0) {
    return result.toArray(new ICompletionProposal[result.size()]);
  }
  return null;
}
Program: 178924
Project: 178924
Buggy source:
/** 
 * Get a prefix from the current offset to a given character (not included). Examples (_ is the current offset): <code> [test_ : getPrefix(..., _, 0, '[', "]") = 'test' [test]..._ : getPrefix(..., _, 0, '[', "]") = null _ is the current offset </code>
 * @param document
 * @param offset The starting offset 
 * @param startCharacter The start character that marks the beginning of the scanning region.
 * @param blockingCharacters A string containing all the blocking characters that will make the scanning fail.
 * @return The found prefix or null if a blocking character is encountered or if the starCharacter is not found.
 */
public static String getPrefix(IDocument document,int offset,char startCharacter,String blockingCharacters){
  String result=null;
  if (offset == 0) {
    return null;
  }
  try {
    int currentOffset=offset - 1;
    while (currentOffset >= 0) {
      if (blockingCharacters.indexOf(document.getChar(currentOffset)) != -1) {
        result=null;
        break;
      }
      if (document.getChar(currentOffset) == startCharacter) {
        result=document.get(currentOffset + 1,offset - currentOffset - 1);
        break;
      }
      currentOffset--;
    }
  }
 catch (  BadLocationException e) {
    e.printStackTrace();
  }
  return result;
}

Fixed version (ground truth):
/** 
 * Get a prefix from the current offset to a given character (not included). Examples (_ is the current offset): <code> [test_ : getPrefix(..., _, 0, '[', "]") = 'test' [test]..._ : getPrefix(..., _, 0, '[', "]") = null _ is the current offset </code>
 * @param document
 * @param offset The starting offset 
 * @param startCharacter The start character that marks the beginning of the scanning region.
 * @param blockingCharacters A string containing all the blocking characters that will make the scanning fail.
 * @return The found prefix or null if a blocking character is encountered or if the starCharacter is not found.
 */
public static String getPrefix(IDocument document,int offset,String startCharacters,String blockingCharacters){
  String result=null;
  if (offset == 0) {
    return null;
  }
  try {
    int currentOffset=offset - 1;
    while (currentOffset >= 0) {
      if (blockingCharacters.indexOf(document.getChar(currentOffset)) != -1) {
        result=null;
        break;
      }
      if (startCharacters.indexOf(document.getChar(currentOffset)) != -1) {
        result=document.get(currentOffset + 1,offset - currentOffset - 1);
        break;
      }
      currentOffset--;
    }
  }
 catch (  BadLocationException e) {
    e.printStackTrace();
  }
  return result;
}