Program: 192587
Project: 192587
Buggy source:
private void onAdvancedPrintOptionsActivityResult(int resultCode,Intent data){
  if (resultCode != RESULT_OK || data == null) {
    return;
  }
  PrintJobInfo printJobInfo=data.getParcelableExtra(PrintService.EXTRA_PRINT_JOB_INFO);
  if (printJobInfo == null) {
    return;
  }
  mPrintJob.setAdvancedOptions(printJobInfo.getAdvancedOptions());
  mCopiesEditText.setText(String.valueOf(printJobInfo.getCopies()));
  mPrintJob.setCopies(printJobInfo.getCopies());
  PrintAttributes currAttributes=mPrintJob.getAttributes();
  PrintAttributes newAttributes=printJobInfo.getAttributes();
  if (newAttributes != null) {
    MediaSize oldMediaSize=currAttributes.getMediaSize();
    MediaSize newMediaSize=newAttributes.getMediaSize();
    if (!oldMediaSize.equals(newMediaSize)) {
      final int mediaSizeCount=mMediaSizeSpinnerAdapter.getCount();
      MediaSize newMediaSizePortrait=newAttributes.getMediaSize().asPortrait();
      for (int i=0; i < mediaSizeCount; i++) {
        MediaSize supportedSizePortrait=mMediaSizeSpinnerAdapter.getItem(i).value.asPortrait();
        if (supportedSizePortrait.equals(newMediaSizePortrait)) {
          currAttributes.setMediaSize(newMediaSize);
          mMediaSizeSpinner.setSelection(i);
          if (currAttributes.getMediaSize().isPortrait()) {
            if (mOrientationSpinner.getSelectedItemPosition() != 0) {
              mOrientationSpinner.setSelection(0);
            }
          }
 else {
            if (mOrientationSpinner.getSelectedItemPosition() != 1) {
              mOrientationSpinner.setSelection(1);
            }
          }
          break;
        }
      }
    }
    Resolution oldResolution=currAttributes.getResolution();
    Resolution newResolution=newAttributes.getResolution();
    if (!oldResolution.equals(newResolution)) {
      PrinterCapabilitiesInfo capabilities=mCurrentPrinter.getCapabilities();
      if (capabilities != null) {
        List<Resolution> resolutions=capabilities.getResolutions();
        final int resolutionCount=resolutions.size();
        for (int i=0; i < resolutionCount; i++) {
          Resolution resolution=resolutions.get(i);
          if (resolution.equals(newResolution)) {
            currAttributes.setResolution(resolution);
            break;
          }
        }
      }
    }
    final int currColorMode=currAttributes.getColorMode();
    final int newColorMode=newAttributes.getColorMode();
    if (currColorMode != newColorMode) {
      final int colorModeCount=mColorModeSpinner.getCount();
      for (int i=0; i < colorModeCount; i++) {
        final int supportedColorMode=mColorModeSpinnerAdapter.getItem(i).value;
        if (supportedColorMode == newColorMode) {
          currAttributes.setColorMode(newColorMode);
          mColorModeSpinner.setSelection(i);
          break;
        }
      }
    }
    final int currDuplexMode=currAttributes.getDuplexMode();
    final int newDuplexMode=newAttributes.getDuplexMode();
    if (currDuplexMode != newDuplexMode) {
      final int duplexModeCount=mDuplexModeSpinner.getCount();
      for (int i=0; i < duplexModeCount; i++) {
        final int supportedDuplexMode=mDuplexModeSpinnerAdapter.getItem(i).value;
        if (supportedDuplexMode == newDuplexMode) {
          currAttributes.setDuplexMode(newDuplexMode);
          mDuplexModeSpinner.setSelection(i);
          break;
        }
      }
    }
  }
  PrintDocumentInfo info=mPrintedDocument.getDocumentInfo().info;
  final int pageCount=(info != null) ? getAdjustedPageCount(info) : 0;
  PageRange[] pageRanges=printJobInfo.getPages();
  if (pageRanges != null && pageCount > 0) {
    pageRanges=PageRangeUtils.normalize(pageRanges);
    List<PageRange> validatedList=new ArrayList<>();
    final int rangeCount=pageRanges.length;
    for (int i=0; i < rangeCount; i++) {
      PageRange pageRange=pageRanges[i];
      if (pageRange.getEnd() >= pageCount) {
        final int rangeStart=pageRange.getStart();
        final int rangeEnd=pageCount - 1;
        if (rangeStart <= rangeEnd) {
          pageRange=new PageRange(rangeStart,rangeEnd);
          validatedList.add(pageRange);
        }
        break;
      }
      validatedList.add(pageRange);
    }
    if (!validatedList.isEmpty()) {
      PageRange[] validatedArray=new PageRange[validatedList.size()];
      validatedList.toArray(validatedArray);
      updateSelectedPages(validatedArray,pageCount);
    }
  }
  if (canUpdateDocument()) {
    updateDocument(false);
  }
}

Fixed version (ground truth):
private void onAdvancedPrintOptionsActivityResult(int resultCode,Intent data){
  if (resultCode != RESULT_OK || data == null) {
    return;
  }
  PrintJobInfo printJobInfo=data.getParcelableExtra(PrintService.EXTRA_PRINT_JOB_INFO);
  if (printJobInfo == null) {
    return;
  }
  mPrintJob.setAdvancedOptions(printJobInfo.getAdvancedOptions());
  if (printJobInfo.getCopies() < 1) {
    Log.w(LOG_TAG,"String_Node_Str" + "String_Node_Str" + printJobInfo.getCopies() + "String_Node_Str"+ "String_Node_Str");
  }
 else {
    mCopiesEditText.setText(String.valueOf(printJobInfo.getCopies()));
    mPrintJob.setCopies(printJobInfo.getCopies());
  }
  PrintAttributes currAttributes=mPrintJob.getAttributes();
  PrintAttributes newAttributes=printJobInfo.getAttributes();
  if (newAttributes != null) {
    MediaSize oldMediaSize=currAttributes.getMediaSize();
    MediaSize newMediaSize=newAttributes.getMediaSize();
    if (newMediaSize != null && !oldMediaSize.equals(newMediaSize)) {
      final int mediaSizeCount=mMediaSizeSpinnerAdapter.getCount();
      MediaSize newMediaSizePortrait=newAttributes.getMediaSize().asPortrait();
      for (int i=0; i < mediaSizeCount; i++) {
        MediaSize supportedSizePortrait=mMediaSizeSpinnerAdapter.getItem(i).value.asPortrait();
        if (supportedSizePortrait.equals(newMediaSizePortrait)) {
          currAttributes.setMediaSize(newMediaSize);
          mMediaSizeSpinner.setSelection(i);
          if (currAttributes.getMediaSize().isPortrait()) {
            if (mOrientationSpinner.getSelectedItemPosition() != 0) {
              mOrientationSpinner.setSelection(0);
            }
          }
 else {
            if (mOrientationSpinner.getSelectedItemPosition() != 1) {
              mOrientationSpinner.setSelection(1);
            }
          }
          break;
        }
      }
    }
    Resolution oldResolution=currAttributes.getResolution();
    Resolution newResolution=newAttributes.getResolution();
    if (!oldResolution.equals(newResolution)) {
      PrinterCapabilitiesInfo capabilities=mCurrentPrinter.getCapabilities();
      if (capabilities != null) {
        List<Resolution> resolutions=capabilities.getResolutions();
        final int resolutionCount=resolutions.size();
        for (int i=0; i < resolutionCount; i++) {
          Resolution resolution=resolutions.get(i);
          if (resolution.equals(newResolution)) {
            currAttributes.setResolution(resolution);
            break;
          }
        }
      }
    }
    final int currColorMode=currAttributes.getColorMode();
    final int newColorMode=newAttributes.getColorMode();
    if (currColorMode != newColorMode) {
      final int colorModeCount=mColorModeSpinner.getCount();
      for (int i=0; i < colorModeCount; i++) {
        final int supportedColorMode=mColorModeSpinnerAdapter.getItem(i).value;
        if (supportedColorMode == newColorMode) {
          currAttributes.setColorMode(newColorMode);
          mColorModeSpinner.setSelection(i);
          break;
        }
      }
    }
    final int currDuplexMode=currAttributes.getDuplexMode();
    final int newDuplexMode=newAttributes.getDuplexMode();
    if (currDuplexMode != newDuplexMode) {
      final int duplexModeCount=mDuplexModeSpinner.getCount();
      for (int i=0; i < duplexModeCount; i++) {
        final int supportedDuplexMode=mDuplexModeSpinnerAdapter.getItem(i).value;
        if (supportedDuplexMode == newDuplexMode) {
          currAttributes.setDuplexMode(newDuplexMode);
          mDuplexModeSpinner.setSelection(i);
          break;
        }
      }
    }
  }
  PrintDocumentInfo info=mPrintedDocument.getDocumentInfo().info;
  final int pageCount=(info != null) ? getAdjustedPageCount(info) : 0;
  PageRange[] pageRanges=printJobInfo.getPages();
  if (pageRanges != null && pageCount > 0) {
    pageRanges=PageRangeUtils.normalize(pageRanges);
    List<PageRange> validatedList=new ArrayList<>();
    final int rangeCount=pageRanges.length;
    for (int i=0; i < rangeCount; i++) {
      PageRange pageRange=pageRanges[i];
      if (pageRange.getEnd() >= pageCount) {
        final int rangeStart=pageRange.getStart();
        final int rangeEnd=pageCount - 1;
        if (rangeStart <= rangeEnd) {
          pageRange=new PageRange(rangeStart,rangeEnd);
          validatedList.add(pageRange);
        }
        break;
      }
      validatedList.add(pageRange);
    }
    if (!validatedList.isEmpty()) {
      PageRange[] validatedArray=new PageRange[validatedList.size()];
      validatedList.toArray(validatedArray);
      updateSelectedPages(validatedArray,pageCount);
    }
  }
  if (canUpdateDocument()) {
    updateDocument(false);
  }
}