Program: 1596
Project: 1596
Buggy source:
public boolean updateUi(){
  if (mCurrentUi != UI_EDITING_PRINT_JOB) {
    return false;
  }
  if (isPrintConfirmed() || isPreviewConfirmed() || isCancelled()) {
    mDestinationSpinner.setEnabled(false);
    mCopiesEditText.setEnabled(false);
    mMediaSizeSpinner.setEnabled(false);
    mColorModeSpinner.setEnabled(false);
    mOrientationSpinner.setEnabled(false);
    mRangeOptionsSpinner.setEnabled(false);
    mPageRangeEditText.setEnabled(false);
    mPrintButton.setEnabled(false);
    return false;
  }
  boolean allOptionsEnabled=false;
  final int selectedIndex=mDestinationSpinner.getSelectedItemPosition();
  if (selectedIndex >= 0) {
    Object item=mDestinationSpinnerAdapter.getItem(selectedIndex);
    if (item instanceof PrinterInfo) {
      PrinterInfo printer=(PrinterInfo)item;
      if (printer.getCapabilities() != null) {
        allOptionsEnabled=true;
      }
    }
  }
  if (!allOptionsEnabled) {
    String minCopiesString=String.valueOf(MIN_COPIES);
    if (!TextUtils.equals(mCopiesEditText.getText(),minCopiesString)) {
      mIgnoreNextCopiesChange=true;
      mCopiesEditText.setText(minCopiesString);
    }
    mCopiesEditText.setEnabled(false);
    if (mMediaSizeSpinner.getSelectedItemPosition() != AdapterView.INVALID_POSITION) {
      mIgnoreNextMediaSizeChange=true;
      mMediaSizeSpinner.setSelection(AdapterView.INVALID_POSITION);
    }
    mMediaSizeSpinner.setEnabled(false);
    if (mColorModeSpinner.getSelectedItemPosition() != AdapterView.INVALID_POSITION) {
      mIgnoreNextColorModeChange=true;
      mColorModeSpinner.setSelection(AdapterView.INVALID_POSITION);
    }
    mColorModeSpinner.setEnabled(false);
    if (mOrientationSpinner.getSelectedItemPosition() != AdapterView.INVALID_POSITION) {
      mIgnoreNextOrientationChange=true;
      mOrientationSpinner.setSelection(AdapterView.INVALID_POSITION);
    }
    mOrientationSpinner.setEnabled(false);
    if (mRangeOptionsSpinner.getSelectedItemPosition() != 0) {
      mIgnoreNextRangeOptionChange=true;
      mRangeOptionsSpinner.setSelection(0);
    }
    mRangeOptionsSpinner.setEnabled(false);
    mRangeOptionsTitle.setText(getString(R.string.label_pages,getString(R.string.page_count_unknown)));
    if (!TextUtils.equals(mPageRangeEditText.getText(),"String_Node_Str")) {
      mIgnoreNextRangeChange=true;
      mPageRangeEditText.setText("String_Node_Str");
    }
    mPageRangeEditText.setEnabled(false);
    mPageRangeEditText.setVisibility(View.INVISIBLE);
    mPageRangeTitle.setVisibility(View.INVISIBLE);
    mPrintButton.setEnabled(false);
    return false;
  }
 else {
    boolean someAttributeSelectionChanged=false;
    PrintAttributes defaultAttributes=mTempPrintAttributes;
    PrinterInfo printer=(PrinterInfo)mDestinationSpinner.getSelectedItem();
    PrinterCapabilitiesInfo capabilities=printer.getCapabilities();
    printer.getCapabilities().getDefaults(defaultAttributes);
    List<MediaSize> mediaSizes=capabilities.getMediaSizes();
    boolean mediaSizesChanged=false;
    final int mediaSizeCount=mediaSizes.size();
    if (mediaSizeCount != mMediaSizeSpinnerAdapter.getCount()) {
      mediaSizesChanged=true;
    }
 else {
      for (int i=0; i < mediaSizeCount; i++) {
        if (!mediaSizes.get(i).equals(mMediaSizeSpinnerAdapter.getItem(i).value)) {
          mediaSizesChanged=true;
          break;
        }
      }
    }
    if (mediaSizesChanged) {
      int oldMediaSizeNewIndex=AdapterView.INVALID_POSITION;
      MediaSize oldMediaSize=mCurrPrintAttributes.getMediaSize();
      mMediaSizeSpinnerAdapter.clear();
      for (int i=0; i < mediaSizeCount; i++) {
        MediaSize mediaSize=mediaSizes.get(i);
        if (mediaSize.equals(oldMediaSize)) {
          oldMediaSizeNewIndex=i;
        }
        mMediaSizeSpinnerAdapter.add(new SpinnerItem<MediaSize>(mediaSize,mediaSize.getLabel(getPackageManager())));
      }
      if (mediaSizeCount <= 0) {
        mMediaSizeSpinner.setEnabled(false);
        someAttributeSelectionChanged=setMediaSizeSpinnerSelectionNoCallback(AdapterView.INVALID_POSITION);
      }
 else {
        mMediaSizeSpinner.setEnabled(true);
        if (oldMediaSizeNewIndex != AdapterView.INVALID_POSITION) {
          setMediaSizeSpinnerSelectionNoCallback(oldMediaSizeNewIndex);
        }
 else {
          final int mediaSizeIndex=Math.max(mediaSizes.indexOf(defaultAttributes.getMediaSize()),0);
          someAttributeSelectionChanged=setMediaSizeSpinnerSelectionNoCallback(mediaSizeIndex);
        }
      }
    }
    mMediaSizeSpinner.setEnabled(true);
    final int colorModes=capabilities.getColorModes();
    boolean colorModesChanged=false;
    if (Integer.bitCount(colorModes) != mColorModeSpinnerAdapter.getCount()) {
      colorModesChanged=true;
    }
 else {
      int remainingColorModes=colorModes;
      int adapterIndex=0;
      while (remainingColorModes != 0) {
        final int colorBitOffset=Integer.numberOfTrailingZeros(remainingColorModes);
        final int colorMode=1 << colorBitOffset;
        remainingColorModes&=~colorMode;
        if (colorMode != mColorModeSpinnerAdapter.getItem(adapterIndex).value) {
          colorModesChanged=true;
          break;
        }
        adapterIndex++;
      }
    }
    if (colorModesChanged) {
      int oldColorModeNewIndex=AdapterView.INVALID_POSITION;
      final int oldColorMode=mCurrPrintAttributes.getColorMode();
      mColorModeSpinnerAdapter.clear();
      String[] colorModeLabels=getResources().getStringArray(R.array.color_mode_labels);
      int remainingColorModes=colorModes;
      while (remainingColorModes != 0) {
        final int colorBitOffset=Integer.numberOfTrailingZeros(remainingColorModes);
        final int colorMode=1 << colorBitOffset;
        if (colorMode == oldColorMode) {
          oldColorModeNewIndex=colorBitOffset;
        }
        remainingColorModes&=~colorMode;
        mColorModeSpinnerAdapter.add(new SpinnerItem<Integer>(colorMode,colorModeLabels[colorBitOffset]));
      }
      final int colorModeCount=Integer.bitCount(colorModes);
      if (colorModeCount <= 0) {
        mColorModeSpinner.setEnabled(false);
        mColorModeSpinner.setSelection(AdapterView.INVALID_POSITION);
      }
 else {
        mColorModeSpinner.setEnabled(true);
        if (oldColorModeNewIndex != AdapterView.INVALID_POSITION) {
          setColorModeSpinnerSelectionNoCallback(oldColorModeNewIndex);
        }
 else {
          final int selectedColorModeIndex=Integer.numberOfTrailingZeros((colorModes & defaultAttributes.getColorMode()));
          someAttributeSelectionChanged=setColorModeSpinnerSelectionNoCallback(selectedColorModeIndex);
        }
      }
    }
    mColorModeSpinner.setEnabled(true);
    mOrientationSpinner.setEnabled(true);
    PrintDocumentInfo info=mDocument.info;
    if (info != null && (info.getPageCount() > 0 || info.getPageCount() == PrintDocumentInfo.PAGE_COUNT_UNKNOWN)) {
      if (info.getPageCount() == 1) {
        mRangeOptionsSpinner.setEnabled(false);
      }
 else {
        mRangeOptionsSpinner.setEnabled(true);
        if (mRangeOptionsSpinner.getSelectedItemPosition() > 0) {
          if (!mPageRangeEditText.isEnabled()) {
            mPageRangeEditText.setEnabled(true);
            mPageRangeEditText.setVisibility(View.VISIBLE);
            mPageRangeTitle.setVisibility(View.VISIBLE);
            mPageRangeEditText.requestFocus();
            InputMethodManager imm=(InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
            imm.showSoftInput(mPageRangeEditText,0);
          }
        }
 else {
          mPageRangeEditText.setEnabled(false);
          mPageRangeEditText.setVisibility(View.INVISIBLE);
          mPageRangeTitle.setVisibility(View.INVISIBLE);
        }
      }
      final int pageCount=mDocument.info.getPageCount();
      mRangeOptionsTitle.setText(getString(R.string.label_pages,(pageCount == PrintDocumentInfo.PAGE_COUNT_UNKNOWN) ? getString(R.string.page_count_unknown) : String.valueOf(pageCount)));
    }
 else {
      if (mRangeOptionsSpinner.getSelectedItemPosition() != 0) {
        mIgnoreNextRangeOptionChange=true;
        mRangeOptionsSpinner.setSelection(0);
      }
      mRangeOptionsSpinner.setEnabled(false);
      mRangeOptionsTitle.setText(getString(R.string.label_pages,getString(R.string.page_count_unknown)));
      mPageRangeEditText.setEnabled(false);
      mPageRangeEditText.setVisibility(View.INVISIBLE);
      mPageRangeTitle.setVisibility(View.INVISIBLE);
    }
    if (mDestinationSpinner.getSelectedItemId() != DEST_ADAPTER_ITEM_ID_SAVE_AS_PDF) {
      String newText=getString(R.string.print_button);
      if (!TextUtils.equals(newText,mPrintButton.getText())) {
        mPrintButton.setText(R.string.print_button);
      }
    }
 else {
      String newText=getString(R.string.save_button);
      if (!TextUtils.equals(newText,mPrintButton.getText())) {
        mPrintButton.setText(R.string.save_button);
      }
    }
    if ((mRangeOptionsSpinner.getSelectedItemPosition() == 1 && (TextUtils.isEmpty(mPageRangeEditText.getText()) || hasErrors())) || (mRangeOptionsSpinner.getSelectedItemPosition() == 0 && (!mController.hasPerformedLayout() || hasErrors()))) {
      mPrintButton.setEnabled(false);
    }
 else {
      mPrintButton.setEnabled(true);
    }
    if (mDestinationSpinner.getSelectedItemId() != DEST_ADAPTER_ITEM_ID_SAVE_AS_PDF) {
      mCopiesEditText.setEnabled(true);
    }
 else {
      mCopiesEditText.setEnabled(false);
    }
    if (mCopiesEditText.getError() == null && TextUtils.isEmpty(mCopiesEditText.getText())) {
      mIgnoreNextCopiesChange=true;
      mCopiesEditText.setText(String.valueOf(MIN_COPIES));
      mCopiesEditText.selectAll();
      mCopiesEditText.requestFocus();
    }
    return someAttributeSelectionChanged;
  }
}

Fixed version (ground truth):
public boolean updateUi(){
  if (mCurrentUi != UI_EDITING_PRINT_JOB) {
    return false;
  }
  if (isPrintConfirmed() || isCancelled()) {
    mDestinationSpinner.setEnabled(false);
    mCopiesEditText.setEnabled(false);
    mMediaSizeSpinner.setEnabled(false);
    mColorModeSpinner.setEnabled(false);
    mOrientationSpinner.setEnabled(false);
    mRangeOptionsSpinner.setEnabled(false);
    mPageRangeEditText.setEnabled(false);
    mPrintButton.setEnabled(false);
    return false;
  }
  boolean allOptionsEnabled=false;
  final int selectedIndex=mDestinationSpinner.getSelectedItemPosition();
  if (selectedIndex >= 0) {
    Object item=mDestinationSpinnerAdapter.getItem(selectedIndex);
    if (item instanceof PrinterInfo) {
      PrinterInfo printer=(PrinterInfo)item;
      if (printer.getCapabilities() != null) {
        allOptionsEnabled=true;
      }
    }
  }
  if (!allOptionsEnabled) {
    String minCopiesString=String.valueOf(MIN_COPIES);
    if (!TextUtils.equals(mCopiesEditText.getText(),minCopiesString)) {
      mIgnoreNextCopiesChange=true;
      mCopiesEditText.setText(minCopiesString);
    }
    mCopiesEditText.setEnabled(false);
    if (mMediaSizeSpinner.getSelectedItemPosition() != AdapterView.INVALID_POSITION) {
      mIgnoreNextMediaSizeChange=true;
      mMediaSizeSpinner.setSelection(AdapterView.INVALID_POSITION);
    }
    mMediaSizeSpinner.setEnabled(false);
    if (mColorModeSpinner.getSelectedItemPosition() != AdapterView.INVALID_POSITION) {
      mIgnoreNextColorModeChange=true;
      mColorModeSpinner.setSelection(AdapterView.INVALID_POSITION);
    }
    mColorModeSpinner.setEnabled(false);
    if (mOrientationSpinner.getSelectedItemPosition() != 0) {
      mIgnoreNextOrientationChange=true;
      mOrientationSpinner.setSelection(0);
    }
    mOrientationSpinner.setEnabled(false);
    if (mRangeOptionsSpinner.getSelectedItemPosition() != 0) {
      mIgnoreNextRangeOptionChange=true;
      mRangeOptionsSpinner.setSelection(0);
    }
    mRangeOptionsSpinner.setEnabled(false);
    mRangeOptionsTitle.setText(getString(R.string.label_pages,getString(R.string.page_count_unknown)));
    if (!TextUtils.equals(mPageRangeEditText.getText(),"String_Node_Str")) {
      mIgnoreNextRangeChange=true;
      mPageRangeEditText.setText("String_Node_Str");
    }
    mPageRangeEditText.setEnabled(false);
    mPageRangeEditText.setVisibility(View.INVISIBLE);
    mPageRangeTitle.setVisibility(View.INVISIBLE);
    mPrintButton.setEnabled(false);
    return false;
  }
 else {
    boolean someAttributeSelectionChanged=false;
    PrintAttributes defaultAttributes=mTempPrintAttributes;
    PrinterInfo printer=(PrinterInfo)mDestinationSpinner.getSelectedItem();
    PrinterCapabilitiesInfo capabilities=printer.getCapabilities();
    printer.getCapabilities().getDefaults(defaultAttributes);
    List<MediaSize> mediaSizes=capabilities.getMediaSizes();
    boolean mediaSizesChanged=false;
    final int mediaSizeCount=mediaSizes.size();
    if (mediaSizeCount != mMediaSizeSpinnerAdapter.getCount()) {
      mediaSizesChanged=true;
    }
 else {
      for (int i=0; i < mediaSizeCount; i++) {
        if (!mediaSizes.get(i).equals(mMediaSizeSpinnerAdapter.getItem(i).value)) {
          mediaSizesChanged=true;
          break;
        }
      }
    }
    if (mediaSizesChanged) {
      int oldMediaSizeNewIndex=AdapterView.INVALID_POSITION;
      MediaSize oldMediaSize=mCurrPrintAttributes.getMediaSize();
      mMediaSizeSpinnerAdapter.clear();
      for (int i=0; i < mediaSizeCount; i++) {
        MediaSize mediaSize=mediaSizes.get(i);
        if (mediaSize.equals(oldMediaSize)) {
          oldMediaSizeNewIndex=i;
        }
        mMediaSizeSpinnerAdapter.add(new SpinnerItem<MediaSize>(mediaSize,mediaSize.getLabel(getPackageManager())));
      }
      if (mediaSizeCount <= 0) {
        mMediaSizeSpinner.setEnabled(false);
        someAttributeSelectionChanged=setMediaSizeSpinnerSelectionNoCallback(AdapterView.INVALID_POSITION);
      }
 else {
        mMediaSizeSpinner.setEnabled(true);
        if (oldMediaSizeNewIndex != AdapterView.INVALID_POSITION) {
          setMediaSizeSpinnerSelectionNoCallback(oldMediaSizeNewIndex);
        }
 else {
          final int mediaSizeIndex=Math.max(mediaSizes.indexOf(defaultAttributes.getMediaSize()),0);
          someAttributeSelectionChanged=setMediaSizeSpinnerSelectionNoCallback(mediaSizeIndex);
        }
      }
    }
    mMediaSizeSpinner.setEnabled(true);
    final int colorModes=capabilities.getColorModes();
    boolean colorModesChanged=false;
    if (Integer.bitCount(colorModes) != mColorModeSpinnerAdapter.getCount()) {
      colorModesChanged=true;
    }
 else {
      int remainingColorModes=colorModes;
      int adapterIndex=0;
      while (remainingColorModes != 0) {
        final int colorBitOffset=Integer.numberOfTrailingZeros(remainingColorModes);
        final int colorMode=1 << colorBitOffset;
        remainingColorModes&=~colorMode;
        if (colorMode != mColorModeSpinnerAdapter.getItem(adapterIndex).value) {
          colorModesChanged=true;
          break;
        }
        adapterIndex++;
      }
    }
    if (colorModesChanged) {
      int oldColorModeNewIndex=AdapterView.INVALID_POSITION;
      final int oldColorMode=mCurrPrintAttributes.getColorMode();
      mColorModeSpinnerAdapter.clear();
      String[] colorModeLabels=getResources().getStringArray(R.array.color_mode_labels);
      int remainingColorModes=colorModes;
      while (remainingColorModes != 0) {
        final int colorBitOffset=Integer.numberOfTrailingZeros(remainingColorModes);
        final int colorMode=1 << colorBitOffset;
        if (colorMode == oldColorMode) {
          oldColorModeNewIndex=colorBitOffset;
        }
        remainingColorModes&=~colorMode;
        mColorModeSpinnerAdapter.add(new SpinnerItem<Integer>(colorMode,colorModeLabels[colorBitOffset]));
      }
      final int colorModeCount=Integer.bitCount(colorModes);
      if (colorModeCount <= 0) {
        mColorModeSpinner.setEnabled(false);
        mColorModeSpinner.setSelection(AdapterView.INVALID_POSITION);
      }
 else {
        mColorModeSpinner.setEnabled(true);
        if (oldColorModeNewIndex != AdapterView.INVALID_POSITION) {
          setColorModeSpinnerSelectionNoCallback(oldColorModeNewIndex);
        }
 else {
          final int selectedColorModeIndex=Integer.numberOfTrailingZeros((colorModes & defaultAttributes.getColorMode()));
          someAttributeSelectionChanged=setColorModeSpinnerSelectionNoCallback(selectedColorModeIndex);
        }
      }
    }
    mColorModeSpinner.setEnabled(true);
    mOrientationSpinner.setEnabled(true);
    PrintDocumentInfo info=mDocument.info;
    if (info != null && (info.getPageCount() > 0 || info.getPageCount() == PrintDocumentInfo.PAGE_COUNT_UNKNOWN)) {
      if (info.getPageCount() == 1) {
        mRangeOptionsSpinner.setEnabled(false);
      }
 else {
        mRangeOptionsSpinner.setEnabled(true);
        if (mRangeOptionsSpinner.getSelectedItemPosition() > 0) {
          if (!mPageRangeEditText.isEnabled()) {
            mPageRangeEditText.setEnabled(true);
            mPageRangeEditText.setVisibility(View.VISIBLE);
            mPageRangeTitle.setVisibility(View.VISIBLE);
            mPageRangeEditText.requestFocus();
            InputMethodManager imm=(InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
            imm.showSoftInput(mPageRangeEditText,0);
          }
        }
 else {
          mPageRangeEditText.setEnabled(false);
          mPageRangeEditText.setVisibility(View.INVISIBLE);
          mPageRangeTitle.setVisibility(View.INVISIBLE);
        }
      }
      final int pageCount=mDocument.info.getPageCount();
      mRangeOptionsTitle.setText(getString(R.string.label_pages,(pageCount == PrintDocumentInfo.PAGE_COUNT_UNKNOWN) ? getString(R.string.page_count_unknown) : String.valueOf(pageCount)));
    }
 else {
      if (mRangeOptionsSpinner.getSelectedItemPosition() != 0) {
        mIgnoreNextRangeOptionChange=true;
        mRangeOptionsSpinner.setSelection(0);
      }
      mRangeOptionsSpinner.setEnabled(false);
      mRangeOptionsTitle.setText(getString(R.string.label_pages,getString(R.string.page_count_unknown)));
      mPageRangeEditText.setEnabled(false);
      mPageRangeEditText.setVisibility(View.INVISIBLE);
      mPageRangeTitle.setVisibility(View.INVISIBLE);
    }
    if (mDestinationSpinner.getSelectedItemId() != DEST_ADAPTER_ITEM_ID_SAVE_AS_PDF) {
      String newText=getString(R.string.print_button);
      if (!TextUtils.equals(newText,mPrintButton.getText())) {
        mPrintButton.setText(R.string.print_button);
      }
    }
 else {
      String newText=getString(R.string.save_button);
      if (!TextUtils.equals(newText,mPrintButton.getText())) {
        mPrintButton.setText(R.string.save_button);
      }
    }
    if ((mRangeOptionsSpinner.getSelectedItemPosition() == 1 && (TextUtils.isEmpty(mPageRangeEditText.getText()) || hasErrors())) || (mRangeOptionsSpinner.getSelectedItemPosition() == 0 && (!mController.hasPerformedLayout() || hasErrors()))) {
      mPrintButton.setEnabled(false);
    }
 else {
      mPrintButton.setEnabled(true);
    }
    if (mDestinationSpinner.getSelectedItemId() != DEST_ADAPTER_ITEM_ID_SAVE_AS_PDF) {
      mCopiesEditText.setEnabled(true);
    }
 else {
      mCopiesEditText.setEnabled(false);
    }
    if (mCopiesEditText.getError() == null && TextUtils.isEmpty(mCopiesEditText.getText())) {
      mIgnoreNextCopiesChange=true;
      mCopiesEditText.setText(String.valueOf(MIN_COPIES));
      mCopiesEditText.selectAll();
      mCopiesEditText.requestFocus();
    }
    return someAttributeSelectionChanged;
  }
}