Program: 71183
Project: 71183
Buggy source:
/** 
 * decompose a Step into steps that can be processed without permutations
 * @param s
 * @return 
 */
private List<Step> decomposeStep(Step s,int nqubit){
  ArrayList<Step> answer=new ArrayList<>();
  answer.add(s);
  List<Gate> gates=s.getGates();
  if (gates.isEmpty())   return answer;
  boolean notsimple=gates.stream().anyMatch(g -> (!(g instanceof SingleQubitGate)));
  if (!notsimple)   return answer;
  List<Gate> firstGates=new ArrayList<>();
  for (  Gate gate : gates) {
    if (gate instanceof SingleQubitGate) {
      firstGates.add(gate);
    }
 else     if (gate instanceof TwoQubitGate) {
      TwoQubitGate tqg=(TwoQubitGate)gate;
      int first=tqg.getMainQubit();
      int second=tqg.getSecondQubit();
      if (first == second - 1) {
        firstGates.add(gate);
      }
 else {
        if (first == second)         throw new RuntimeException("String_Node_Str" + gate);
        if (second > first) {
          Step prePermutation=new Step();
          PermutationGate pg=new PermutationGate(first + 1,second,nqubit);
          prePermutation.addGate(pg);
          answer.add(0,prePermutation);
          answer.add(prePermutation);
        }
 else {
          Step prePermutation=new Step();
          PermutationGate pg=new PermutationGate(first,second,nqubit);
          prePermutation.addGate(pg);
          answer.add(0,prePermutation);
          answer.add(prePermutation);
          Step postPermutation=new Step();
          PermutationGate pg2=new PermutationGate(second + 1,first,nqubit);
          postPermutation.addGate(pg2);
          answer.add(0,postPermutation);
          answer.add(postPermutation);
          for (int i=second; i < first; i++) {
            Swap swap=new Swap(i,i + 1);
            prePermutation.addGate(swap);
          }
          tqg.setMainQubit(first - 1);
          tqg.setAdditionalQubit(first,0);
        }
      }
    }
 else {
      throw new RuntimeException("String_Node_Str");
    }
  }
  return answer;
}

Fixed version (ground truth):
/** 
 * decompose a Step into steps that can be processed without permutations
 * @param s
 * @return 
 */
private List<Step> decomposeStep(Step s,int nqubit){
  ArrayList<Step> answer=new ArrayList<>();
  answer.add(s);
  List<Gate> gates=s.getGates();
  if (gates.isEmpty())   return answer;
  boolean notsimple=gates.stream().anyMatch(g -> (!(g instanceof SingleQubitGate)));
  if (!notsimple)   return answer;
  List<Gate> firstGates=new ArrayList<>();
  for (  Gate gate : gates) {
    if (gate instanceof SingleQubitGate) {
      firstGates.add(gate);
    }
 else     if (gate instanceof TwoQubitGate) {
      TwoQubitGate tqg=(TwoQubitGate)gate;
      int first=tqg.getMainQubit();
      int second=tqg.getSecondQubit();
      if (first == second - 1) {
        firstGates.add(gate);
      }
 else {
        if (first == second)         throw new RuntimeException("String_Node_Str" + gate);
        if (second > first) {
          Step prePermutation=new Step();
          PermutationGate pg=new PermutationGate(first + 1,second,nqubit);
          prePermutation.addGate(pg);
          answer.add(0,prePermutation);
          answer.add(prePermutation);
        }
 else {
          Step prePermutation=new Step();
          PermutationGate pg=new PermutationGate(first,second,nqubit);
          prePermutation.addGate(pg);
          answer.add(0,prePermutation);
          answer.add(prePermutation);
          Step postPermutation=new Step();
          PermutationGate pg2=new PermutationGate(second + 1,first,nqubit);
          postPermutation.addGate(pg2);
          answer.add(0,postPermutation);
          answer.add(postPermutation);
          tqg.setMainQubit(second);
          tqg.setAdditionalQubit(second + 1,0);
        }
      }
    }
 else {
      throw new RuntimeException("String_Node_Str");
    }
  }
  return answer;
}