Program: 19941
Project: 19941
Buggy source:
/** 
 * Asettaa TouchListenerit ja k�sittelee kosketustapahtumat.
 */
public final void setSurfaceListeners(){
  surface.setOnTouchListener(new OnTouchListener(){
    public boolean onTouch(    View v,    MotionEvent event){
      action=event.getAction();
      if (event.getPointerCount() > 1) {
        actionCode=action & MotionEvent.ACTION_MASK;
        action=event.getAction();
        for (int i=0; i < event.getPointerCount(); i++) {
          if (i == 0) {
            xFirstTouch=(int)event.getX(i) - screenWidth / 2;
            yFirstTouch=screenHeight / 2 - (int)event.getY(i);
            if (!Joystick.joystickInUse && Joystick.joystickDown && Utility.getDistance((float)xFirstTouch,(float)yFirstTouch,(float)joystickX,(float)joystickY) < JOYSTICK_TRESHOLD) {
              Joystick.joystickInUse=true;
            }
 else             if (Joystick.joystickInUse) {
              Joystick.useJoystick(xFirstTouch,yFirstTouch,(int)event.getX(),(int)event.getY(),wrapper);
              if (Utility.getDistance((float)xFirstTouch,(float)yFirstTouch,(float)joystickX,(float)joystickY) > JOYSTICK_TRESHOLD) {
                Joystick.joystickDown=false;
                Joystick.joystickInUse=false;
                wrapper.player.movementAcceleration=-6;
              }
            }
          }
          if (i == 1) {
            xSecondTouch=(int)event.getX(i) - screenWidth / 2;
            ySecondTouch=screenHeight / 2 - (int)event.getY(i);
            if (weaponManager.currentWeapon == WeaponManager.WEAPON_SPITFIRE && xSecondTouch > (screenWidth / 2) - 100 * Options.scaleX && xSecondTouch < (screenWidth / 2) && ySecondTouch < yFirstButtonBorder) {
              weaponManager.triggerPlayerShoot(xSecondTouch,ySecondTouch);
            }
 else             if (weaponManager.isUsingMotionEvents) {
              if (pointerCount < 10) {
                if (Math.abs(touchPath[pointerCount - 1][0] - xFirstTouch) >= 8 || Math.abs(touchPath[pointerCount - 1][1] - yFirstTouch) >= 8) {
                  setPathPoint(xFirstTouch,yFirstTouch,pointerCount);
                  pointerCount++;
                }
              }
            }
          }
        }
        if (actionCode == MotionEvent.ACTION_POINTER_DOWN) {
          if (xSecondTouch > (screenWidth / 2) - 100 * Options.scaleX && xSecondTouch < (screenWidth / 2) && ySecondTouch < yFirstButtonBorder) {
            if (ySecondTouch < yThirdButtonBorder && ySecondTouch > (-screenHeight / 2)) {
              Log.e("String_Node_Str","String_Node_Str");
              hud.triggerClick(Hud.BUTTON_1);
            }
 else             if (ySecondTouch < ySecondButtonBorder && ySecondTouch > yThirdButtonBorder) {
              Log.e("String_Node_Str","String_Node_Str");
              hud.triggerClick(Hud.BUTTON_2);
            }
          }
 else {
            weaponManager.triggerPlayerShoot(xSecondTouch,ySecondTouch);
          }
        }
        if (actionCode == MotionEvent.ACTION_POINTER_UP) {
          Log.d("String_Node_Str","String_Node_Str");
          if (weaponManager.isUsingMotionEvents) {
            weaponManager.triggerMotionShoot(touchPath);
            for (int i=0; i < 10; i++) {
              touchPath[i][0]=0;
              touchPath[i][1]=0;
            }
            pointerCount=1;
          }
        }
      }
 else {
        xFirstTouch=(int)event.getX() - screenWidth / 2;
        yFirstTouch=screenHeight / 2 - (int)event.getY();
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
          xFirstTouch=(int)event.getX() - screenWidth / 2;
          yFirstTouch=screenHeight / 2 - (int)event.getY();
          if (xFirstTouch > (screenWidth / 2) - 100 * Options.scaleX && xFirstTouch < (screenWidth / 2) && yFirstTouch < yFirstButtonBorder) {
            if (yFirstTouch < yThirdButtonBorder && yFirstTouch > (-screenHeight / 2)) {
              Log.e("String_Node_Str","String_Node_Str");
              hud.triggerClick(Hud.BUTTON_1);
            }
 else             if (yFirstTouch < ySecondButtonBorder && yFirstTouch > yThirdButtonBorder) {
              Log.e("String_Node_Str","String_Node_Str");
              hud.triggerClick(Hud.BUTTON_2);
            }
          }
          if (joystickX != 0 && joystickY != 0 && Utility.getDistance((float)xFirstTouch,(float)yFirstTouch,(float)joystickX,(float)joystickY) < JOYSTICK_TRESHOLD) {
            Joystick.joystickDown=true;
          }
 else {
            if (xFirstTouch < (screenWidth / 2) - 100 * Options.scaleX && yFirstTouch > yFirstButtonBorder) {
              weaponManager.triggerPlayerShoot(event.getX() - screenWidth / 2,-((-screenHeight / 2) + event.getY()));
            }
          }
        }
        if (event.getAction() == MotionEvent.ACTION_MOVE) {
          xFirstTouch=(int)event.getX() - screenWidth / 2;
          yFirstTouch=screenHeight / 2 - (int)event.getY();
          if (joystickX != 0 && joystickY != 0 && Utility.getDistance((float)xFirstTouch,(float)yFirstTouch,(float)joystickX,(float)joystickY) < JOYSTICK_TRESHOLD) {
            Joystick.joystickDown=true;
          }
 else           if (weaponManager.currentWeapon == WeaponManager.WEAPON_SPITFIRE) {
            weaponManager.triggerPlayerShoot(xFirstTouch,yFirstTouch);
          }
          if (weaponManager.isUsingMotionEvents) {
            if (pointerCount < 10) {
              if (Math.abs(touchPath[pointerCount - 1][0] - xFirstTouch) >= 8 || Math.abs(touchPath[pointerCount - 1][1] - yFirstTouch) >= 8) {
                setPathPoint(xFirstTouch,yFirstTouch,pointerCount);
                pointerCount++;
              }
            }
          }
          if (!Joystick.joystickInUse && Joystick.joystickDown && Utility.getDistance((float)xFirstTouch,(float)yFirstTouch,(float)joystickX,(float)joystickY) < JOYSTICK_TRESHOLD) {
            Joystick.joystickInUse=true;
          }
 else           if (Joystick.joystickInUse) {
            Joystick.useJoystick(xFirstTouch,yFirstTouch,(int)event.getX(),(int)event.getY(),wrapper);
            if (Utility.getDistance((float)xFirstTouch,(float)yFirstTouch,(float)joystickX,(float)joystickY) > JOYSTICK_TRESHOLD) {
              Joystick.joystickDown=false;
              Joystick.joystickInUse=false;
              wrapper.player.movementAcceleration=-6;
            }
          }
        }
        if (event.getAction() == MotionEvent.ACTION_UP) {
          Joystick.joystickInUse=false;
          Joystick.joystickDown=false;
          wrapper.player.movementAcceleration=-6;
          if (weaponManager.isUsingMotionEvents) {
            weaponManager.triggerMotionShoot(touchPath);
            for (int i=0; i < 10; i++) {
              touchPath[i][0]=0;
              touchPath[i][1]=0;
            }
            pointerCount=1;
          }
          if (Math.abs(event.getX() - (xFirstTouch - screenWidth / 2)) < touchMarginal && Math.abs(event.getY() - (yFirstTouch - screenHeight / 2)) < touchMarginal) {
          }
        }
      }
      return true;
    }
  }
);
}

Fixed version (ground truth):
/** 
 * Asettaa TouchListenerit ja k�sittelee kosketustapahtumat.
 */
public final void setSurfaceListeners(){
  surface.setOnTouchListener(new OnTouchListener(){
    public boolean onTouch(    View v,    MotionEvent event){
      action=event.getAction();
      if (event.getPointerCount() > 1) {
        actionCode=action & MotionEvent.ACTION_MASK;
        action=event.getAction();
        for (int i=0; i < event.getPointerCount(); i++) {
          if (i == 0) {
            xFirstTouch=(int)event.getX(i) - screenWidth / 2;
            yFirstTouch=screenHeight / 2 - (int)event.getY(i);
            if (!Joystick.joystickInUse && Joystick.joystickDown && Utility.getDistance((float)xFirstTouch,(float)yFirstTouch,(float)joystickX,(float)joystickY) < JOYSTICK_TRESHOLD) {
              Joystick.joystickInUse=true;
            }
 else             if (Joystick.joystickInUse) {
              Joystick.useJoystick(xFirstTouch,yFirstTouch,(int)event.getX(),(int)event.getY(),wrapper);
              if (Utility.getDistance((float)xFirstTouch,(float)yFirstTouch,(float)joystickX,(float)joystickY) > JOYSTICK_TRESHOLD) {
                Joystick.joystickDown=false;
                Joystick.joystickInUse=false;
                wrapper.player.movementAcceleration=-6;
              }
            }
          }
          if (i == 1) {
            xSecondTouch=(int)event.getX(i) - screenWidth / 2;
            ySecondTouch=screenHeight / 2 - (int)event.getY(i);
            if (weaponManager.currentWeapon == WeaponManager.WEAPON_SPITFIRE && xSecondTouch > (screenWidth / 2) - 100 * Options.scaleX && xSecondTouch < (screenWidth / 2) && ySecondTouch < yFirstButtonBorder) {
              weaponManager.triggerPlayerShoot(xSecondTouch,ySecondTouch);
            }
 else             if (weaponManager.isUsingMotionEvents) {
              if (pointerCount < 10) {
                if (Math.abs(touchPath[pointerCount - 1][0] - xFirstTouch) >= 8 || Math.abs(touchPath[pointerCount - 1][1] - yFirstTouch) >= 8) {
                  setPathPoint(xFirstTouch,yFirstTouch,pointerCount);
                  pointerCount++;
                }
              }
            }
          }
        }
        if (actionCode == MotionEvent.ACTION_POINTER_DOWN) {
          if (xSecondTouch > (screenWidth / 2) - 100 * Options.scaleX && xSecondTouch < (screenWidth / 2) && ySecondTouch < yFirstButtonBorder) {
            if (ySecondTouch < yThirdButtonBorder && ySecondTouch > (-screenHeight / 2)) {
              Log.e("String_Node_Str","String_Node_Str");
              hud.triggerClick(Hud.BUTTON_1);
            }
 else             if (ySecondTouch < ySecondButtonBorder && ySecondTouch > yThirdButtonBorder) {
              Log.e("String_Node_Str","String_Node_Str");
              hud.triggerClick(Hud.BUTTON_2);
            }
          }
 else {
            weaponManager.triggerPlayerShoot(xSecondTouch,ySecondTouch);
          }
        }
        if (actionCode == MotionEvent.ACTION_POINTER_UP) {
          Log.d("String_Node_Str","String_Node_Str");
          Joystick.joystickDown=false;
          Joystick.joystickInUse=false;
          if (weaponManager.isUsingMotionEvents) {
            weaponManager.triggerMotionShoot(touchPath);
            for (int i=0; i < 10; i++) {
              touchPath[i][0]=0;
              touchPath[i][1]=0;
            }
            pointerCount=1;
          }
        }
      }
 else {
        xFirstTouch=(int)event.getX() - screenWidth / 2;
        yFirstTouch=screenHeight / 2 - (int)event.getY();
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
          xFirstTouch=(int)event.getX() - screenWidth / 2;
          yFirstTouch=screenHeight / 2 - (int)event.getY();
          if (xFirstTouch > (screenWidth / 2) - 100 * Options.scaleX && xFirstTouch < (screenWidth / 2) && yFirstTouch < yFirstButtonBorder) {
            if (yFirstTouch < yThirdButtonBorder && yFirstTouch > (-screenHeight / 2)) {
              Log.e("String_Node_Str","String_Node_Str");
              hud.triggerClick(Hud.BUTTON_1);
            }
 else             if (yFirstTouch < ySecondButtonBorder && yFirstTouch > yThirdButtonBorder) {
              Log.e("String_Node_Str","String_Node_Str");
              hud.triggerClick(Hud.BUTTON_2);
            }
          }
          if (joystickX != 0 && joystickY != 0 && Utility.getDistance((float)xFirstTouch,(float)yFirstTouch,(float)joystickX,(float)joystickY) < JOYSTICK_TRESHOLD) {
            Joystick.joystickDown=true;
          }
 else {
            if (xFirstTouch < (screenWidth / 2) - 100 * Options.scaleX && yFirstTouch > yFirstButtonBorder || xFirstTouch < (screenWidth / 2) - 100 * Options.scaleX && yFirstTouch < yFirstButtonBorder || xFirstTouch > (screenWidth / 2) - 100 * Options.scaleX && yFirstTouch > yFirstButtonBorder) {
              weaponManager.triggerPlayerShoot(event.getX() - screenWidth / 2,-((-screenHeight / 2) + event.getY()));
            }
          }
        }
        if (event.getAction() == MotionEvent.ACTION_MOVE) {
          xFirstTouch=(int)event.getX() - screenWidth / 2;
          yFirstTouch=screenHeight / 2 - (int)event.getY();
          if (joystickX != 0 && joystickY != 0 && Utility.getDistance((float)xFirstTouch,(float)yFirstTouch,(float)joystickX,(float)joystickY) < JOYSTICK_TRESHOLD) {
            Joystick.joystickDown=true;
          }
 else           if (weaponManager.currentWeapon == WeaponManager.WEAPON_SPITFIRE) {
            weaponManager.triggerPlayerShoot(xFirstTouch,yFirstTouch);
          }
          if (weaponManager.isUsingMotionEvents) {
            if (pointerCount < 10) {
              if (Math.abs(touchPath[pointerCount - 1][0] - xFirstTouch) >= 8 || Math.abs(touchPath[pointerCount - 1][1] - yFirstTouch) >= 8) {
                setPathPoint(xFirstTouch,yFirstTouch,pointerCount);
                pointerCount++;
              }
            }
          }
          if (!Joystick.joystickInUse && Joystick.joystickDown && Utility.getDistance((float)xFirstTouch,(float)yFirstTouch,(float)joystickX,(float)joystickY) < JOYSTICK_TRESHOLD) {
            Joystick.joystickInUse=true;
          }
 else           if (Joystick.joystickInUse) {
            Joystick.useJoystick(xFirstTouch,yFirstTouch,(int)event.getX(),(int)event.getY(),wrapper);
            if (Utility.getDistance((float)xFirstTouch,(float)yFirstTouch,(float)joystickX,(float)joystickY) > JOYSTICK_TRESHOLD) {
              Joystick.joystickDown=false;
              Joystick.joystickInUse=false;
              wrapper.player.movementAcceleration=-6;
            }
          }
        }
        if (event.getAction() == MotionEvent.ACTION_UP) {
          Joystick.joystickInUse=false;
          Joystick.joystickDown=false;
          wrapper.player.movementAcceleration=-6;
          if (weaponManager.isUsingMotionEvents) {
            weaponManager.triggerMotionShoot(touchPath);
            for (int i=0; i < 10; i++) {
              touchPath[i][0]=0;
              touchPath[i][1]=0;
            }
            pointerCount=1;
          }
          if (Math.abs(event.getX() - (xFirstTouch - screenWidth / 2)) < touchMarginal && Math.abs(event.getY() - (yFirstTouch - screenHeight / 2)) < touchMarginal) {
          }
        }
      }
      return true;
    }
  }
);
}