Program: 50998
Project: 50998
Buggy source:
private Result executeInternal(final Execution execution){
  final Statement statement=execution.getMondrianStatement();
  final Query query=statement.getQuery();
  final MemoryMonitor.Listener listener=new MemoryMonitor.Listener(){
    public void memoryUsageNotification(    long used,    long max){
      execution.setOutOfMemory("String_Node_Str" + used + "String_Node_Str"+ max+ "String_Node_Str"+ getConnectString());
    }
  }
;
  MemoryMonitor mm=MemoryMonitorFactory.getMemoryMonitor();
  final long currId=execution.getId();
  try {
    mm.addListener(listener);
    execution.checkCancelOrTimeout();
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug(Util.unparse(query));
    }
    if (RolapUtil.MDX_LOGGER.isDebugEnabled()) {
      RolapUtil.MDX_LOGGER.debug(currId + "String_Node_Str" + Util.unparse(query));
    }
    statement.start(execution);
    final Locus locus=new Locus(execution,null,"String_Node_Str");
    Locus.push(locus);
    Result result;
    try {
      result=new RolapResult(execution,true);
      int i=0;
      for (      QueryAxis axis : query.getAxes()) {
        if (axis.isNonEmpty()) {
          result=new NonEmptyResult(result,execution,i);
        }
        ++i;
      }
    }
  finally {
      Locus.pop(locus);
    }
    statement.end(execution);
    return result;
  }
 catch (  ResultLimitExceededException e) {
    throw e;
  }
catch (  Exception e) {
    statement.end(execution);
    String queryString;
    try {
      queryString=Util.unparse(query);
    }
 catch (    Exception e1) {
      queryString="String_Node_Str";
    }
    throw Util.newError(e,"String_Node_Str" + queryString + "String_Node_Str");
  }
 finally {
    mm.removeListener(listener);
    if (RolapUtil.MDX_LOGGER.isDebugEnabled()) {
      final long elapsed=execution.getElapsedMillis();
      RolapUtil.MDX_LOGGER.debug(currId + "String_Node_Str" + elapsed+ "String_Node_Str");
    }
  }
}

Fixed version (ground truth):
private Result executeInternal(final Execution execution){
  final Statement statement=execution.getMondrianStatement();
synchronized (statement) {
    final Execution previousExecution=statement.getCurrentExecution();
    if (previousExecution != null) {
      statement.end(previousExecution);
    }
  }
  final Query query=statement.getQuery();
  final MemoryMonitor.Listener listener=new MemoryMonitor.Listener(){
    public void memoryUsageNotification(    long used,    long max){
      execution.setOutOfMemory("String_Node_Str" + used + "String_Node_Str"+ max+ "String_Node_Str"+ getConnectString());
    }
  }
;
  MemoryMonitor mm=MemoryMonitorFactory.getMemoryMonitor();
  final long currId=execution.getId();
  try {
    mm.addListener(listener);
    execution.checkCancelOrTimeout();
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug(Util.unparse(query));
    }
    if (RolapUtil.MDX_LOGGER.isDebugEnabled()) {
      RolapUtil.MDX_LOGGER.debug(currId + "String_Node_Str" + Util.unparse(query));
    }
    statement.start(execution);
    final Locus locus=new Locus(execution,null,"String_Node_Str");
    Locus.push(locus);
    Result result;
    try {
      result=new RolapResult(execution,true);
      int i=0;
      for (      QueryAxis axis : query.getAxes()) {
        if (axis.isNonEmpty()) {
          result=new NonEmptyResult(result,execution,i);
        }
        ++i;
      }
    }
  finally {
      Locus.pop(locus);
    }
    statement.end(execution);
    return result;
  }
 catch (  ResultLimitExceededException e) {
    throw e;
  }
catch (  Exception e) {
    try {
      statement.end(execution);
    }
 catch (    Exception e1) {
    }
    String queryString;
    try {
      queryString=Util.unparse(query);
    }
 catch (    Exception e1) {
      queryString="String_Node_Str";
    }
    throw Util.newError(e,"String_Node_Str" + queryString + "String_Node_Str");
  }
 finally {
    mm.removeListener(listener);
    if (RolapUtil.MDX_LOGGER.isDebugEnabled()) {
      final long elapsed=execution.getElapsedMillis();
      RolapUtil.MDX_LOGGER.debug(currId + "String_Node_Str" + elapsed+ "String_Node_Str");
    }
  }
}