Program: 33785
Project: 33785
Buggy source:
/** 
 * Builds a SAX representation.
 * @param timeseries
 * @param threadsNum
 * @param slidingWindowSize
 * @param paaSize
 * @param alphabetSize
 * @param nrStrategy
 * @param normalizationThreshold
 * @return
 * @throws TSException
 */
public SAXRecords process(double[] timeseries,int threadsNum,int slidingWindowSize,int paaSize,int alphabetSize,NumerosityReductionStrategy nrStrategy,double normalizationThreshold) throws TSException {
  consoleLogger.debug("String_Node_Str");
  NormalAlphabet alphabet=new NormalAlphabet();
  SAXRecords res=new SAXRecords(0);
  ExecutorService executorService=Executors.newFixedThreadPool(threadsNum);
  consoleLogger.debug("String_Node_Str" + threadsNum + "String_Node_Str");
  CompletionService<SAXRecords> completionService=new ExecutorCompletionService<SAXRecords>(executorService);
  int totalTaskCounter=0;
  long tstamp=System.currentTimeMillis();
  int evenIncrement=timeseries.length / threadsNum;
  int reminder=timeseries.length % threadsNum;
  int firstChunkSize=evenIncrement + reminder;
  consoleLogger.debug("String_Node_Str" + timeseries.length + "String_Node_Str"+ evenIncrement+ "String_Node_Str"+ reminder+ "String_Node_Str"+ firstChunkSize);
{
    int firstChunkStart=0;
    int firstChunkEnd=firstChunkSize + slidingWindowSize - 1;
    final SAXWorker job0=new SAXWorker(tstamp + totalTaskCounter,timeseries,firstChunkStart,firstChunkEnd,slidingWindowSize,paaSize,alphabetSize,nrStrategy,normalizationThreshold);
    completionService.submit(job0);
    consoleLogger.debug("String_Node_Str" + tstamp);
    totalTaskCounter++;
  }
  while (totalTaskCounter < threadsNum - 1) {
    int intermediateChunkStart=firstChunkSize + (totalTaskCounter - 1) * evenIncrement;
    int intermediateChunkEnd=firstChunkSize + (totalTaskCounter * evenIncrement) + slidingWindowSize - 1;
    final SAXWorker job=new SAXWorker(tstamp + totalTaskCounter,timeseries,intermediateChunkStart,intermediateChunkEnd,slidingWindowSize,paaSize,alphabetSize,nrStrategy,normalizationThreshold);
    completionService.submit(job);
    consoleLogger.debug("String_Node_Str" + Long.valueOf(tstamp + totalTaskCounter));
    totalTaskCounter++;
  }
{
    int lastChunkStart=timeseries.length - evenIncrement;
    int lastChunkEnd=timeseries.length;
    final SAXWorker jobN=new SAXWorker(tstamp + totalTaskCounter,timeseries,lastChunkStart,lastChunkEnd,slidingWindowSize,paaSize,alphabetSize,nrStrategy,normalizationThreshold);
    completionService.submit(jobN);
    consoleLogger.debug("String_Node_Str" + Long.valueOf(tstamp + totalTaskCounter));
    totalTaskCounter++;
  }
  executorService.shutdown();
  try {
    while (totalTaskCounter > 0) {
      Future<SAXRecords> finished=completionService.poll(128,TimeUnit.HOURS);
      if (null == finished) {
        System.err.println("String_Node_Str");
        break;
      }
 else {
        SAXRecords chunkRes=finished.get();
        int idx=(int)(chunkRes.getId() - tstamp);
        consoleLogger.debug("String_Node_Str" + chunkRes.getId() + "String_Node_Str"+ idx+ "String_Node_Str");
        if (0 == res.size()) {
          res.addAll(chunkRes);
          consoleLogger.debug("String_Node_Str");
        }
 else {
          consoleLogger.debug("String_Node_Str" + idx + "String_Node_Str");
          if (0 == idx) {
            consoleLogger.debug("String_Node_Str");
            int tailIndex=chunkRes.getMaxIndex();
            SaxRecord chunkTail=chunkRes.getByIndex(tailIndex);
            int resHeadIndex=firstChunkSize - 1;
            while ((null == res.getByIndex(resHeadIndex)) && (resHeadIndex < (firstChunkSize + evenIncrement))) {
              resHeadIndex++;
            }
            if (resHeadIndex < (firstChunkSize + evenIncrement - 1)) {
              SaxRecord resHead=res.getByIndex(resHeadIndex);
              consoleLogger.debug("String_Node_Str" + resHeadIndex + "String_Node_Str"+ String.valueOf(resHead.getPayload())+ "String_Node_Str"+ tailIndex+ "String_Node_Str"+ String.valueOf(chunkTail.getPayload()));
              if (nrStrategy.equals(NumerosityReductionStrategy.EXACT) && Arrays.equals(chunkTail.getPayload(),res.getByIndex(resHeadIndex).getPayload())) {
                consoleLogger.debug("String_Node_Str" + String.valueOf(res.getByIndex(resHeadIndex).getPayload()) + "String_Node_Str"+ resHeadIndex+ "String_Node_Str"+ String.valueOf(chunkTail.getPayload())+ "String_Node_Str"+ tailIndex);
                res.dropByIndex(resHeadIndex);
              }
 else               if (nrStrategy.equals(NumerosityReductionStrategy.MINDIST) && (0.0 == SAXFactory.saxMinDist(chunkTail.getPayload(),res.getByIndex(resHeadIndex).getPayload(),alphabet.getDistanceMatrix(alphabetSize)))) {
                consoleLogger.debug("String_Node_Str" + String.valueOf(res.getByIndex(resHeadIndex).getPayload()) + "String_Node_Str"+ resHeadIndex+ "String_Node_Str"+ String.valueOf(chunkTail.getPayload())+ "String_Node_Str"+ tailIndex);
                res.dropByIndex(resHeadIndex);
              }
 else {
                consoleLogger.debug("String_Node_Str");
              }
            }
            res.addAll(chunkRes);
          }
 else {
            consoleLogger.debug("String_Node_Str" + idx);
{
              int resLeftmostIndex=res.getMinIndex();
              int chunkLeftmostIndex=chunkRes.getMinIndex();
              SaxRecord chunkLeftmostEntry=chunkRes.getByIndex(chunkLeftmostIndex);
              consoleLogger.debug("String_Node_Str" + resLeftmostIndex + "String_Node_Str"+ chunkLeftmostIndex);
              if (resLeftmostIndex < chunkLeftmostIndex) {
                consoleLogger.debug("String_Node_Str");
                int leftOfChunkIndex=chunkLeftmostIndex;
                while ((null == res.getByIndex(leftOfChunkIndex)) && (leftOfChunkIndex >= resLeftmostIndex) && (leftOfChunkIndex >= chunkLeftmostIndex - evenIncrement)) {
                  leftOfChunkIndex--;
                }
                if (leftOfChunkIndex >= chunkLeftmostIndex - evenIncrement) {
                  SaxRecord resLeftEntry=res.getByIndex(leftOfChunkIndex);
                  consoleLogger.debug("String_Node_Str" + leftOfChunkIndex + "String_Node_Str"+ String.valueOf(resLeftEntry.getPayload())+ "String_Node_Str"+ chunkLeftmostIndex+ "String_Node_Str"+ String.valueOf(chunkLeftmostEntry.getPayload()));
                  if (nrStrategy.equals(NumerosityReductionStrategy.EXACT) && Arrays.equals(resLeftEntry.getPayload(),chunkLeftmostEntry.getPayload())) {
                    consoleLogger.debug("String_Node_Str" + String.valueOf(resLeftEntry.getPayload()) + "String_Node_Str"+ leftOfChunkIndex+ "String_Node_Str"+ String.valueOf(chunkLeftmostEntry.getPayload())+ "String_Node_Str"+ chunkLeftmostIndex);
                    res.dropByIndex(leftOfChunkIndex);
                  }
 else                   if (nrStrategy.equals(NumerosityReductionStrategy.MINDIST) && (0.0 == SAXFactory.saxMinDist(resLeftEntry.getPayload(),chunkLeftmostEntry.getPayload(),alphabet.getDistanceMatrix(alphabetSize)))) {
                    consoleLogger.debug("String_Node_Str" + String.valueOf(resLeftEntry.getPayload()) + "String_Node_Str"+ leftOfChunkIndex+ "String_Node_Str"+ String.valueOf(chunkLeftmostEntry.getPayload())+ "String_Node_Str"+ chunkLeftmostIndex);
                    res.dropByIndex(leftOfChunkIndex);
                  }
                }
              }
            }
{
              int resRightmostIndex=res.getMaxIndex();
              int chunkRightmostIndex=chunkRes.getMaxIndex();
              SaxRecord chunkRightmostEntry=chunkRes.getByIndex(chunkRightmostIndex);
              consoleLogger.debug("String_Node_Str" + resRightmostIndex + "String_Node_Str"+ chunkRightmostIndex);
              if (resRightmostIndex > chunkRightmostIndex) {
                int rightOfChunkIndex=chunkRightmostIndex;
                while ((null == res.getByIndex(rightOfChunkIndex)) && (rightOfChunkIndex <= resRightmostIndex) && (rightOfChunkIndex <= chunkRightmostIndex + evenIncrement)) {
                  rightOfChunkIndex++;
                }
                if (rightOfChunkIndex <= chunkRightmostIndex + evenIncrement) {
                  SaxRecord resRightEntry=res.getByIndex(rightOfChunkIndex);
                  consoleLogger.debug("String_Node_Str" + rightOfChunkIndex + "String_Node_Str"+ String.valueOf(resRightEntry.getPayload())+ "String_Node_Str"+ chunkRightmostIndex+ "String_Node_Str"+ String.valueOf(chunkRightmostEntry.getPayload()));
                  if (nrStrategy.equals(NumerosityReductionStrategy.EXACT) && Arrays.equals(resRightEntry.getPayload(),chunkRightmostEntry.getPayload())) {
                    consoleLogger.debug("String_Node_Str" + String.valueOf(resRightEntry.getPayload()) + "String_Node_Str"+ rightOfChunkIndex+ "String_Node_Str"+ String.valueOf(chunkRightmostEntry.getPayload())+ "String_Node_Str"+ chunkRightmostIndex);
                    res.dropByIndex(rightOfChunkIndex);
                  }
 else                   if (nrStrategy.equals(NumerosityReductionStrategy.MINDIST) && (0.0 == SAXFactory.saxMinDist(resRightEntry.getPayload(),chunkRightmostEntry.getPayload(),alphabet.getDistanceMatrix(alphabetSize)))) {
                    consoleLogger.debug("String_Node_Str" + String.valueOf(resRightEntry.getPayload()) + "String_Node_Str"+ rightOfChunkIndex+ "String_Node_Str"+ String.valueOf(chunkRightmostEntry.getPayload())+ "String_Node_Str"+ chunkRightmostIndex);
                    res.dropByIndex(rightOfChunkIndex);
                  }
                }
              }
            }
            res.addAll(chunkRes);
          }
        }
      }
      totalTaskCounter--;
    }
  }
 catch (  Exception e) {
    System.err.println("String_Node_Str" + StackTrace.toString(e));
  }
 finally {
    try {
      if (!executorService.awaitTermination(4,TimeUnit.HOURS)) {
        executorService.shutdownNow();
        if (!executorService.awaitTermination(30,TimeUnit.MINUTES))         System.err.println("String_Node_Str");
      }
    }
 catch (    InterruptedException ie) {
      System.err.println("String_Node_Str" + StackTrace.toString(ie));
      executorService.shutdownNow();
      Thread.currentThread().interrupt();
    }
  }
  return res;
}

Fixed version (ground truth):
/** 
 * Builds a SAX representation.
 * @param timeseries
 * @param threadsNum
 * @param slidingWindowSize
 * @param paaSize
 * @param alphabetSize
 * @param nrStrategy
 * @param normalizationThreshold
 * @return
 * @throws TSException
 */
public SAXRecords process(double[] timeseries,int threadsNum,int slidingWindowSize,int paaSize,int alphabetSize,NumerosityReductionStrategy nrStrategy,double normalizationThreshold) throws TSException {
  consoleLogger.debug("String_Node_Str");
  NormalAlphabet alphabet=new NormalAlphabet();
  SAXRecords res=new SAXRecords(0);
  ExecutorService executorService=Executors.newFixedThreadPool(threadsNum);
  consoleLogger.debug("String_Node_Str" + threadsNum + "String_Node_Str");
  CompletionService<SAXRecords> completionService=new ExecutorCompletionService<SAXRecords>(executorService);
  int totalTaskCounter=0;
  long tstamp=System.currentTimeMillis();
  int evenIncrement=timeseries.length / threadsNum;
  int reminder=timeseries.length % threadsNum;
  int firstChunkSize=evenIncrement + reminder;
  consoleLogger.debug("String_Node_Str" + timeseries.length + "String_Node_Str"+ evenIncrement+ "String_Node_Str"+ reminder+ "String_Node_Str"+ firstChunkSize);
{
    int firstChunkStart=0;
    int firstChunkEnd=firstChunkSize + slidingWindowSize - 1;
    final SAXWorker job0=new SAXWorker(tstamp + totalTaskCounter,timeseries,firstChunkStart,firstChunkEnd,slidingWindowSize,paaSize,alphabetSize,nrStrategy,normalizationThreshold);
    completionService.submit(job0);
    consoleLogger.debug("String_Node_Str" + tstamp);
    totalTaskCounter++;
  }
  while (totalTaskCounter < threadsNum - 1) {
    int intermediateChunkStart=firstChunkSize + (totalTaskCounter - 1) * evenIncrement;
    int intermediateChunkEnd=firstChunkSize + (totalTaskCounter * evenIncrement) + slidingWindowSize - 1;
    final SAXWorker job=new SAXWorker(tstamp + totalTaskCounter,timeseries,intermediateChunkStart,intermediateChunkEnd,slidingWindowSize,paaSize,alphabetSize,nrStrategy,normalizationThreshold);
    completionService.submit(job);
    consoleLogger.debug("String_Node_Str" + Long.valueOf(tstamp + totalTaskCounter));
    totalTaskCounter++;
  }
{
    int lastChunkStart=timeseries.length - evenIncrement;
    int lastChunkEnd=timeseries.length;
    final SAXWorker jobN=new SAXWorker(tstamp + totalTaskCounter,timeseries,lastChunkStart,lastChunkEnd,slidingWindowSize,paaSize,alphabetSize,nrStrategy,normalizationThreshold);
    completionService.submit(jobN);
    consoleLogger.debug("String_Node_Str" + Long.valueOf(tstamp + totalTaskCounter));
    totalTaskCounter++;
  }
  executorService.shutdown();
  try {
    while (totalTaskCounter > 0) {
      Future<SAXRecords> finished=completionService.poll(128,TimeUnit.HOURS);
      if (null == finished) {
        System.err.println("String_Node_Str");
        break;
      }
 else {
        SAXRecords chunkRes=finished.get();
        int idx=(int)(chunkRes.getId() - tstamp);
        consoleLogger.debug("String_Node_Str" + chunkRes.getId() + "String_Node_Str"+ idx+ "String_Node_Str");
        if (0 == res.size()) {
          res.addAll(chunkRes);
          consoleLogger.debug("String_Node_Str");
        }
 else {
          consoleLogger.debug("String_Node_Str" + idx + "String_Node_Str");
          if (0 == idx) {
            consoleLogger.debug("String_Node_Str");
            int chunkTailIndex=chunkRes.getMaxIndex();
            SaxRecord chunkTail=chunkRes.getByIndex(chunkTailIndex);
            int resultHeadIndex=firstChunkSize - 1;
            while ((null == res.getByIndex(resultHeadIndex)) && (resultHeadIndex < (firstChunkSize + evenIncrement))) {
              resultHeadIndex++;
            }
            if (resultHeadIndex < (firstChunkSize + evenIncrement - 1)) {
              SaxRecord resHead=res.getByIndex(resultHeadIndex);
              consoleLogger.debug("String_Node_Str" + resultHeadIndex + "String_Node_Str"+ String.valueOf(resHead.getPayload())+ "String_Node_Str"+ chunkTailIndex+ "String_Node_Str"+ String.valueOf(chunkTail.getPayload()));
              if (nrStrategy.equals(NumerosityReductionStrategy.EXACT) && Arrays.equals(chunkTail.getPayload(),res.getByIndex(resultHeadIndex).getPayload())) {
                consoleLogger.debug("String_Node_Str" + String.valueOf(res.getByIndex(resultHeadIndex).getPayload()) + "String_Node_Str"+ resultHeadIndex+ "String_Node_Str"+ String.valueOf(chunkTail.getPayload())+ "String_Node_Str"+ chunkTailIndex);
                res.dropByIndex(resultHeadIndex);
              }
 else               if (nrStrategy.equals(NumerosityReductionStrategy.MINDIST) && (0.0 == SAXFactory.saxMinDist(chunkTail.getPayload(),res.getByIndex(resultHeadIndex).getPayload(),alphabet.getDistanceMatrix(alphabetSize)))) {
                consoleLogger.debug("String_Node_Str" + String.valueOf(res.getByIndex(resultHeadIndex).getPayload()) + "String_Node_Str"+ resultHeadIndex+ "String_Node_Str"+ String.valueOf(chunkTail.getPayload())+ "String_Node_Str"+ chunkTailIndex);
                res.dropByIndex(resultHeadIndex);
              }
 else {
                consoleLogger.debug("String_Node_Str");
              }
            }
            res.addAll(chunkRes);
          }
 else {
            consoleLogger.debug("String_Node_Str" + idx);
{
              int resLeftmostIndex=res.getMinIndex();
              int chunkLeftmostIndex=chunkRes.getMinIndex();
              SaxRecord chunkLeftmostEntry=chunkRes.getByIndex(chunkLeftmostIndex);
              consoleLogger.debug("String_Node_Str" + resLeftmostIndex + "String_Node_Str"+ chunkLeftmostIndex);
              if (resLeftmostIndex < chunkLeftmostIndex) {
                consoleLogger.debug("String_Node_Str");
                int leftOfChunkIndex=chunkLeftmostIndex;
                while ((null == res.getByIndex(leftOfChunkIndex)) && (leftOfChunkIndex >= resLeftmostIndex) && (leftOfChunkIndex >= chunkLeftmostIndex - evenIncrement)) {
                  leftOfChunkIndex--;
                }
                if (leftOfChunkIndex >= chunkLeftmostIndex - evenIncrement) {
                  SaxRecord resLeftEntry=res.getByIndex(leftOfChunkIndex);
                  consoleLogger.debug("String_Node_Str" + leftOfChunkIndex + "String_Node_Str"+ String.valueOf(resLeftEntry.getPayload())+ "String_Node_Str"+ chunkLeftmostIndex+ "String_Node_Str"+ String.valueOf(chunkLeftmostEntry.getPayload()));
                  if (nrStrategy.equals(NumerosityReductionStrategy.EXACT) && Arrays.equals(resLeftEntry.getPayload(),chunkLeftmostEntry.getPayload())) {
                    consoleLogger.debug("String_Node_Str" + String.valueOf(chunkLeftmostEntry.getPayload()) + "String_Node_Str"+ chunkLeftmostIndex+ "String_Node_Str"+ String.valueOf(resLeftEntry.getPayload())+ "String_Node_Str"+ leftOfChunkIndex);
                    chunkRes.dropByIndex(chunkLeftmostIndex);
                  }
 else                   if (nrStrategy.equals(NumerosityReductionStrategy.MINDIST) && (0.0 == SAXFactory.saxMinDist(resLeftEntry.getPayload(),chunkLeftmostEntry.getPayload(),alphabet.getDistanceMatrix(alphabetSize)))) {
                    consoleLogger.debug("String_Node_Str" + String.valueOf(resLeftEntry.getPayload()) + "String_Node_Str"+ leftOfChunkIndex+ "String_Node_Str"+ String.valueOf(chunkLeftmostEntry.getPayload())+ "String_Node_Str"+ chunkLeftmostIndex);
                    res.dropByIndex(leftOfChunkIndex);
                  }
                }
              }
            }
{
              int resRightmostIndex=res.getMaxIndex();
              int chunkRightmostIndex=chunkRes.getMaxIndex();
              SaxRecord chunkRightmostEntry=chunkRes.getByIndex(chunkRightmostIndex);
              consoleLogger.debug("String_Node_Str" + resRightmostIndex + "String_Node_Str"+ chunkRightmostIndex);
              if (resRightmostIndex > chunkRightmostIndex) {
                int rightOfChunkIndex=chunkRightmostIndex;
                while ((null == res.getByIndex(rightOfChunkIndex)) && (rightOfChunkIndex <= resRightmostIndex) && (rightOfChunkIndex <= chunkRightmostIndex + evenIncrement)) {
                  rightOfChunkIndex++;
                }
                if (rightOfChunkIndex <= chunkRightmostIndex + evenIncrement) {
                  SaxRecord resRightEntry=res.getByIndex(rightOfChunkIndex);
                  consoleLogger.debug("String_Node_Str" + rightOfChunkIndex + "String_Node_Str"+ String.valueOf(resRightEntry.getPayload())+ "String_Node_Str"+ chunkRightmostIndex+ "String_Node_Str"+ String.valueOf(chunkRightmostEntry.getPayload()));
                  if (nrStrategy.equals(NumerosityReductionStrategy.EXACT) && Arrays.equals(resRightEntry.getPayload(),chunkRightmostEntry.getPayload())) {
                    consoleLogger.debug("String_Node_Str" + String.valueOf(resRightEntry.getPayload()) + "String_Node_Str"+ rightOfChunkIndex+ "String_Node_Str"+ String.valueOf(chunkRightmostEntry.getPayload())+ "String_Node_Str"+ chunkRightmostIndex);
                    res.dropByIndex(rightOfChunkIndex);
                  }
 else                   if (nrStrategy.equals(NumerosityReductionStrategy.MINDIST) && (0.0 == SAXFactory.saxMinDist(resRightEntry.getPayload(),chunkRightmostEntry.getPayload(),alphabet.getDistanceMatrix(alphabetSize)))) {
                    consoleLogger.debug("String_Node_Str" + String.valueOf(resRightEntry.getPayload()) + "String_Node_Str"+ rightOfChunkIndex+ "String_Node_Str"+ String.valueOf(chunkRightmostEntry.getPayload())+ "String_Node_Str"+ chunkRightmostIndex);
                    res.dropByIndex(rightOfChunkIndex);
                  }
                }
              }
            }
            res.addAll(chunkRes);
          }
        }
      }
      totalTaskCounter--;
    }
  }
 catch (  Exception e) {
    System.err.println("String_Node_Str" + StackTrace.toString(e));
  }
 finally {
    try {
      if (!executorService.awaitTermination(4,TimeUnit.HOURS)) {
        executorService.shutdownNow();
        if (!executorService.awaitTermination(30,TimeUnit.MINUTES))         System.err.println("String_Node_Str");
      }
    }
 catch (    InterruptedException ie) {
      System.err.println("String_Node_Str" + StackTrace.toString(ie));
      executorService.shutdownNow();
      Thread.currentThread().interrupt();
    }
  }
  return res;
}