Program: 424
Project: 424
Buggy source:
/** 
 * Changes held item entity. <p>Detaches old held item and removes it's components. Adds components to new held item and attaches it to the mount point entity.</p>
 */
private void linkHeldItemLocationForLocalPlayer(EntityRef newItem){
  if (!newItem.equals(currentHeldItem)) {
    EntityRef camera=localPlayer.getCameraEntity();
    FirstPersonHeldItemMountPointComponent mountPointComponent=camera.getComponent(FirstPersonHeldItemMountPointComponent.class);
    if (mountPointComponent != null) {
      if (currentHeldItem != EntityRef.NULL) {
        currentHeldItem.destroy();
      }
      EntityRef newHeldItem;
      if (newItem == EntityRef.NULL) {
        newHeldItem=getHandEntity();
      }
 else {
        newHeldItem=newItem;
      }
      currentHeldItem=entityManager.create(newHeldItem.getParentPrefab());
      LightComponent lightComponent=newHeldItem.getComponent(LightComponent.class);
      if (lightComponent != null) {
        currentHeldItem.addOrSaveComponent(lightComponent);
      }
      MeshComponent meshComponent=newHeldItem.getComponent(MeshComponent.class);
      if (meshComponent != null) {
        currentHeldItem.addOrSaveComponent(meshComponent);
      }
      currentHeldItem.removeComponent(NetworkComponent.class);
      currentHeldItem.removeComponent(RigidBodyComponent.class);
      currentHeldItem.addOrSaveComponent(new LocationComponent());
      currentHeldItem.addOrSaveComponent(new ItemIsHeldComponent());
      FirstPersonHeldItemTransformComponent heldItemTransformComponent=currentHeldItem.getComponent(FirstPersonHeldItemTransformComponent.class);
      if (heldItemTransformComponent == null) {
        heldItemTransformComponent=new FirstPersonHeldItemTransformComponent();
        currentHeldItem.addComponent(heldItemTransformComponent);
      }
      Location.attachChild(mountPointComponent.mountPointEntity,currentHeldItem,heldItemTransformComponent.translate,new Quat4f(TeraMath.DEG_TO_RAD * heldItemTransformComponent.rotateDegrees.y,TeraMath.DEG_TO_RAD * heldItemTransformComponent.rotateDegrees.x,TeraMath.DEG_TO_RAD * heldItemTransformComponent.rotateDegrees.z),heldItemTransformComponent.scale);
    }
  }
}

Fixed version (ground truth):
/** 
 * Changes held item entity. <p>Detaches old held item and removes it's components. Adds components to new held item and attaches it to the mount point entity.</p>
 */
private void linkHeldItemLocationForLocalPlayer(EntityRef newItem){
  if (!newItem.equals(currentHeldItem)) {
    EntityRef camera=localPlayer.getCameraEntity();
    FirstPersonHeldItemMountPointComponent mountPointComponent=camera.getComponent(FirstPersonHeldItemMountPointComponent.class);
    if (mountPointComponent != null) {
      if (currentHeldItem != EntityRef.NULL) {
        currentHeldItem.destroy();
      }
      EntityRef newHeldItem;
      if (newItem == EntityRef.NULL) {
        newHeldItem=getHandEntity();
      }
 else {
        newHeldItem=newItem;
      }
      currentHeldItem=entityManager.create();
      for (      Component component : newHeldItem.iterateComponents()) {
        if (component instanceof VisualComponent) {
          currentHeldItem.addComponent(component);
        }
      }
      currentHeldItem.addComponent(new LocationComponent());
      currentHeldItem.addComponent(new ItemIsHeldComponent());
      FirstPersonHeldItemTransformComponent heldItemTransformComponent=currentHeldItem.getComponent(FirstPersonHeldItemTransformComponent.class);
      if (heldItemTransformComponent == null) {
        heldItemTransformComponent=new FirstPersonHeldItemTransformComponent();
        currentHeldItem.addComponent(heldItemTransformComponent);
      }
      Location.attachChild(mountPointComponent.mountPointEntity,currentHeldItem,heldItemTransformComponent.translate,new Quat4f(TeraMath.DEG_TO_RAD * heldItemTransformComponent.rotateDegrees.y,TeraMath.DEG_TO_RAD * heldItemTransformComponent.rotateDegrees.x,TeraMath.DEG_TO_RAD * heldItemTransformComponent.rotateDegrees.z),heldItemTransformComponent.scale);
    }
  }
}