Program: 59131
Project: 59131
Buggy source:
public void handlePicking(AUniqueManagedObject uniqueManagedObject,GL gl,PickingJoglMouseListener pickingTriggerMouseAdapter,boolean bIsMaster){
  int iViewID=uniqueManagedObject.getId();
  Point pickPoint=null;
  boolean bMouseReleased=pickingTriggerMouseAdapter.wasMouseReleased();
  EPickingMode ePickingMode=EPickingMode.CLICKED;
  if (pickingTriggerMouseAdapter.wasMousePressed() || bMouseReleased) {
    pickPoint=pickingTriggerMouseAdapter.getPickedPoint();
    ePickingMode=EPickingMode.CLICKED;
  }
 else   if (pickingTriggerMouseAdapter.wasMouseDragged()) {
    pickPoint=pickingTriggerMouseAdapter.getPickedPoint();
    ePickingMode=EPickingMode.DRAGGED;
  }
 else   if (pickingTriggerMouseAdapter.wasMouseMoved()) {
    hashViewIDToLastMouseMovedTimeStamp.put(iViewID,System.nanoTime());
    hashViewIDToIsMouseOverPickingEvent.put(iViewID,true);
  }
 else   if (hashViewIDToIsMouseOverPickingEvent.get(iViewID) != null && hashViewIDToLastMouseMovedTimeStamp.get(iViewID) != null && hashViewIDToIsMouseOverPickingEvent.get(iViewID) == true && System.nanoTime() - hashViewIDToLastMouseMovedTimeStamp.get(iViewID) >= 0) {
    pickPoint=pickingTriggerMouseAdapter.getPickedPoint();
    hashViewIDToLastMouseMovedTimeStamp.put(iViewID,System.nanoTime());
    ePickingMode=EPickingMode.MOUSE_OVER;
  }
  if (pickPoint == null) {
    return;
  }
  hashViewIDToIsMouseOverPickingEvent.put(iViewID,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((double)pickPoint.x,(double)(viewport[3] - pickPoint.y),5.0,5.0,viewport,0);
  float fAspectRatio=(float)(float)(viewport[3] - viewport[1]) / (float)(viewport[2] - viewport[0]);
  IViewFrustum viewFrustum=((AGLCanvasUser)uniqueManagedObject).getViewFrustum();
  if (fAspectRatio < 1.0) {
    fAspectRatio=1.0f / fAspectRatio;
    if (viewFrustum.getProjectionMode().equals(ProjectionMode.ORTHOGRAPHIC)) {
      gl.glOrtho(viewFrustum.getLeft() * fAspectRatio,viewFrustum.getRight() * fAspectRatio,viewFrustum.getBottom(),viewFrustum.getTop(),viewFrustum.getNear(),viewFrustum.getFar());
    }
 else {
      gl.glFrustum(viewFrustum.getLeft() * fAspectRatio,viewFrustum.getRight() * fAspectRatio,viewFrustum.getBottom(),viewFrustum.getTop(),viewFrustum.getNear(),viewFrustum.getFar());
    }
  }
 else {
    if (viewFrustum.getProjectionMode().equals(ProjectionMode.ORTHOGRAPHIC)) {
      gl.glOrtho(viewFrustum.getLeft(),viewFrustum.getRight(),viewFrustum.getBottom() * fAspectRatio,viewFrustum.getTop() * fAspectRatio,viewFrustum.getNear(),viewFrustum.getFar());
    }
 else {
      gl.glFrustum(viewFrustum.getLeft(),viewFrustum.getRight(),viewFrustum.getBottom() * fAspectRatio,viewFrustum.getTop() * fAspectRatio,viewFrustum.getNear(),viewFrustum.getFar());
    }
  }
  gl.glMatrixMode(GL.GL_MODELVIEW);
  Point tmpPickPoint=(Point)pickPoint.clone();
  pickPoint=null;
  ((AGLCanvasUser)uniqueManagedObject).displayLocal(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,uniqueManagedObject,ePickingMode,bIsMaster,tmpPickPoint,pickingTriggerMouseAdapter.getPickedPointDragStart());
  }
}

Fixed version (ground truth):
/** 
 * TODO: Documentation
 * @param uniqueManagedObject
 * @param gl
 * @param pickingTriggerMouseAdapter
 * @param bIsMaster
 */
public void handlePicking(AUniqueManagedObject uniqueManagedObject,GL gl,PickingJoglMouseListener pickingTriggerMouseAdapter,boolean bIsMaster){
  int iViewID=uniqueManagedObject.getId();
  Point pickPoint=null;
  boolean bMouseReleased=pickingTriggerMouseAdapter.wasMouseReleased();
  EPickingMode ePickingMode=EPickingMode.CLICKED;
  if (pickingTriggerMouseAdapter.wasMousePressed() || bMouseReleased) {
    pickPoint=pickingTriggerMouseAdapter.getPickedPoint();
    ePickingMode=EPickingMode.CLICKED;
  }
 else   if (pickingTriggerMouseAdapter.wasMouseDragged()) {
    pickPoint=pickingTriggerMouseAdapter.getPickedPoint();
    ePickingMode=EPickingMode.DRAGGED;
  }
 else   if (pickingTriggerMouseAdapter.wasMouseMoved()) {
    hashViewIDToLastMouseMovedTimeStamp.put(iViewID,System.nanoTime());
    hashViewIDToIsMouseOverPickingEvent.put(iViewID,true);
  }
 else   if (hashViewIDToIsMouseOverPickingEvent.get(iViewID) != null && hashViewIDToLastMouseMovedTimeStamp.get(iViewID) != null && hashViewIDToIsMouseOverPickingEvent.get(iViewID) == true && System.nanoTime() - hashViewIDToLastMouseMovedTimeStamp.get(iViewID) >= 0) {
    pickPoint=pickingTriggerMouseAdapter.getPickedPoint();
    hashViewIDToLastMouseMovedTimeStamp.put(iViewID,System.nanoTime());
    ePickingMode=EPickingMode.MOUSE_OVER;
  }
  if (pickPoint == null) {
    return;
  }
  hashViewIDToIsMouseOverPickingEvent.put(iViewID,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((double)pickPoint.x,(double)(viewport[3] - pickPoint.y),5.0,5.0,viewport,0);
  float fAspectRatio=(float)(float)(viewport[3] - viewport[1]) / (float)(viewport[2] - viewport[0]);
  IViewFrustum viewFrustum=((AGLCanvasUser)uniqueManagedObject).getViewFrustum();
  if (fAspectRatio < 1.0) {
    fAspectRatio=1.0f / fAspectRatio;
    if (viewFrustum.getProjectionMode().equals(ProjectionMode.ORTHOGRAPHIC)) {
      gl.glOrtho(viewFrustum.getLeft() * fAspectRatio,viewFrustum.getRight() * fAspectRatio,viewFrustum.getBottom(),viewFrustum.getTop(),viewFrustum.getNear(),viewFrustum.getFar());
    }
 else {
      gl.glFrustum(viewFrustum.getLeft() * fAspectRatio,viewFrustum.getRight() * fAspectRatio,viewFrustum.getBottom(),viewFrustum.getTop(),viewFrustum.getNear(),viewFrustum.getFar());
    }
  }
 else {
    if (viewFrustum.getProjectionMode().equals(ProjectionMode.ORTHOGRAPHIC)) {
      gl.glOrtho(viewFrustum.getLeft(),viewFrustum.getRight(),viewFrustum.getBottom() * fAspectRatio,viewFrustum.getTop() * fAspectRatio,viewFrustum.getNear(),viewFrustum.getFar());
    }
 else {
      gl.glFrustum(viewFrustum.getLeft(),viewFrustum.getRight(),viewFrustum.getBottom() * fAspectRatio,viewFrustum.getTop() * fAspectRatio,viewFrustum.getNear(),viewFrustum.getFar());
    }
  }
  gl.glMatrixMode(GL.GL_MODELVIEW);
  Point tmpPickPoint=(Point)pickPoint.clone();
  pickPoint=null;
  ((AGLCanvasUser)uniqueManagedObject).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,uniqueManagedObject,ePickingMode,bIsMaster,tmpPickPoint,pickingTriggerMouseAdapter.getPickedPointDragStart());
  }
}