Program: 58112
Project: 58112
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 glView a reference to the calling view
 * @param gl the GL2 context
 */
public void handlePicking(final AGLView glView,final GL2 gl){
  if (bEnablePicking == false)   return;
  GLMouseListener glMouseListener=glView.getParentGLCanvas().getGLMouseListener();
  Point pickPoint=null;
  EPickingMode ePickingMode=EPickingMode.CLICKED;
  if (glMouseListener.wasMouseDoubleClicked()) {
    pickPoint=glMouseListener.getPickedPoint();
    ePickingMode=EPickingMode.DOUBLE_CLICKED;
  }
 else   if (glMouseListener.wasMouseDragged()) {
    pickPoint=glMouseListener.getPickedPoint();
    ePickingMode=EPickingMode.DRAGGED;
  }
 else   if (glMouseListener.wasLeftMouseButtonPressed()) {
    pickPoint=glMouseListener.getPickedPoint();
    ePickingMode=EPickingMode.CLICKED;
  }
 else   if (glMouseListener.wasRightMouseButtonPressed()) {
    pickPoint=glMouseListener.getPickedPoint();
    ePickingMode=EPickingMode.RIGHT_CLICKED;
  }
 else   if (glMouseListener.wasMouseMoved()) {
    hashViewIDToIsMouseOverPickingEvent.put(glView.getID(),true);
  }
 else   if (hashViewIDToIsMouseOverPickingEvent.get(glView.getID()) != null && hashViewIDToIsMouseOverPickingEvent.get(glView.getID()) == true) {
    pickPoint=glMouseListener.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=IntBuffer.allocate(PICKING_BUFSIZE);
  int iHitCount=-1;
  int viewport[]=new int[4];
  gl.glGetIntegerv(GL2.GL_VIEWPORT,viewport,0);
  gl.glSelectBuffer(PICKING_BUFSIZE,pickingBuffer);
  gl.glRenderMode(GL2.GL_SELECT);
  gl.glInitNames();
  gl.glMatrixMode(GL2.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]);
  ViewFrustum viewFrustum=glView.getViewFrustum();
  viewFrustum.setProjectionMatrix(gl,fAspectRatio);
  Point tmpPickPoint=(Point)pickPoint.clone();
  pickPoint=null;
  glView.display(gl);
  gl.glMatrixMode(GL2.GL_PROJECTION);
  gl.glPopMatrix();
  gl.glMatrixMode(GL2.GL_MODELVIEW);
  iHitCount=gl.glRenderMode(GL2.GL_RENDER);
  pickingBuffer.get(iArPickingBuffer);
  ArrayList<Integer> iAlPickedObjectId=processHits(iHitCount,iArPickingBuffer);
  if (iAlPickedObjectId.size() > 0) {
    processPicks(iAlPickedObjectId,ePickingMode,tmpPickPoint,glMouseListener.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 GL2 context
 */
public void handlePicking(final AGLView glView,final GL2 gl){
  if (bEnablePicking == false)   return;
  GLMouseListener glMouseListener=glView.getParentGLCanvas().getGLMouseListener();
  Point pickPoint=null;
  EPickingMode ePickingMode=EPickingMode.CLICKED;
  if (glMouseListener.wasMouseDoubleClicked()) {
    pickPoint=glMouseListener.getPickedPoint();
    ePickingMode=EPickingMode.DOUBLE_CLICKED;
  }
 else   if (glMouseListener.wasMouseDragged()) {
    pickPoint=glMouseListener.getPickedPoint();
    ePickingMode=EPickingMode.DRAGGED;
  }
 else   if (glMouseListener.wasLeftMouseButtonPressed()) {
    pickPoint=glMouseListener.getPickedPoint();
    ePickingMode=EPickingMode.CLICKED;
  }
 else   if (glMouseListener.wasRightMouseButtonPressed()) {
    pickPoint=glMouseListener.getPickedPoint();
    ePickingMode=EPickingMode.RIGHT_CLICKED;
  }
 else   if (glMouseListener.wasMouseMoved()) {
    hashViewIDToIsMouseOverPickingEvent.put(glView.getID(),true);
  }
 else   if (hashViewIDToIsMouseOverPickingEvent.get(glView.getID()) != null && hashViewIDToIsMouseOverPickingEvent.get(glView.getID()) == true) {
    pickPoint=glMouseListener.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=Buffers.newDirectIntBuffer(PICKING_BUFSIZE);
  int iHitCount=-1;
  int viewport[]=new int[4];
  gl.glGetIntegerv(GL2.GL_VIEWPORT,viewport,0);
  gl.glSelectBuffer(PICKING_BUFSIZE,pickingBuffer);
  gl.glRenderMode(GL2.GL_SELECT);
  gl.glInitNames();
  gl.glMatrixMode(GL2.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]);
  ViewFrustum viewFrustum=glView.getViewFrustum();
  viewFrustum.setProjectionMatrix(gl,fAspectRatio);
  Point tmpPickPoint=(Point)pickPoint.clone();
  pickPoint=null;
  glView.display(gl);
  gl.glMatrixMode(GL2.GL_PROJECTION);
  gl.glPopMatrix();
  gl.glMatrixMode(GL2.GL_MODELVIEW);
  iHitCount=gl.glRenderMode(GL2.GL_RENDER);
  pickingBuffer.get(iArPickingBuffer);
  ArrayList<Integer> iAlPickedObjectId=processHits(iHitCount,iArPickingBuffer);
  if (iAlPickedObjectId.size() > 0) {
    processPicks(iAlPickedObjectId,ePickingMode,tmpPickPoint,glMouseListener.getPickedPointDragStart());
  }
}