Program: 13657
Project: 13657
Buggy source:
@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  ((WordPress)getApplication()).component().inject(this);
  mDispatcher.register(this);
  setContentView(R.layout.new_edit_post_activity);
  if (savedInstanceState == null) {
    mSite=(SiteModel)getIntent().getSerializableExtra(WordPress.SITE);
  }
 else {
    mSite=(SiteModel)savedInstanceState.getSerializable(WordPress.SITE);
  }
  PreferenceManager.setDefaultValues(this,R.xml.account_settings,false);
  mShowAztecEditor=AppPrefs.isAztecEditorEnabled();
  mShowNewEditor=AppPrefs.isVisualEditorEnabled();
  final ActionBar actionBar=getSupportActionBar();
  if (actionBar != null) {
    actionBar.setDisplayHomeAsUpEnabled(true);
  }
  FragmentManager fragmentManager=getFragmentManager();
  Bundle extras=getIntent().getExtras();
  String action=getIntent().getAction();
  if (savedInstanceState == null) {
    if (!getIntent().hasExtra(EXTRA_POST_LOCAL_ID) || Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)|| NEW_MEDIA_POST.equals(action)|| getIntent().hasExtra(EXTRA_IS_QUICKPRESS)) {
      if (getIntent().hasExtra(EXTRA_QUICKPRESS_BLOG_ID)) {
        int localSiteId=getIntent().getIntExtra(EXTRA_QUICKPRESS_BLOG_ID,-1);
        mSite=mSiteStore.getSiteByLocalId(localSiteId);
      }
      if (extras != null) {
        mIsPage=extras.getBoolean(EXTRA_IS_PAGE);
        mIsPromo=extras.getBoolean(EXTRA_IS_PROMO);
      }
      mIsNewPost=true;
      if (mSite == null) {
        showErrorAndFinish(R.string.blog_not_found);
        return;
      }
      if (!mSite.isVisible()) {
        showErrorAndFinish(R.string.error_blog_hidden);
        return;
      }
      List<Long> categories=new ArrayList<>();
      String postFormat="String_Node_Str";
      if (mSite.isUsingWpComRestApi()) {
        categories.add((long)SiteSettingsInterface.getDefaultCategory(WordPress.getContext()));
        postFormat=SiteSettingsInterface.getDefaultFormat(WordPress.getContext());
      }
      mPost=mPostStore.instantiatePostModel(mSite,mIsPage,categories,postFormat);
      mPost.setStatus(PostStatus.PUBLISHED.toString());
    }
 else     if (extras != null) {
      mPost=mPostStore.getPostByLocalPostId(extras.getInt(EXTRA_POST_LOCAL_ID));
      if (mPost != null) {
        initializePostObject();
      }
    }
  }
 else {
    mDroppedMediaUris=savedInstanceState.getParcelable(STATE_KEY_DROPPED_MEDIA_URIS);
    mIsNewPost=savedInstanceState.getBoolean(STATE_KEY_IS_NEW_POST,false);
    if (savedInstanceState.containsKey(STATE_KEY_POST_REMOTE_ID)) {
      mPost=mPostStore.getPostByRemotePostId(savedInstanceState.getLong(STATE_KEY_POST_REMOTE_ID),mSite);
      initializePostObject();
    }
 else     if (savedInstanceState.containsKey(STATE_KEY_POST_LOCAL_ID)) {
      mPost=mPostStore.getPostByLocalPostId(savedInstanceState.getInt(STATE_KEY_POST_LOCAL_ID));
      initializePostObject();
    }
    mEditorFragment=(EditorFragmentAbstract)fragmentManager.getFragment(savedInstanceState,STATE_KEY_EDITOR_FRAGMENT);
    if (mEditorFragment instanceof EditorMediaUploadListener) {
      mEditorMediaUploadListener=(EditorMediaUploadListener)mEditorFragment;
    }
  }
  if (mSite == null) {
    ToastUtils.showToast(this,R.string.blog_not_found,ToastUtils.Duration.SHORT);
    finish();
    return;
  }
  if (mHasSetPostContent=mEditorFragment != null) {
    mEditorFragment.setImageLoader(mImageLoader);
  }
  if (mPost == null) {
    showErrorAndFinish(R.string.post_not_found);
    return;
  }
  if (mIsNewPost) {
    trackEditorCreatedPost(action,getIntent());
  }
 else {
    UploadService.cancelFinalNotification(this,mPost);
    resetUploadingMediaToFailedIfPostHasNotMediaInProgressOrQueued();
  }
  setTitle(SiteUtils.getSiteNameOrHomeURL(mSite));
  mSectionsPagerAdapter=new SectionsPagerAdapter(fragmentManager);
  mViewPager=(WPViewPager)findViewById(R.id.pager);
  mViewPager.setAdapter(mSectionsPagerAdapter);
  mViewPager.setOffscreenPageLimit(2);
  mViewPager.setPagingEnabled(false);
  mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener(){
    @Override public void onPageSelected(    int position){
      invalidateOptionsMenu();
      if (position == PAGE_CONTENT) {
        setTitle(SiteUtils.getSiteNameOrHomeURL(mSite));
      }
 else       if (position == PAGE_SETTINGS) {
        setTitle(mPost.isPage() ? R.string.page_settings : R.string.post_settings);
        hidePhotoPicker();
      }
 else       if (position == PAGE_PREVIEW) {
        setTitle(mPost.isPage() ? R.string.preview_page : R.string.preview_post);
        hidePhotoPicker();
        savePostAsync(new AfterSavePostListener(){
          @Override public void onPostSave(){
            if (mEditPostPreviewFragment != null) {
              runOnUiThread(new Runnable(){
                @Override public void run(){
                  if (mEditPostPreviewFragment != null) {
                    mEditPostPreviewFragment.loadPost(mPost);
                  }
                }
              }
);
            }
          }
        }
);
      }
    }
  }
);
  ActivityId.trackLastActivity(ActivityId.POST_EDITOR);
}

Fixed version (ground truth):
@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  ((WordPress)getApplication()).component().inject(this);
  mDispatcher.register(this);
  setContentView(R.layout.new_edit_post_activity);
  if (savedInstanceState == null) {
    mSite=(SiteModel)getIntent().getSerializableExtra(WordPress.SITE);
  }
 else {
    mSite=(SiteModel)savedInstanceState.getSerializable(WordPress.SITE);
  }
  PreferenceManager.setDefaultValues(this,R.xml.account_settings,false);
  mShowAztecEditor=AppPrefs.isAztecEditorEnabled();
  mShowNewEditor=AppPrefs.isVisualEditorEnabled();
  if (mShowAztecEditor) {
    View overlay=findViewById(R.id.view_overlay);
    RelativeLayout.LayoutParams layoutParams=(RelativeLayout.LayoutParams)overlay.getLayoutParams();
    layoutParams.bottomMargin=getResources().getDimensionPixelOffset(R.dimen.aztec_format_bar_height);
    overlay.setLayoutParams(layoutParams);
  }
  final ActionBar actionBar=getSupportActionBar();
  if (actionBar != null) {
    actionBar.setDisplayHomeAsUpEnabled(true);
  }
  FragmentManager fragmentManager=getFragmentManager();
  Bundle extras=getIntent().getExtras();
  String action=getIntent().getAction();
  if (savedInstanceState == null) {
    if (!getIntent().hasExtra(EXTRA_POST_LOCAL_ID) || Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)|| NEW_MEDIA_POST.equals(action)|| getIntent().hasExtra(EXTRA_IS_QUICKPRESS)) {
      if (getIntent().hasExtra(EXTRA_QUICKPRESS_BLOG_ID)) {
        int localSiteId=getIntent().getIntExtra(EXTRA_QUICKPRESS_BLOG_ID,-1);
        mSite=mSiteStore.getSiteByLocalId(localSiteId);
      }
      if (extras != null) {
        mIsPage=extras.getBoolean(EXTRA_IS_PAGE);
        mIsPromo=extras.getBoolean(EXTRA_IS_PROMO);
      }
      mIsNewPost=true;
      if (mSite == null) {
        showErrorAndFinish(R.string.blog_not_found);
        return;
      }
      if (!mSite.isVisible()) {
        showErrorAndFinish(R.string.error_blog_hidden);
        return;
      }
      List<Long> categories=new ArrayList<>();
      String postFormat="String_Node_Str";
      if (mSite.isUsingWpComRestApi()) {
        categories.add((long)SiteSettingsInterface.getDefaultCategory(WordPress.getContext()));
        postFormat=SiteSettingsInterface.getDefaultFormat(WordPress.getContext());
      }
      mPost=mPostStore.instantiatePostModel(mSite,mIsPage,categories,postFormat);
      mPost.setStatus(PostStatus.PUBLISHED.toString());
    }
 else     if (extras != null) {
      mPost=mPostStore.getPostByLocalPostId(extras.getInt(EXTRA_POST_LOCAL_ID));
      if (mPost != null) {
        initializePostObject();
      }
    }
  }
 else {
    mDroppedMediaUris=savedInstanceState.getParcelable(STATE_KEY_DROPPED_MEDIA_URIS);
    mIsNewPost=savedInstanceState.getBoolean(STATE_KEY_IS_NEW_POST,false);
    if (savedInstanceState.containsKey(STATE_KEY_POST_REMOTE_ID)) {
      mPost=mPostStore.getPostByRemotePostId(savedInstanceState.getLong(STATE_KEY_POST_REMOTE_ID),mSite);
      initializePostObject();
    }
 else     if (savedInstanceState.containsKey(STATE_KEY_POST_LOCAL_ID)) {
      mPost=mPostStore.getPostByLocalPostId(savedInstanceState.getInt(STATE_KEY_POST_LOCAL_ID));
      initializePostObject();
    }
    mEditorFragment=(EditorFragmentAbstract)fragmentManager.getFragment(savedInstanceState,STATE_KEY_EDITOR_FRAGMENT);
    if (mEditorFragment instanceof EditorMediaUploadListener) {
      mEditorMediaUploadListener=(EditorMediaUploadListener)mEditorFragment;
    }
  }
  if (mSite == null) {
    ToastUtils.showToast(this,R.string.blog_not_found,ToastUtils.Duration.SHORT);
    finish();
    return;
  }
  if (mHasSetPostContent=mEditorFragment != null) {
    mEditorFragment.setImageLoader(mImageLoader);
  }
  if (mPost == null) {
    showErrorAndFinish(R.string.post_not_found);
    return;
  }
  if (mIsNewPost) {
    trackEditorCreatedPost(action,getIntent());
  }
 else {
    UploadService.cancelFinalNotification(this,mPost);
    resetUploadingMediaToFailedIfPostHasNotMediaInProgressOrQueued();
  }
  setTitle(SiteUtils.getSiteNameOrHomeURL(mSite));
  mSectionsPagerAdapter=new SectionsPagerAdapter(fragmentManager);
  mViewPager=(WPViewPager)findViewById(R.id.pager);
  mViewPager.setAdapter(mSectionsPagerAdapter);
  mViewPager.setOffscreenPageLimit(2);
  mViewPager.setPagingEnabled(false);
  mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener(){
    @Override public void onPageSelected(    int position){
      invalidateOptionsMenu();
      if (position == PAGE_CONTENT) {
        setTitle(SiteUtils.getSiteNameOrHomeURL(mSite));
      }
 else       if (position == PAGE_SETTINGS) {
        setTitle(mPost.isPage() ? R.string.page_settings : R.string.post_settings);
        hidePhotoPicker();
      }
 else       if (position == PAGE_PREVIEW) {
        setTitle(mPost.isPage() ? R.string.preview_page : R.string.preview_post);
        hidePhotoPicker();
        savePostAsync(new AfterSavePostListener(){
          @Override public void onPostSave(){
            if (mEditPostPreviewFragment != null) {
              runOnUiThread(new Runnable(){
                @Override public void run(){
                  if (mEditPostPreviewFragment != null) {
                    mEditPostPreviewFragment.loadPost(mPost);
                  }
                }
              }
);
            }
          }
        }
);
      }
    }
  }
);
  ActivityId.trackLastActivity(ActivityId.POST_EDITOR);
}