Program: 57988
Project: 57988
Buggy source:
/** 
 * This method shall be called before the view is rendered in order to be zoomed.
 * @param gl
 */
public void beginZoom(GL2 gl){
  if (currentZoomScale == 1.0f) {
    relativeViewTranlateX=0;
    relativeViewTranlateY=0;
    return;
  }
  float viewTranslateX=relativeViewTranlateX * viewFrustum.getWidth();
  float viewTranslateY=relativeViewTranlateY * viewFrustum.getHeight();
  if (wasMouseWheeled) {
    PixelGLConverter pixelGLConverter=parentGLCanvas.getPixelGLConverter();
    float viewPositionX=pixelGLConverter.getGLWidthForCurrentGLTransform(gl);
    float viewPositionY=pixelGLConverter.getGLHeightForCurrentGLTransform(gl);
    float wheelPositionX=pixelGLConverter.getGLWidthForPixelWidth(mouseWheelPosition.x);
    float wheelPositionY=pixelGLConverter.getGLHeightForPixelHeight(parentGLCanvas.getHeight() - mouseWheelPosition.y);
    float zoomCenterMouseX=wheelPositionX - viewPositionX;
    float zoomCenterMouseY=wheelPositionY - viewPositionY;
    float relativeImageCenterX=(-viewTranslateX + zoomCenterMouseX) / (viewFrustum.getWidth() * previousZoomScale);
    float relativeImageCenterY=(-viewTranslateY + zoomCenterMouseY) / (viewFrustum.getHeight() * previousZoomScale);
    float zoomCenterX=relativeImageCenterX * viewFrustum.getWidth();
    float zoomCenterY=relativeImageCenterY * viewFrustum.getHeight();
    viewTranslateX=(viewFrustum.getWidth() / 2.0f) - zoomCenterX - (currentZoomScale - 1) * zoomCenterX;
    viewTranslateY=(viewFrustum.getHeight() / 2.0f) - zoomCenterY - (currentZoomScale - 1) * zoomCenterY;
    if (viewTranslateX > 0)     viewTranslateX=0;
    if (viewTranslateY > 0)     viewTranslateY=0;
    if (viewTranslateX < -(viewFrustum.getWidth() * (currentZoomScale - 1)))     viewTranslateX=-(viewFrustum.getWidth() * (currentZoomScale - 1));
    if (viewTranslateY < -(viewFrustum.getHeight() * (currentZoomScale - 1)))     viewTranslateY=-(viewFrustum.getHeight() * (currentZoomScale - 1));
    relativeImageCenterX=(-viewTranslateX + viewFrustum.getWidth() / 2.0f) / (viewFrustum.getWidth() * currentZoomScale);
    relativeImageCenterY=(-viewTranslateY + viewFrustum.getHeight() / 2.0f) / (viewFrustum.getHeight() * currentZoomScale);
    zoomCenterX=relativeImageCenterX * viewFrustum.getWidth();
    zoomCenterY=relativeImageCenterY * viewFrustum.getHeight();
    hScrollBar.setPageSize(pixelGLConverter.getPixelWidthForGLWidth((viewFrustum.getWidth() - viewFrustum.getWidth() / currentZoomScale) / currentZoomScale));
    hScrollBar.setMaxValue(pixelGLConverter.getPixelWidthForGLWidth(viewFrustum.getWidth() - viewFrustum.getWidth() / (currentZoomScale * 2.0f)));
    hScrollBar.setMinValue(pixelGLConverter.getPixelWidthForGLWidth(viewFrustum.getWidth() / (currentZoomScale * 2.0f)));
    hScrollBar.setSelection(pixelGLConverter.getPixelWidthForGLWidth(zoomCenterX));
    vScrollBar.setPageSize(pixelGLConverter.getPixelWidthForGLWidth((viewFrustum.getHeight() - viewFrustum.getHeight() / currentZoomScale) / currentZoomScale));
    vScrollBar.setMaxValue(pixelGLConverter.getPixelWidthForGLWidth(viewFrustum.getHeight() - viewFrustum.getHeight() / (currentZoomScale * 2.0f)));
    vScrollBar.setMinValue(pixelGLConverter.getPixelWidthForGLWidth(viewFrustum.getHeight() / (currentZoomScale * 2.0f)));
    vScrollBar.setSelection(pixelGLConverter.getPixelWidthForGLWidth(zoomCenterY));
    relativeViewTranlateX=viewTranslateX / viewFrustum.getWidth();
    relativeViewTranlateY=viewTranslateY / viewFrustum.getHeight();
  }
  gl.glPushMatrix();
  gl.glTranslatef(viewTranslateX,viewTranslateY,0);
  gl.glScalef(currentZoomScale,currentZoomScale,1);
}

Fixed version (ground truth):
/** 
 * This method shall be called before the view is rendered in order to be zoomed.
 * @param gl
 */
public void beginZoom(GL2 gl){
  if (currentZoomScale == 1.0f) {
    relativeViewTranlateX=0;
    relativeViewTranlateY=0;
    return;
  }
  float viewTranslateX=relativeViewTranlateX * viewFrustum.getWidth();
  float viewTranslateY=relativeViewTranlateY * viewFrustum.getHeight();
  PixelGLConverter pixelGLConverter=parentGLCanvas.getPixelGLConverter();
  if (wasMouseWheeled) {
    float viewPositionX=pixelGLConverter.getGLWidthForCurrentGLTransform(gl);
    float viewPositionY=pixelGLConverter.getGLHeightForCurrentGLTransform(gl);
    float wheelPositionX=pixelGLConverter.getGLWidthForPixelWidth(mouseWheelPosition.x);
    float wheelPositionY=pixelGLConverter.getGLHeightForPixelHeight(parentGLCanvas.getHeight() - mouseWheelPosition.y);
    float zoomCenterMouseX=wheelPositionX - viewPositionX;
    float zoomCenterMouseY=wheelPositionY - viewPositionY;
    float relativeImageCenterX=(-viewTranslateX + zoomCenterMouseX) / (viewFrustum.getWidth() * previousZoomScale);
    float relativeImageCenterY=(-viewTranslateY + zoomCenterMouseY) / (viewFrustum.getHeight() * previousZoomScale);
    float zoomCenterX=relativeImageCenterX * viewFrustum.getWidth();
    float zoomCenterY=relativeImageCenterY * viewFrustum.getHeight();
    viewTranslateX=(viewFrustum.getWidth() / 2.0f) - zoomCenterX - (currentZoomScale - 1) * zoomCenterX;
    viewTranslateY=(viewFrustum.getHeight() / 2.0f) - zoomCenterY - (currentZoomScale - 1) * zoomCenterY;
    if (viewTranslateX > 0)     viewTranslateX=0;
    if (viewTranslateY > 0)     viewTranslateY=0;
    if (viewTranslateX < -(viewFrustum.getWidth() * (currentZoomScale - 1)))     viewTranslateX=-(viewFrustum.getWidth() * (currentZoomScale - 1));
    if (viewTranslateY < -(viewFrustum.getHeight() * (currentZoomScale - 1)))     viewTranslateY=-(viewFrustum.getHeight() * (currentZoomScale - 1));
    relativeViewTranlateX=viewTranslateX / viewFrustum.getWidth();
    relativeViewTranlateY=viewTranslateY / viewFrustum.getHeight();
  }
  float relativeImageCenterX=(-viewTranslateX + viewFrustum.getWidth() / 2.0f) / (viewFrustum.getWidth() * currentZoomScale);
  float relativeImageCenterY=(-viewTranslateY + viewFrustum.getHeight() / 2.0f) / (viewFrustum.getHeight() * currentZoomScale);
  float zoomCenterX=relativeImageCenterX * viewFrustum.getWidth();
  float zoomCenterY=relativeImageCenterY * viewFrustum.getHeight();
  hScrollBar.setPageSize(pixelGLConverter.getPixelWidthForGLWidth((viewFrustum.getWidth() - viewFrustum.getWidth() / currentZoomScale) / currentZoomScale));
  hScrollBar.setMaxValue(pixelGLConverter.getPixelWidthForGLWidth(viewFrustum.getWidth() - viewFrustum.getWidth() / (currentZoomScale * 2.0f)));
  hScrollBar.setMinValue(pixelGLConverter.getPixelWidthForGLWidth(viewFrustum.getWidth() / (currentZoomScale * 2.0f)));
  hScrollBar.setSelection(pixelGLConverter.getPixelWidthForGLWidth(zoomCenterX));
  vScrollBar.setPageSize(pixelGLConverter.getPixelWidthForGLWidth((viewFrustum.getHeight() - viewFrustum.getHeight() / currentZoomScale) / currentZoomScale));
  vScrollBar.setMaxValue(pixelGLConverter.getPixelWidthForGLWidth(viewFrustum.getHeight() - viewFrustum.getHeight() / (currentZoomScale * 2.0f)));
  vScrollBar.setMinValue(pixelGLConverter.getPixelWidthForGLWidth(viewFrustum.getHeight() / (currentZoomScale * 2.0f)));
  vScrollBar.setSelection(pixelGLConverter.getPixelWidthForGLWidth(zoomCenterY));
  gl.glPushMatrix();
  gl.glTranslatef(viewTranslateX,viewTranslateY,0);
  gl.glScalef(currentZoomScale,currentZoomScale,1);
}