Program: 70845
Project: 70845
Buggy source:
public void processSelection(GLAutoDrawable drawable){
  if (!(myViewer instanceof GLViewer)) {
    return;
  }
  GLViewer viewer=(GLViewer)myViewer;
  GL2GL3 gl=(GL2GL3)(viewer.getGL());
  viewer.setColorEnabled(true);
  viewer.setDepthEnabled(true);
  viewer.setLightingEnabled(true);
  if (changeViewport) {
    gl.glViewport(mySavedViewport[0],mySavedViewport[1],mySavedViewport[2],mySavedViewport[3]);
  }
  viewer.clearPickMatrix();
  if (!myMaxQStack.isEmpty()) {
    throw new IllegalStateException("String_Node_Str");
  }
  int lastQidx=-1;
  for (int i=myTotalMaxQ - 1; i >= 0; i--) {
    if (myQueryWasUsed[i]) {
      lastQidx=i;
      break;
    }
  }
  if (lastQidx == -1) {
    myViewer.setSelected(new LinkedList[0]);
  }
 else {
    int[] available=new int[1];
    do {
      gl.glGetQueryObjectiv(myQueries[lastQidx],GL2.GL_QUERY_RESULT_AVAILABLE,available,0);
      if (available[0] == 0) {
        waitMsec(1);
      }
    }
 while (available[0] == 0);
    int qid=0;
    LinkedList<HitRecord> records=new LinkedList<HitRecord>();
    int[] result=new int[1];
    Iterator<GLRenderable> it=myViewer.renderIterator();
    while (it.hasNext()) {
      GLRenderable r=it.next();
      if (r instanceof GLSelectable) {
        GLSelectable s=(GLSelectable)r;
        int numq=s.numSelectionQueriesNeeded();
        int nums=(numq >= 0 ? numq : 1);
        if (s.isSelectable()) {
          for (int i=0; i < nums; i++) {
            if (myQueryWasUsed[qid + i]) {
              gl.glGetQueryObjectuiv(myQueries[qid + i],GL2.GL_QUERY_RESULT,result,0);
              if (result[0] > 0) {
                HitRecord rec=new HitRecord(result[0]);
                if (numq < 0) {
                  rec.objs.add(s);
                }
 else {
                  s.getSelection(rec.objs,i);
                }
                if (rec.objs.size() > 0) {
                  records.add(rec);
                }
              }
            }
          }
        }
        qid+=nums;
        if (qid > lastQidx) {
          break;
        }
      }
    }
    Collections.sort(records);
    LinkedList<Object>[] selObjs=new LinkedList[records.size()];
    for (int i=0; i < records.size(); i++) {
      selObjs[i]=records.get(i).objs;
    }
    myViewer.setSelected(selObjs);
  }
  gl.glDeleteQueries(myTotalMaxQ,myQueries,0);
  myQueries=null;
  myQueryWasUsed=null;
  GLSelectionListener[] listeners=myViewer.getSelectionListeners();
  for (int i=0; i < listeners.length; i++) {
    listeners[i].itemsSelected(myViewer.getSelectionEvent());
  }
  myViewer.getCanvas().repaint();
}

Fixed version (ground truth):
public void processSelection(GLAutoDrawable drawable){
  if (!(myViewer instanceof GLViewer)) {
    return;
  }
  GLViewer viewer=(GLViewer)myViewer;
  GL2GL3 gl=(GL2GL3)(drawable.getGL());
  viewer.setColorEnabled(true);
  viewer.setDepthEnabled(true);
  viewer.setLightingEnabled(true);
  if (changeViewport) {
    gl.glViewport(mySavedViewport[0],mySavedViewport[1],mySavedViewport[2],mySavedViewport[3]);
  }
  viewer.clearPickMatrix();
  if (!myMaxQStack.isEmpty()) {
    throw new IllegalStateException("String_Node_Str");
  }
  int lastQidx=-1;
  for (int i=myTotalMaxQ - 1; i >= 0; i--) {
    if (myQueryWasUsed[i]) {
      lastQidx=i;
      break;
    }
  }
  if (lastQidx == -1) {
    myViewer.setSelected(new LinkedList[0]);
  }
 else {
    int[] available=new int[1];
    do {
      gl.glGetQueryObjectiv(myQueries[lastQidx],GL2.GL_QUERY_RESULT_AVAILABLE,available,0);
      if (available[0] == 0) {
        waitMsec(1);
      }
    }
 while (available[0] == 0);
    int qid=0;
    LinkedList<HitRecord> records=new LinkedList<HitRecord>();
    int[] result=new int[1];
    Iterator<GLRenderable> it=myViewer.renderIterator();
    while (it.hasNext()) {
      GLRenderable r=it.next();
      if (r instanceof GLSelectable) {
        GLSelectable s=(GLSelectable)r;
        int numq=s.numSelectionQueriesNeeded();
        int nums=(numq >= 0 ? numq : 1);
        if (s.isSelectable()) {
          for (int i=0; i < nums; i++) {
            if (myQueryWasUsed[qid + i]) {
              gl.glGetQueryObjectuiv(myQueries[qid + i],GL2.GL_QUERY_RESULT,result,0);
              if (result[0] > 0) {
                HitRecord rec=new HitRecord(result[0]);
                if (numq < 0) {
                  rec.objs.add(s);
                }
 else {
                  s.getSelection(rec.objs,i);
                }
                if (rec.objs.size() > 0) {
                  records.add(rec);
                }
              }
            }
          }
        }
        qid+=nums;
        if (qid > lastQidx) {
          break;
        }
      }
    }
    Collections.sort(records);
    LinkedList<Object>[] selObjs=new LinkedList[records.size()];
    for (int i=0; i < records.size(); i++) {
      selObjs[i]=records.get(i).objs;
    }
    myViewer.setSelected(selObjs);
  }
  gl.glDeleteQueries(myTotalMaxQ,myQueries,0);
  myQueries=null;
  myQueryWasUsed=null;
  GLSelectionListener[] listeners=myViewer.getSelectionListeners();
  for (int i=0; i < listeners.length; i++) {
    listeners[i].itemsSelected(myViewer.getSelectionEvent());
  }
  myViewer.getCanvas().repaint();
}