Program: 1721
Project: 1721
Buggy source:
public TimePicker(Context context,AttributeSet attrs,int defStyle){
  super(context,attrs,defStyle);
  setCurrentLocale(Locale.getDefault());
  TypedArray attributesArray=context.obtainStyledAttributes(attrs,R.styleable.TimePicker,defStyle,0);
  int layoutResourceId=attributesArray.getResourceId(R.styleable.TimePicker_internalLayout,R.layout.time_picker);
  attributesArray.recycle();
  LayoutInflater inflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  inflater.inflate(layoutResourceId,this,true);
  mHourSpinner=(NumberPicker)findViewById(R.id.hour);
  mHourSpinner.setOnValueChangedListener(new NumberPicker.OnValueChangeListener(){
    public void onValueChange(    NumberPicker spinner,    int oldVal,    int newVal){
      updateInputState();
      if (!is24HourView()) {
        if ((oldVal == HOURS_IN_HALF_DAY - 1 && newVal == HOURS_IN_HALF_DAY) || (oldVal == HOURS_IN_HALF_DAY && newVal == HOURS_IN_HALF_DAY - 1)) {
          mIsAm=!mIsAm;
          updateAmPmControl();
        }
      }
      onTimeChanged();
    }
  }
);
  mHourSpinnerInput=(EditText)mHourSpinner.findViewById(R.id.numberpicker_input);
  mHourSpinnerInput.setImeOptions(EditorInfo.IME_ACTION_NEXT);
  mDivider=(TextView)findViewById(R.id.divider);
  if (mDivider != null) {
    mDivider.setText(R.string.time_picker_separator);
  }
  mMinuteSpinner=(NumberPicker)findViewById(R.id.minute);
  mMinuteSpinner.setMinValue(0);
  mMinuteSpinner.setMaxValue(59);
  mMinuteSpinner.setOnLongPressUpdateInterval(100);
  mMinuteSpinner.setFormatter(NumberPicker.getTwoDigitFormatter());
  mMinuteSpinner.setOnValueChangedListener(new NumberPicker.OnValueChangeListener(){
    public void onValueChange(    NumberPicker spinner,    int oldVal,    int newVal){
      updateInputState();
      int minValue=mMinuteSpinner.getMinValue();
      int maxValue=mMinuteSpinner.getMaxValue();
      if (oldVal == maxValue && newVal == minValue) {
        int newHour=mHourSpinner.getValue() + 1;
        if (!is24HourView() && newHour == HOURS_IN_HALF_DAY) {
          mIsAm=!mIsAm;
          updateAmPmControl();
        }
        mHourSpinner.setValue(newHour);
      }
 else       if (oldVal == minValue && newVal == maxValue) {
        int newHour=mHourSpinner.getValue() - 1;
        if (!is24HourView() && newHour == HOURS_IN_HALF_DAY - 1) {
          mIsAm=!mIsAm;
          updateAmPmControl();
        }
        mHourSpinner.setValue(newHour);
      }
      onTimeChanged();
    }
  }
);
  mMinuteSpinnerInput=(EditText)mMinuteSpinner.findViewById(R.id.numberpicker_input);
  mMinuteSpinnerInput.setImeOptions(EditorInfo.IME_ACTION_NEXT);
  mAmPmStrings=new DateFormatSymbols().getAmPmStrings();
  View amPmView=findViewById(R.id.amPm);
  if (amPmView instanceof Button) {
    mAmPmSpinner=null;
    mAmPmSpinnerInput=null;
    mAmPmButton=(Button)amPmView;
    mAmPmButton.setOnClickListener(new OnClickListener(){
      public void onClick(      View button){
        button.requestFocus();
        mIsAm=!mIsAm;
        updateAmPmControl();
        onTimeChanged();
      }
    }
);
  }
 else {
    mAmPmButton=null;
    mAmPmSpinner=(NumberPicker)amPmView;
    mAmPmSpinner.setMinValue(0);
    mAmPmSpinner.setMaxValue(1);
    mAmPmSpinner.setDisplayedValues(mAmPmStrings);
    mAmPmSpinner.setOnValueChangedListener(new OnValueChangeListener(){
      public void onValueChange(      NumberPicker picker,      int oldVal,      int newVal){
        updateInputState();
        picker.requestFocus();
        mIsAm=!mIsAm;
        updateAmPmControl();
        onTimeChanged();
      }
    }
);
    mAmPmSpinnerInput=(EditText)mAmPmSpinner.findViewById(R.id.numberpicker_input);
    mAmPmSpinnerInput.setImeOptions(EditorInfo.IME_ACTION_DONE);
  }
  updateHourControl();
  updateMinuteControl();
  updateAmPmControl();
  setOnTimeChangedListener(NO_OP_CHANGE_LISTENER);
  setCurrentHour(mTempCalendar.get(Calendar.HOUR_OF_DAY));
  setCurrentMinute(mTempCalendar.get(Calendar.MINUTE));
  if (!isEnabled()) {
    setEnabled(false);
  }
  setContentDescriptions();
  if (getImportantForAccessibility() == IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
    setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES);
  }
}

Fixed version (ground truth):
public TimePicker(Context context,AttributeSet attrs,int defStyle){
  super(context,attrs,defStyle);
  setCurrentLocale(Locale.getDefault());
  TypedArray attributesArray=context.obtainStyledAttributes(attrs,R.styleable.TimePicker,defStyle,0);
  int layoutResourceId=attributesArray.getResourceId(R.styleable.TimePicker_internalLayout,R.layout.time_picker);
  attributesArray.recycle();
  LayoutInflater inflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  inflater.inflate(layoutResourceId,this,true);
  mHourSpinner=(NumberPicker)findViewById(R.id.hour);
  mHourSpinner.setOnValueChangedListener(new NumberPicker.OnValueChangeListener(){
    public void onValueChange(    NumberPicker spinner,    int oldVal,    int newVal){
      updateInputState();
      if (!is24HourView()) {
        if ((oldVal == HOURS_IN_HALF_DAY - 1 && newVal == HOURS_IN_HALF_DAY) || (oldVal == HOURS_IN_HALF_DAY && newVal == HOURS_IN_HALF_DAY - 1)) {
          mIsAm=!mIsAm;
          updateAmPmControl();
        }
      }
      onTimeChanged();
    }
  }
);
  mHourSpinnerInput=(EditText)mHourSpinner.findViewById(R.id.numberpicker_input);
  mHourSpinnerInput.setImeOptions(EditorInfo.IME_ACTION_NEXT);
  mDivider=(TextView)findViewById(R.id.divider);
  if (mDivider != null) {
    setDividerText();
  }
  mMinuteSpinner=(NumberPicker)findViewById(R.id.minute);
  mMinuteSpinner.setMinValue(0);
  mMinuteSpinner.setMaxValue(59);
  mMinuteSpinner.setOnLongPressUpdateInterval(100);
  mMinuteSpinner.setFormatter(NumberPicker.getTwoDigitFormatter());
  mMinuteSpinner.setOnValueChangedListener(new NumberPicker.OnValueChangeListener(){
    public void onValueChange(    NumberPicker spinner,    int oldVal,    int newVal){
      updateInputState();
      int minValue=mMinuteSpinner.getMinValue();
      int maxValue=mMinuteSpinner.getMaxValue();
      if (oldVal == maxValue && newVal == minValue) {
        int newHour=mHourSpinner.getValue() + 1;
        if (!is24HourView() && newHour == HOURS_IN_HALF_DAY) {
          mIsAm=!mIsAm;
          updateAmPmControl();
        }
        mHourSpinner.setValue(newHour);
      }
 else       if (oldVal == minValue && newVal == maxValue) {
        int newHour=mHourSpinner.getValue() - 1;
        if (!is24HourView() && newHour == HOURS_IN_HALF_DAY - 1) {
          mIsAm=!mIsAm;
          updateAmPmControl();
        }
        mHourSpinner.setValue(newHour);
      }
      onTimeChanged();
    }
  }
);
  mMinuteSpinnerInput=(EditText)mMinuteSpinner.findViewById(R.id.numberpicker_input);
  mMinuteSpinnerInput.setImeOptions(EditorInfo.IME_ACTION_NEXT);
  mAmPmStrings=new DateFormatSymbols().getAmPmStrings();
  View amPmView=findViewById(R.id.amPm);
  if (amPmView instanceof Button) {
    mAmPmSpinner=null;
    mAmPmSpinnerInput=null;
    mAmPmButton=(Button)amPmView;
    mAmPmButton.setOnClickListener(new OnClickListener(){
      public void onClick(      View button){
        button.requestFocus();
        mIsAm=!mIsAm;
        updateAmPmControl();
        onTimeChanged();
      }
    }
);
  }
 else {
    mAmPmButton=null;
    mAmPmSpinner=(NumberPicker)amPmView;
    mAmPmSpinner.setMinValue(0);
    mAmPmSpinner.setMaxValue(1);
    mAmPmSpinner.setDisplayedValues(mAmPmStrings);
    mAmPmSpinner.setOnValueChangedListener(new OnValueChangeListener(){
      public void onValueChange(      NumberPicker picker,      int oldVal,      int newVal){
        updateInputState();
        picker.requestFocus();
        mIsAm=!mIsAm;
        updateAmPmControl();
        onTimeChanged();
      }
    }
);
    mAmPmSpinnerInput=(EditText)mAmPmSpinner.findViewById(R.id.numberpicker_input);
    mAmPmSpinnerInput.setImeOptions(EditorInfo.IME_ACTION_DONE);
  }
  if (isAmPmAtStart()) {
    ViewGroup amPmParent=(ViewGroup)findViewById(R.id.timePickerLayout);
    amPmParent.removeView(amPmView);
    amPmParent.addView(amPmView,0);
    ViewGroup.MarginLayoutParams lp=(ViewGroup.MarginLayoutParams)amPmView.getLayoutParams();
    final int startMargin=lp.getMarginStart();
    final int endMargin=lp.getMarginEnd();
    if (startMargin != endMargin) {
      lp.setMarginStart(endMargin);
      lp.setMarginEnd(startMargin);
    }
  }
  getHourFormatData();
  updateHourControl();
  updateMinuteControl();
  updateAmPmControl();
  setOnTimeChangedListener(NO_OP_CHANGE_LISTENER);
  setCurrentHour(mTempCalendar.get(Calendar.HOUR_OF_DAY));
  setCurrentMinute(mTempCalendar.get(Calendar.MINUTE));
  if (!isEnabled()) {
    setEnabled(false);
  }
  setContentDescriptions();
  if (getImportantForAccessibility() == IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
    setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES);
  }
}