Program: 58848
Project: 58848
Buggy source:
/** 
 * This method has to be called in every display step. It is responsible for the ray tracing which does the actual picking. It needs the ID of the calling view and a gl context. It calls the display() method of the calling view, therefore only elements rendered in the display() can be picked.
 * @param canvasUser a reference to the calling view
 * @param gl the GL context
 */
public void handlePicking(final AGLEventListener canvasUser,final GL gl){
  if (bEnablePicking == false)   return;
  PickingMouseListener pickingTriggerMouseAdapter=canvasUser.getParentGLCanvas().getJoglMouseListener();
  Point pickPoint=null;
  EPickingMode ePickingMode=EPickingMode.CLICKED;
  if (pickingTriggerMouseAdapter.wasMouseDoubleClicked()) {
    pickPoint=pickingTriggerMouseAdapter.getPickedPoint();
    ePickingMode=EPickingMode.DOUBLE_CLICKED;
  }
 else   if (pickingTriggerMouseAdapter.wasMouseDragged()) {
    pickPoint=pickingTriggerMouseAdapter.getPickedPoint();
    ePickingMode=EPickingMode.DRAGGED;
  }
 else   if (pickingTriggerMouseAdapter.wasLeftMouseButtonPressed()) {
    pickPoint=pickingTriggerMouseAdapter.getPickedPoint();
    ePickingMode=EPickingMode.CLICKED;
  }
 else   if (pickingTriggerMouseAdapter.wasRightMouseButtonPressed()) {
    pickPoint=pickingTriggerMouseAdapter.getPickedPoint();
    ePickingMode=EPickingMode.RIGHT_CLICKED;
  }
 else   if (pickingTriggerMouseAdapter.wasMouseMoved()) {
    hashViewIDToIsMouseOverPickingEvent.put(canvasUser.getID(),true);
  }
 else   if (hashViewIDToIsMouseOverPickingEvent.get(canvasUser.getID()) != null && hashViewIDToIsMouseOverPickingEvent.get(canvasUser.getID()) == true) {
    pickPoint=pickingTriggerMouseAdapter.getPickedPoint();
    ePickingMode=EPickingMode.MOUSE_OVER;
  }
  if (pickPoint == null)   return;
  hashViewIDToIsMouseOverPickingEvent.put(canvasUser.getID(),false);
  int PICKING_BUFSIZE=1024;
  int iArPickingBuffer[]=new int[PICKING_BUFSIZE];
  IntBuffer pickingBuffer=BufferUtil.newIntBuffer(PICKING_BUFSIZE);
  int iHitCount=-1;
  int viewport[]=new int[4];
  gl.glGetIntegerv(GL.GL_VIEWPORT,viewport,0);
  gl.glSelectBuffer(PICKING_BUFSIZE,pickingBuffer);
  gl.glRenderMode(GL.GL_SELECT);
  gl.glInitNames();
  gl.glMatrixMode(GL.GL_PROJECTION);
  gl.glPushMatrix();
  gl.glLoadIdentity();
  GLU glu=new GLU();
  glu.gluPickMatrix(pickPoint.x,(viewport[3] - pickPoint.y),5.0,5.0,viewport,0);
  float fAspectRatio=(float)(viewport[3] - viewport[1]) / (float)(viewport[2] - viewport[0]);
  IViewFrustum viewFrustum=canvasUser.getViewFrustum();
  viewFrustum.setProjectionMatrix(gl,fAspectRatio);
  Point tmpPickPoint=(Point)pickPoint.clone();
  pickPoint=null;
  canvasUser.display(gl);
  gl.glMatrixMode(GL.GL_PROJECTION);
  gl.glPopMatrix();
  gl.glMatrixMode(GL.GL_MODELVIEW);
  iHitCount=gl.glRenderMode(GL.GL_RENDER);
  pickingBuffer.get(iArPickingBuffer);
  ArrayList<Integer> iAlPickedObjectId=processHits(iHitCount,iArPickingBuffer);
  if (iAlPickedObjectId.size() > 0) {
    processPicks(iAlPickedObjectId,ePickingMode,tmpPickPoint,pickingTriggerMouseAdapter.getPickedPointDragStart());
  }
}

Fixed version (ground truth):
/** 
 * This method has to be called in every display step. It is responsible for the ray tracing which does the actual picking. It needs the ID of the calling view and a gl context. It calls the display() method of the calling view, therefore only elements rendered in the display() can be picked.
 * @param glView a reference to the calling view
 * @param gl the GL context
 */
public void handlePicking(final AGLEventListener glView,final GL gl){
  if (bEnablePicking == false)   return;
  PickingMouseListener pickingTriggerMouseAdapter=glView.getParentGLCanvas().getJoglMouseListener();
  Point pickPoint=null;
  EPickingMode ePickingMode=EPickingMode.CLICKED;
  if (pickingTriggerMouseAdapter.wasMouseDoubleClicked()) {
    pickPoint=pickingTriggerMouseAdapter.getPickedPoint();
    ePickingMode=EPickingMode.DOUBLE_CLICKED;
    ContextMenu.get().flush();
  }
 else   if (pickingTriggerMouseAdapter.wasMouseDragged()) {
    pickPoint=pickingTriggerMouseAdapter.getPickedPoint();
    ePickingMode=EPickingMode.DRAGGED;
    ContextMenu.get().flush();
  }
 else   if (pickingTriggerMouseAdapter.wasLeftMouseButtonPressed()) {
    pickPoint=pickingTriggerMouseAdapter.getPickedPoint();
    ePickingMode=EPickingMode.CLICKED;
    ContextMenu.get().flush();
  }
 else   if (pickingTriggerMouseAdapter.wasRightMouseButtonPressed()) {
    pickPoint=pickingTriggerMouseAdapter.getPickedPoint();
    ePickingMode=EPickingMode.RIGHT_CLICKED;
  }
 else   if (pickingTriggerMouseAdapter.wasMouseMoved()) {
    hashViewIDToIsMouseOverPickingEvent.put(glView.getID(),true);
  }
 else   if (hashViewIDToIsMouseOverPickingEvent.get(glView.getID()) != null && hashViewIDToIsMouseOverPickingEvent.get(glView.getID()) == true) {
    pickPoint=pickingTriggerMouseAdapter.getPickedPoint();
    ePickingMode=EPickingMode.MOUSE_OVER;
  }
  if (pickPoint == null)   return;
  hashViewIDToIsMouseOverPickingEvent.put(glView.getID(),false);
  int PICKING_BUFSIZE=1024;
  int iArPickingBuffer[]=new int[PICKING_BUFSIZE];
  IntBuffer pickingBuffer=BufferUtil.newIntBuffer(PICKING_BUFSIZE);
  int iHitCount=-1;
  int viewport[]=new int[4];
  gl.glGetIntegerv(GL.GL_VIEWPORT,viewport,0);
  gl.glSelectBuffer(PICKING_BUFSIZE,pickingBuffer);
  gl.glRenderMode(GL.GL_SELECT);
  gl.glInitNames();
  gl.glMatrixMode(GL.GL_PROJECTION);
  gl.glPushMatrix();
  gl.glLoadIdentity();
  GLU glu=new GLU();
  glu.gluPickMatrix(pickPoint.x,(viewport[3] - pickPoint.y),5.0,5.0,viewport,0);
  float fAspectRatio=(float)(viewport[3] - viewport[1]) / (float)(viewport[2] - viewport[0]);
  IViewFrustum viewFrustum=glView.getViewFrustum();
  viewFrustum.setProjectionMatrix(gl,fAspectRatio);
  Point tmpPickPoint=(Point)pickPoint.clone();
  pickPoint=null;
  glView.display(gl);
  gl.glMatrixMode(GL.GL_PROJECTION);
  gl.glPopMatrix();
  gl.glMatrixMode(GL.GL_MODELVIEW);
  iHitCount=gl.glRenderMode(GL.GL_RENDER);
  pickingBuffer.get(iArPickingBuffer);
  ArrayList<Integer> iAlPickedObjectId=processHits(iHitCount,iArPickingBuffer);
  if (iAlPickedObjectId.size() > 0) {
    processPicks(iAlPickedObjectId,ePickingMode,tmpPickPoint,pickingTriggerMouseAdapter.getPickedPointDragStart());
  }
}