Program: 38574
Project: 38574
Buggy source:
@Override public void onCreate(Bundle data,Bundle restoreState){
  super.onCreate(data,restoreState);
  mActionBar=mActivity.getGalleryActionBar();
  mSelectionManager=new SelectionManager(mActivity,false);
  mMenuExecutor=new MenuExecutor(mActivity,mSelectionManager);
  mPhotoView=new PhotoView(mActivity);
  mPhotoView.setListener(this);
  mRootPane.addComponent(mPhotoView);
  mApplication=(GalleryApp)((Activity)mActivity).getApplication();
  mOrientationManager=mActivity.getOrientationManager();
  mOrientationManager.addListener(this);
  mActivity.getGLRoot().setOrientationSource(mOrientationManager);
  mHandler=new SynchronizedHandler(mActivity.getGLRoot()){
    @Override public void handleMessage(    Message message){
switch (message.what) {
case MSG_HIDE_BARS:
{
          hideBars();
          break;
        }
case MSG_REFRESH_BOTTOM_CONTROLS:
{
        if (mBottomControls != null)         mBottomControls.refresh();
        break;
      }
case MSG_LOCK_ORIENTATION:
{
      mOrientationManager.lockOrientation();
      break;
    }
case MSG_UNLOCK_ORIENTATION:
{
    mOrientationManager.unlockOrientation();
    break;
  }
case MSG_ON_FULL_SCREEN_CHANGED:
{
  mAppBridge.onFullScreenChanged(message.arg1 == 1);
  break;
}
case MSG_UPDATE_ACTION_BAR:
{
updateBars();
break;
}
case MSG_WANT_BARS:
{
wantBars();
break;
}
case MSG_UNFREEZE_GLROOT:
{
mActivity.getGLRoot().unfreeze();
break;
}
case MSG_ON_CAMERA_CENTER:
{
mSkipUpdateCurrentPhoto=false;
boolean updateNeeded=false;
if (!mPhotoView.getFilmMode()) {
lockOrientation();
updateNeeded=true;
}
 else if (SystemClock.uptimeMillis() < mCameraSwitchCutoff && mMediaSet.getMediaItemCount() > 1) {
mPhotoView.switchToImage(1);
}
 else {
mPhotoView.setFilmMode(false);
updateNeeded=true;
}
if (updateNeeded) {
updateBars();
updateCurrentPhoto(mModel.getMediaItem(0));
}
break;
}
case MSG_ON_PICTURE_CENTER:
{
if (mCurrentPhoto != null && (mCurrentPhoto.getSupportedOperations() & MediaObject.SUPPORT_ACTION) != 0) {
mPhotoView.setFilmMode(true);
}
break;
}
default :
throw new AssertionError(message.what);
}
}
}
;
mSetPathString=data.getString(KEY_MEDIA_SET_PATH);
mOriginalSetPathString=mSetPathString;
setupNfcBeamPush();
String itemPathString=data.getString(KEY_MEDIA_ITEM_PATH);
Path itemPath=itemPathString != null ? Path.fromString(data.getString(KEY_MEDIA_ITEM_PATH)) : null;
mTreatBackAsUp=data.getBoolean(KEY_TREAT_BACK_AS_UP,false);
mStartInFilmstrip=data.getBoolean(KEY_START_IN_FILMSTRIP,false);
mInCameraRoll=data.getBoolean(KEY_IN_CAMERA_ROLL,false);
mStartedFromAlbumPage=data.getInt(KEY_ALBUMPAGE_TRANSITION,MSG_ALBUMPAGE_NONE) == MSG_ALBUMPAGE_STARTED;
mCurrentIndex=data.getInt(KEY_INDEX_HINT,0);
if (mSetPathString != null) {
mShowSpinner=true;
mAppBridge=(AppBridge)data.getParcelable(KEY_APP_BRIDGE);
if (mAppBridge != null) {
mShowBars=false;
mInCameraRoll=true;
mAppBridge.setServer(this);
mOrientationManager.lockOrientation();
int id=SnailSource.newId();
Path screenNailSetPath=SnailSource.getSetPath(id);
Path screenNailItemPath=SnailSource.getItemPath(id);
mScreenNailSet=(SnailAlbum)mActivity.getDataManager().getMediaObject(screenNailSetPath);
mScreenNailItem=(SnailItem)mActivity.getDataManager().getMediaObject(screenNailItemPath);
mScreenNailItem.setScreenNail(mAppBridge.attachScreenNail());
if (SecureSource.isSecurePath(mSetPathString)) {
mSecureAlbum=(SecureAlbum)mActivity.getDataManager().getMediaSet(mSetPathString);
mShowSpinner=false;
}
if (data.getBoolean(KEY_SHOW_WHEN_LOCKED,false)) {
mFlags|=FLAG_SHOW_WHEN_LOCKED;
}
if (!mSetPathString.equals("String_Node_Str")) {
mSetPathString="String_Node_Str" + mSetPathString + "String_Node_Str";
}
if (LightCycleHelper.hasLightCycleCapture(mActivity.getAndroidContext())) {
mSetPathString=LightCycleHelper.wrapGalleryPath(mSetPathString);
}
mSetPathString="String_Node_Str" + screenNailSetPath + "String_Node_Str"+ mSetPathString+ "String_Node_Str";
itemPath=screenNailItemPath;
}
 else if (mInCameraRoll && GalleryUtils.isCameraAvailable(mActivity)) {
mSetPathString="String_Node_Str" + FilterSource.FILTER_CAMERA_SHORTCUT + "String_Node_Str"+ mSetPathString+ "String_Node_Str";
mCurrentIndex++;
}
MediaSet originalSet=mActivity.getDataManager().getMediaSet(mSetPathString);
if (mInCameraRoll && originalSet instanceof ComboAlbum) {
((ComboAlbum)originalSet).useNameOfChild(1);
}
mSelectionManager.setSourceMediaSet(originalSet);
mSetPathString="String_Node_Str" + mSetPathString + "String_Node_Str";
mMediaSet=(FilterDeleteSet)mActivity.getDataManager().getMediaSet(mSetPathString);
if (mMediaSet == null) {
Log.w(TAG,"String_Node_Str" + mSetPathString);
}
if (itemPath == null) {
int mediaItemCount=mMediaSet.getMediaItemCount();
if (mediaItemCount > 0) {
if (mCurrentIndex >= mediaItemCount) mCurrentIndex=0;
itemPath=mMediaSet.getMediaItem(mCurrentIndex,1).get(0).getPath();
}
 else {
return;
}
}
PhotoDataAdapter pda=new PhotoDataAdapter(mActivity,mPhotoView,mMediaSet,itemPath,mCurrentIndex,mAppBridge == null ? -1 : 0,mAppBridge == null ? false : mAppBridge.isPanorama(),mAppBridge == null ? false : mAppBridge.isStaticCamera());
mModel=pda;
mPhotoView.setModel(mModel);
pda.setDataListener(new PhotoDataAdapter.DataListener(){
@Override public void onPhotoChanged(int index,Path item){
int oldIndex=mCurrentIndex;
mCurrentIndex=index;
if (mAppBridge != null) {
if (mCurrentIndex > 0) {
mSkipUpdateCurrentPhoto=false;
}
if (oldIndex == 0 && mCurrentIndex > 0 && !mPhotoView.getFilmMode()) {
mPhotoView.setFilmMode(true);
}
 else if (oldIndex == 2 && mCurrentIndex == 1) {
mCameraSwitchCutoff=SystemClock.uptimeMillis() + CAMERA_SWITCH_CUTOFF_THRESHOLD_MS;
mPhotoView.stopScrolling();
}
 else if (oldIndex == 1 && mCurrentIndex == 0) {
mPhotoView.setWantPictureCenterCallbacks(true);
mSkipUpdateCurrentPhoto=true;
}
}
if (!mSkipUpdateCurrentPhoto) {
if (item != null) {
MediaItem photo=mModel.getMediaItem(0);
if (photo != null) updateCurrentPhoto(photo);
}
updateBars();
}
refreshHidingMessage();
}
@Override public void onLoadingFinished(){
if (!mModel.isEmpty()) {
MediaItem photo=mModel.getMediaItem(0);
if (photo != null) updateCurrentPhoto(photo);
}
 else if (mIsActive) {
if (mMediaSet.getNumberOfDeletions() == 0) {
mActivity.getStateManager().finishState(PhotoPage.this);
}
}
}
@Override public void onLoadingStarted(){
}
}
);
}
 else {
MediaItem mediaItem=(MediaItem)mActivity.getDataManager().getMediaObject(itemPath);
mModel=new SinglePhotoDataAdapter(mActivity,mPhotoView,mediaItem);
mPhotoView.setModel(mModel);
updateCurrentPhoto(mediaItem);
mShowSpinner=false;
}
mPhotoView.setFilmMode(mStartInFilmstrip && mMediaSet.getMediaItemCount() > 1);
if (mSecureAlbum == null) {
RelativeLayout galleryRoot=(RelativeLayout)((Activity)mActivity).findViewById(mAppBridge != null ? R.id.content : R.id.gallery_root);
if (galleryRoot != null) {
mBottomControls=new PhotoPageBottomControls(this,mActivity,galleryRoot);
}
}
}

Fixed version (ground truth):
@Override public void onCreate(Bundle data,Bundle restoreState){
  super.onCreate(data,restoreState);
  mActionBar=mActivity.getGalleryActionBar();
  mSelectionManager=new SelectionManager(mActivity,false);
  mMenuExecutor=new MenuExecutor(mActivity,mSelectionManager);
  mPhotoView=new PhotoView(mActivity);
  mPhotoView.setListener(this);
  mRootPane.addComponent(mPhotoView);
  mApplication=(GalleryApp)((Activity)mActivity).getApplication();
  mOrientationManager=mActivity.getOrientationManager();
  mOrientationManager.addListener(this);
  mActivity.getGLRoot().setOrientationSource(mOrientationManager);
  mHandler=new SynchronizedHandler(mActivity.getGLRoot()){
    @Override public void handleMessage(    Message message){
switch (message.what) {
case MSG_HIDE_BARS:
{
          hideBars();
          break;
        }
case MSG_REFRESH_BOTTOM_CONTROLS:
{
        if (mBottomControls != null)         mBottomControls.refresh();
        break;
      }
case MSG_LOCK_ORIENTATION:
{
      mOrientationManager.lockOrientation();
      break;
    }
case MSG_UNLOCK_ORIENTATION:
{
    mOrientationManager.unlockOrientation();
    break;
  }
case MSG_ON_FULL_SCREEN_CHANGED:
{
  mAppBridge.onFullScreenChanged(message.arg1 == 1);
  break;
}
case MSG_UPDATE_ACTION_BAR:
{
updateBars();
break;
}
case MSG_WANT_BARS:
{
wantBars();
break;
}
case MSG_UNFREEZE_GLROOT:
{
mActivity.getGLRoot().unfreeze();
break;
}
case MSG_ON_CAMERA_CENTER:
{
mSkipUpdateCurrentPhoto=false;
boolean stayedOnCamera=false;
if (!mPhotoView.getFilmMode()) {
stayedOnCamera=true;
}
 else if (SystemClock.uptimeMillis() < mCameraSwitchCutoff && mMediaSet.getMediaItemCount() > 1) {
mPhotoView.switchToImage(1);
}
 else {
mPhotoView.setFilmMode(false);
stayedOnCamera=true;
}
if (stayedOnCamera) {
lockOrientation();
updateBars();
updateCurrentPhoto(mModel.getMediaItem(0));
}
break;
}
case MSG_ON_PICTURE_CENTER:
{
if (mCurrentPhoto != null && (mCurrentPhoto.getSupportedOperations() & MediaObject.SUPPORT_ACTION) != 0) {
mPhotoView.setFilmMode(true);
}
break;
}
default :
throw new AssertionError(message.what);
}
}
}
;
mSetPathString=data.getString(KEY_MEDIA_SET_PATH);
mOriginalSetPathString=mSetPathString;
setupNfcBeamPush();
String itemPathString=data.getString(KEY_MEDIA_ITEM_PATH);
Path itemPath=itemPathString != null ? Path.fromString(data.getString(KEY_MEDIA_ITEM_PATH)) : null;
mTreatBackAsUp=data.getBoolean(KEY_TREAT_BACK_AS_UP,false);
mStartInFilmstrip=data.getBoolean(KEY_START_IN_FILMSTRIP,false);
mInCameraRoll=data.getBoolean(KEY_IN_CAMERA_ROLL,false);
mStartedFromAlbumPage=data.getInt(KEY_ALBUMPAGE_TRANSITION,MSG_ALBUMPAGE_NONE) == MSG_ALBUMPAGE_STARTED;
mCurrentIndex=data.getInt(KEY_INDEX_HINT,0);
if (mSetPathString != null) {
mShowSpinner=true;
mAppBridge=(AppBridge)data.getParcelable(KEY_APP_BRIDGE);
if (mAppBridge != null) {
mShowBars=false;
mInCameraRoll=true;
mAppBridge.setServer(this);
mOrientationManager.lockOrientation();
int id=SnailSource.newId();
Path screenNailSetPath=SnailSource.getSetPath(id);
Path screenNailItemPath=SnailSource.getItemPath(id);
mScreenNailSet=(SnailAlbum)mActivity.getDataManager().getMediaObject(screenNailSetPath);
mScreenNailItem=(SnailItem)mActivity.getDataManager().getMediaObject(screenNailItemPath);
mScreenNailItem.setScreenNail(mAppBridge.attachScreenNail());
if (SecureSource.isSecurePath(mSetPathString)) {
mSecureAlbum=(SecureAlbum)mActivity.getDataManager().getMediaSet(mSetPathString);
mShowSpinner=false;
}
if (data.getBoolean(KEY_SHOW_WHEN_LOCKED,false)) {
mFlags|=FLAG_SHOW_WHEN_LOCKED;
}
if (!mSetPathString.equals("String_Node_Str")) {
mSetPathString="String_Node_Str" + mSetPathString + "String_Node_Str";
}
if (LightCycleHelper.hasLightCycleCapture(mActivity.getAndroidContext())) {
mSetPathString=LightCycleHelper.wrapGalleryPath(mSetPathString);
}
mSetPathString="String_Node_Str" + screenNailSetPath + "String_Node_Str"+ mSetPathString+ "String_Node_Str";
itemPath=screenNailItemPath;
}
 else if (mInCameraRoll && GalleryUtils.isCameraAvailable(mActivity)) {
mSetPathString="String_Node_Str" + FilterSource.FILTER_CAMERA_SHORTCUT + "String_Node_Str"+ mSetPathString+ "String_Node_Str";
mCurrentIndex++;
}
MediaSet originalSet=mActivity.getDataManager().getMediaSet(mSetPathString);
if (mInCameraRoll && originalSet instanceof ComboAlbum) {
((ComboAlbum)originalSet).useNameOfChild(1);
}
mSelectionManager.setSourceMediaSet(originalSet);
mSetPathString="String_Node_Str" + mSetPathString + "String_Node_Str";
mMediaSet=(FilterDeleteSet)mActivity.getDataManager().getMediaSet(mSetPathString);
if (mMediaSet == null) {
Log.w(TAG,"String_Node_Str" + mSetPathString);
}
if (itemPath == null) {
int mediaItemCount=mMediaSet.getMediaItemCount();
if (mediaItemCount > 0) {
if (mCurrentIndex >= mediaItemCount) mCurrentIndex=0;
itemPath=mMediaSet.getMediaItem(mCurrentIndex,1).get(0).getPath();
}
 else {
return;
}
}
PhotoDataAdapter pda=new PhotoDataAdapter(mActivity,mPhotoView,mMediaSet,itemPath,mCurrentIndex,mAppBridge == null ? -1 : 0,mAppBridge == null ? false : mAppBridge.isPanorama(),mAppBridge == null ? false : mAppBridge.isStaticCamera());
mModel=pda;
mPhotoView.setModel(mModel);
pda.setDataListener(new PhotoDataAdapter.DataListener(){
@Override public void onPhotoChanged(int index,Path item){
int oldIndex=mCurrentIndex;
mCurrentIndex=index;
if (mAppBridge != null) {
if (mCurrentIndex > 0) {
mSkipUpdateCurrentPhoto=false;
}
if (oldIndex == 0 && mCurrentIndex > 0 && !mPhotoView.getFilmMode()) {
mPhotoView.setFilmMode(true);
}
 else if (oldIndex == 2 && mCurrentIndex == 1) {
mCameraSwitchCutoff=SystemClock.uptimeMillis() + CAMERA_SWITCH_CUTOFF_THRESHOLD_MS;
mPhotoView.stopScrolling();
}
 else if (oldIndex >= 1 && mCurrentIndex == 0) {
mPhotoView.setWantPictureCenterCallbacks(true);
mSkipUpdateCurrentPhoto=true;
}
}
if (!mSkipUpdateCurrentPhoto) {
if (item != null) {
MediaItem photo=mModel.getMediaItem(0);
if (photo != null) updateCurrentPhoto(photo);
}
updateBars();
}
refreshHidingMessage();
}
@Override public void onLoadingFinished(){
if (!mModel.isEmpty()) {
MediaItem photo=mModel.getMediaItem(0);
if (photo != null) updateCurrentPhoto(photo);
}
 else if (mIsActive) {
if (mMediaSet.getNumberOfDeletions() == 0) {
mActivity.getStateManager().finishState(PhotoPage.this);
}
}
}
@Override public void onLoadingStarted(){
}
}
);
}
 else {
MediaItem mediaItem=(MediaItem)mActivity.getDataManager().getMediaObject(itemPath);
mModel=new SinglePhotoDataAdapter(mActivity,mPhotoView,mediaItem);
mPhotoView.setModel(mModel);
updateCurrentPhoto(mediaItem);
mShowSpinner=false;
}
mPhotoView.setFilmMode(mStartInFilmstrip && mMediaSet.getMediaItemCount() > 1);
if (mSecureAlbum == null) {
RelativeLayout galleryRoot=(RelativeLayout)((Activity)mActivity).findViewById(mAppBridge != null ? R.id.content : R.id.gallery_root);
if (galleryRoot != null) {
mBottomControls=new PhotoPageBottomControls(this,mActivity,galleryRoot);
}
}
}