Program: 17559
Project: 17559
Buggy source:
public void optimizeLayout() throws NullPointerException {
  try {
    if (mDevice.isRecoverySupported() || mDevice.isKernelSupported()) {
      if (getIntent().getAction().equals(Intent.ACTION_VIEW)) {
        setContentView(R.layout.flash_as);
        RelativeLayout FlashAsLayout=(RelativeLayout)findViewById(R.layout.flash_as);
        String path;
        if ((path=getIntent().getData().getPath()) != null) {
          final File IMG=new File(path);
          if (IMG.exists()) {
            TextView tvFlashAs=(TextView)findViewById(R.id.tvFlashAs);
            tvFlashAs.setText(String.format(getString(R.string.flash_as),IMG.getName()));
          }
 else {
            exit();
          }
          RadioButton optAsRecovery=(RadioButton)findViewById(R.id.optAsRecovery);
          RadioButton optAsKernel=(RadioButton)findViewById(R.id.optAsKernel);
          if (!mDevice.isRecoverySupported()) {
            FlashAsLayout.removeView(optAsRecovery);
            optAsKernel.setChecked(true);
          }
          if (!mDevice.isKernelSupported()) {
            FlashAsLayout.removeView((optAsKernel));
          }
        }
 else {
          exit();
        }
      }
 else {
        setContentView(R.layout.recovery_tools);
        mRecoveryToolsLayout=(DrawerLayout)findViewById(R.id.RecoveryToolsLayout);
        LayoutInflater layoutInflater=getLayoutInflater();
        DrawerLayout mMenuDrawer=(DrawerLayout)layoutInflater.inflate(R.layout.menu_drawer,mRecoveryToolsLayout,true);
        DrawerLayout mBackupDrawer=(DrawerLayout)layoutInflater.inflate(R.layout.backup_drawer,mRecoveryToolsLayout,true);
        mRecoveryToolsLayout.setDrawerShadow(R.drawable.drawer_shadow,GravityCompat.START);
        ActionBarDrawerToggle mDrawerToggle=new ActionBarDrawerToggle(mActivity,mRecoveryToolsLayout,R.drawable.ic_drawer,R.string.settings,R.string.app_name);
        mRecoveryToolsLayout.setDrawerListener(mDrawerToggle);
        mDrawerToggle.syncState();
        mDrawerToggle.setDrawerIndicatorEnabled(true);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
        String Styles[]=getResources().getStringArray(R.array.styles);
        if (mMenuDrawer != null) {
          Spinner spStyle=(Spinner)mMenuDrawer.findViewById(R.id.spStyle);
          ArrayAdapter<String> adapter=new ArrayAdapter<String>(mActivity,R.layout.custom_list_item,Styles);
          adapter.setDropDownViewResource(R.layout.custom_list_item);
          spStyle.setAdapter(adapter);
          spStyle.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){
            @Override public void onItemSelected(            AdapterView<?> parent,            View view,            int position,            long id){
switch (position) {
case 1:
                Common.setIntegerPref(mContext,PREF_NAME,PREF_STYLE,APPCOMPAT_LIGHT_DARK_BAR);
              restartActivity();
            break;
case 2:
          Common.setIntegerPref(mContext,PREF_NAME,PREF_STYLE,APPCOMPAT_LIGHT);
        restartActivity();
      break;
case 3:
    Common.setIntegerPref(mContext,PREF_NAME,PREF_STYLE,APPCOMPAT_DARK);
  restartActivity();
break;
}
}
@Override public void onNothingSelected(AdapterView<?> parent){
}
}
);
CheckBox cbShowAds=(CheckBox)mMenuDrawer.findViewById(R.id.cbShowAds);
CheckBox cbLog=(CheckBox)mMenuDrawer.findViewById(R.id.cbLog);
cbShowAds.setChecked(Common.getBooleanPref(mContext,PREF_NAME,PREF_KEY_ADS));
cbLog.setChecked(Common.getBooleanPref(mContext,Shell.PREF_NAME,Shell.PREF_LOG));
if (cbLog.isChecked()) {
findViewById(R.id.bShowLogs).setVisibility(View.VISIBLE);
}
 else {
findViewById(R.id.bShowLogs).setVisibility(View.INVISIBLE);
}
cbShowAds.setChecked(Common.getBooleanPref(mContext,PREF_NAME,PREF_KEY_ADS));
}
final TextView RecoveryVersion=(TextView)findViewById(R.id.tvVersion);
RecoveryVersion.setText(mDevice.getRecoveryVersion() + "String_Node_Str" + mDevice.getKernelVersion());
loadBackupDrawer();
if (!Common.getBooleanPref(mContext,PREF_NAME,PREF_KEY_ADS)) {
mRecoveryToolsLayout.removeView(mRecoveryToolsLayout.findViewById(R.id.adView));
}
if (mDevice.isRecoveryOverRecovery() && mBackupDrawer != null) {
mRecoveryToolsLayout.removeView(mBackupDrawer);
}
if (!mDevice.isKernelSupported()) {
mRecoveryToolsLayout.removeView((mRecoveryToolsLayout.findViewById(R.id.bFlashKernel)));
if (mBackupDrawer != null) {
mBackupDrawer.removeView(mBackupDrawer.findViewById(R.id.bCreateKernelBackup));
mBackupDrawer.removeView(mBackupDrawer.findViewById(R.id.lvKernelBackups));
}
}
if (!mDevice.isRecoverySupported()) {
mRecoveryToolsLayout.removeView(findViewById(R.id.bFlashRecovery));
if (mBackupDrawer != null) {
mBackupDrawer.removeView(findViewById(R.id.bCreateRecoveryBackup));
mBackupDrawer.removeView(findViewById(R.id.lvRecoveryBackups));
}
}
}
}
}
 catch (NullPointerException e) {
throw new NullPointerException("String_Node_Str" + e.getMessage());
}
}

Fixed version (ground truth):
public void optimizeLayout() throws NullPointerException {
  try {
    if (mDevice.isRecoverySupported() || mDevice.isKernelSupported()) {
      if (getIntent().getAction().equals(Intent.ACTION_VIEW)) {
        setContentView(R.layout.flash_as);
        RelativeLayout FlashAsLayout=(RelativeLayout)findViewById(R.layout.flash_as);
        String path;
        if ((path=getIntent().getData().getPath()) != null) {
          final File IMG=new File(path);
          if (IMG.exists()) {
            TextView tvFlashAs=(TextView)findViewById(R.id.tvFlashAs);
            tvFlashAs.setText(String.format(getString(R.string.flash_as),IMG.getName()));
          }
 else {
            exit();
          }
          RadioButton optAsRecovery=(RadioButton)findViewById(R.id.optAsRecovery);
          RadioButton optAsKernel=(RadioButton)findViewById(R.id.optAsKernel);
          if (!mDevice.isRecoverySupported()) {
            FlashAsLayout.removeView(optAsRecovery);
            optAsKernel.setChecked(true);
          }
          if (!mDevice.isKernelSupported()) {
            FlashAsLayout.removeView((optAsKernel));
          }
        }
 else {
          exit();
        }
      }
 else {
        setContentView(R.layout.recovery_tools);
        mRecoveryToolsLayout=(DrawerLayout)findViewById(R.id.RecoveryToolsLayout);
        LayoutInflater layoutInflater=getLayoutInflater();
        DrawerLayout mMenuDrawer=(DrawerLayout)layoutInflater.inflate(R.layout.menu_drawer,mRecoveryToolsLayout,true);
        DrawerLayout mBackupDrawer=(DrawerLayout)layoutInflater.inflate(R.layout.backup_drawer,mRecoveryToolsLayout,true);
        mRecoveryToolsLayout.setDrawerShadow(R.drawable.drawer_shadow,GravityCompat.START);
        ActionBarDrawerToggle mDrawerToggle=new ActionBarDrawerToggle(mActivity,mRecoveryToolsLayout,R.drawable.ic_drawer,R.string.settings,R.string.app_name);
        mRecoveryToolsLayout.setDrawerListener(mDrawerToggle);
        mDrawerToggle.syncState();
        mDrawerToggle.setDrawerIndicatorEnabled(true);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
        String Styles[]=getResources().getStringArray(R.array.styles);
        if (mMenuDrawer != null) {
          Spinner spStyle=(Spinner)mMenuDrawer.findViewById(R.id.spStyle);
          ArrayAdapter<String> adapter=new ArrayAdapter<String>(mActivity,R.layout.custom_list_item,Styles);
          adapter.setDropDownViewResource(R.layout.custom_list_item);
          spStyle.setAdapter(adapter);
          spStyle.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){
            @Override public void onItemSelected(            AdapterView<?> parent,            View view,            int position,            long id){
switch (position) {
case 1:
                Common.setIntegerPref(mContext,PREF_NAME,PREF_STYLE,APPCOMPAT_LIGHT_DARK_BAR);
              restartActivity();
            break;
case 2:
          Common.setIntegerPref(mContext,PREF_NAME,PREF_STYLE,APPCOMPAT_LIGHT);
        restartActivity();
      break;
case 3:
    Common.setIntegerPref(mContext,PREF_NAME,PREF_STYLE,APPCOMPAT_DARK);
  restartActivity();
break;
}
}
@Override public void onNothingSelected(AdapterView<?> parent){
}
}
);
CheckBox cbShowAds=(CheckBox)mMenuDrawer.findViewById(R.id.cbShowAds);
CheckBox cbLog=(CheckBox)mMenuDrawer.findViewById(R.id.cbLog);
cbShowAds.setChecked(Common.getBooleanPref(mContext,PREF_NAME,PREF_KEY_ADS));
cbLog.setChecked(Common.getBooleanPref(mContext,Shell.PREF_NAME,Shell.PREF_LOG));
if (cbLog.isChecked()) {
findViewById(R.id.bShowLogs).setVisibility(View.VISIBLE);
}
 else {
findViewById(R.id.bShowLogs).setVisibility(View.INVISIBLE);
}
cbShowAds.setChecked(Common.getBooleanPref(mContext,PREF_NAME,PREF_KEY_ADS));
}
final TextView RecoveryVersion=(TextView)findViewById(R.id.tvVersion);
RecoveryVersion.setText(mDevice.getRecoveryVersion() + "String_Node_Str" + mDevice.getKernelVersion());
loadBackupDrawer();
AdView adView=(AdView)findViewById(R.id.adView);
ViewGroup MainParent=(ViewGroup)adView.getParent();
if (!Common.getBooleanPref(mContext,PREF_NAME,PREF_KEY_ADS)) {
if (adView != null && MainParent != null) {
MainParent.removeView(adView);
}
}
if (MainParent != null) {
if (!mDevice.isKernelSupported()) {
MainParent.removeView(findViewById(R.id.bFlashKernel));
}
if (!mDevice.isRecoverySupported()) {
MainParent.removeView(findViewById(R.id.bFlashRecovery));
}
}
if (mBackupDrawer != null) {
ViewGroup BackupDrawerParent=(ViewGroup)mBackupDrawer.getParent();
if (mDevice.isRecoveryOverRecovery()) {
BackupDrawerParent.removeView(mBackupDrawer);
}
 else {
View createKernelBackup=findViewById(R.id.bCreateKernelBackup);
View kernelBackups=findViewById(R.id.lvKernelBackups);
View createRecoveryBackup=findViewById(R.id.bCreateRecoveryBackup);
View recoveryBackups=findViewById(R.id.lvRecoveryBackups);
if (!mDevice.isKernelSupported()) {
((ViewGroup)createKernelBackup.getParent()).removeView(createKernelBackup);
((ViewGroup)kernelBackups.getParent()).removeView(kernelBackups);
}
if (!mDevice.isRecoverySupported()) {
((ViewGroup)createRecoveryBackup.getParent()).removeView(createRecoveryBackup);
((ViewGroup)recoveryBackups.getParent()).removeView(recoveryBackups);
}
}
}
}
}
}
 catch (NullPointerException e) {
throw new NullPointerException("String_Node_Str" + e.getMessage());
}
}