Program: 28705
Project: 28705
Buggy source:
public void restoreRevision(String revision) throws CannotRestoreSiddhiAppStateException {
  PersistenceStore persistenceStore=siddhiAppContext.getSiddhiContext().getPersistenceStore();
  IncrementalPersistenceStore incrementalPersistenceStore=siddhiAppContext.getSiddhiContext().getIncrementalPersistenceStore();
  String siddhiAppName=siddhiAppContext.getName();
  if (persistenceStore != null) {
    if (log.isDebugEnabled()) {
      log.debug("String_Node_Str" + revision + "String_Node_Str");
    }
    byte[] snapshot=persistenceStore.load(siddhiAppContext.getName(),revision);
    if (snapshot != null) {
      restore(snapshot);
      if (log.isDebugEnabled()) {
        log.debug("String_Node_Str" + revision);
      }
    }
 else {
      if (log.isDebugEnabled()) {
        log.debug("String_Node_Str" + revision);
      }
    }
  }
 else   if (incrementalPersistenceStore != null) {
    if (log.isDebugEnabled()) {
      log.debug("String_Node_Str" + revision + "String_Node_Str");
    }
    IncrementalSnapshotInfo restoreSnapshotInfo=PersistenceHelper.convertRevision(revision);
    List<IncrementalSnapshotInfo> incrementalSnapshotInfos=incrementalPersistenceStore.getListOfRevisionsToLoad(restoreSnapshotInfo.getTime(),restoreSnapshotInfo.getSiddhiAppId());
    if (incrementalSnapshotInfos != null) {
      incrementalSnapshotInfos.sort(new Comparator<IncrementalSnapshotInfo>(){
        @Override public int compare(        IncrementalSnapshotInfo o1,        IncrementalSnapshotInfo o2){
          int results=o1.getElementId().compareTo(o2.getElementId());
          if (results == 0) {
            results=Long.compare(o2.getTime(),o1.getTime());
            if (results == 0) {
              return o2.getType().compareTo(o1.getType());
            }
          }
          return results;
        }
      }
);
      String lastElementId=null;
      boolean baseFound=false;
      for (Iterator<IncrementalSnapshotInfo> iterator=incrementalSnapshotInfos.iterator(); iterator.hasNext(); ) {
        IncrementalSnapshotInfo snapshotInfo=iterator.next();
        if (snapshotInfo.getElementId().equals(lastElementId)) {
          if (baseFound) {
            iterator.remove();
          }
 else           if (snapshotInfo.getType() == IncrementalSnapshotInfo.SnapshotType.BASE) {
            baseFound=true;
          }
        }
 else {
          baseFound=snapshotInfo.getType() == IncrementalSnapshotInfo.SnapshotType.BASE;
        }
        lastElementId=snapshotInfo.getElementId();
      }
      Map<String,Map<String,Map<Long,Map<IncrementalSnapshotInfo,byte[]>>>> incrementalState=new HashMap<>();
      for (      IncrementalSnapshotInfo snapshotInfo : incrementalSnapshotInfos) {
        Map<String,Map<Long,Map<IncrementalSnapshotInfo,byte[]>>> incrementalStateByElementId=incrementalState.computeIfAbsent(snapshotInfo.getQueryName(),k -> new TreeMap<>());
        Map<Long,Map<IncrementalSnapshotInfo,byte[]>> incrementalStateByTime=incrementalStateByElementId.computeIfAbsent(snapshotInfo.getElementId(),k -> new TreeMap<>());
        Map<IncrementalSnapshotInfo,byte[]> incrementalStateByInfo=incrementalStateByTime.computeIfAbsent(snapshotInfo.getTime(),k -> new HashMap<>());
        incrementalStateByInfo.put(snapshotInfo,incrementalPersistenceStore.load(snapshotInfo));
      }
      restore(incrementalState);
      if (log.isDebugEnabled()) {
        log.debug("String_Node_Str" + revision);
      }
    }
 else {
      if (log.isDebugEnabled()) {
        log.debug("String_Node_Str" + revision);
      }
    }
  }
 else {
    throw new NoPersistenceStoreException("String_Node_Str" + siddhiAppName);
  }
}

Fixed version (ground truth):
public void restoreRevision(String revision) throws CannotRestoreSiddhiAppStateException {
  PersistenceStore persistenceStore=siddhiAppContext.getSiddhiContext().getPersistenceStore();
  IncrementalPersistenceStore incrementalPersistenceStore=siddhiAppContext.getSiddhiContext().getIncrementalPersistenceStore();
  String siddhiAppName=siddhiAppContext.getName();
  if (persistenceStore != null) {
    if (log.isDebugEnabled()) {
      log.debug("String_Node_Str" + revision + "String_Node_Str");
    }
    byte[] snapshot=persistenceStore.load(siddhiAppContext.getName(),revision);
    if (snapshot != null) {
      restore(snapshot);
      if (log.isDebugEnabled()) {
        log.debug("String_Node_Str" + revision);
      }
    }
 else {
      if (log.isDebugEnabled()) {
        log.debug("String_Node_Str" + revision);
      }
      throw new PersistenceStoreException("String_Node_Str" + revision);
    }
  }
 else   if (incrementalPersistenceStore != null) {
    if (log.isDebugEnabled()) {
      log.debug("String_Node_Str" + revision + "String_Node_Str");
    }
    IncrementalSnapshotInfo restoreSnapshotInfo=PersistenceHelper.convertRevision(revision);
    List<IncrementalSnapshotInfo> incrementalSnapshotInfos=incrementalPersistenceStore.getListOfRevisionsToLoad(restoreSnapshotInfo.getTime(),restoreSnapshotInfo.getSiddhiAppId());
    if (incrementalSnapshotInfos != null) {
      incrementalSnapshotInfos.sort(new Comparator<IncrementalSnapshotInfo>(){
        @Override public int compare(        IncrementalSnapshotInfo o1,        IncrementalSnapshotInfo o2){
          int results=o1.getElementId().compareTo(o2.getElementId());
          if (results == 0) {
            results=Long.compare(o2.getTime(),o1.getTime());
            if (results == 0) {
              return o2.getType().compareTo(o1.getType());
            }
          }
          return results;
        }
      }
);
      String lastElementId=null;
      boolean baseFound=false;
      for (Iterator<IncrementalSnapshotInfo> iterator=incrementalSnapshotInfos.iterator(); iterator.hasNext(); ) {
        IncrementalSnapshotInfo snapshotInfo=iterator.next();
        if (snapshotInfo.getElementId().equals(lastElementId)) {
          if (baseFound) {
            iterator.remove();
          }
 else           if (snapshotInfo.getType() == IncrementalSnapshotInfo.SnapshotType.BASE) {
            baseFound=true;
          }
        }
 else {
          baseFound=snapshotInfo.getType() == IncrementalSnapshotInfo.SnapshotType.BASE;
        }
        lastElementId=snapshotInfo.getElementId();
      }
      Map<String,Map<String,Map<Long,Map<IncrementalSnapshotInfo,byte[]>>>> incrementalState=new HashMap<>();
      for (      IncrementalSnapshotInfo snapshotInfo : incrementalSnapshotInfos) {
        Map<String,Map<Long,Map<IncrementalSnapshotInfo,byte[]>>> incrementalStateByElementId=incrementalState.computeIfAbsent(snapshotInfo.getQueryName(),k -> new TreeMap<>());
        Map<Long,Map<IncrementalSnapshotInfo,byte[]>> incrementalStateByTime=incrementalStateByElementId.computeIfAbsent(snapshotInfo.getElementId(),k -> new TreeMap<>());
        Map<IncrementalSnapshotInfo,byte[]> incrementalStateByInfo=incrementalStateByTime.computeIfAbsent(snapshotInfo.getTime(),k -> new HashMap<>());
        incrementalStateByInfo.put(snapshotInfo,incrementalPersistenceStore.load(snapshotInfo));
      }
      restore(incrementalState);
      if (log.isDebugEnabled()) {
        log.debug("String_Node_Str" + revision);
      }
    }
 else {
      if (log.isDebugEnabled()) {
        log.debug("String_Node_Str" + revision);
      }
      throw new PersistenceStoreException("String_Node_Str" + revision);
    }
  }
 else {
    throw new NoPersistenceStoreException("String_Node_Str" + siddhiAppName);
  }
}