Program: 87464
Project: 87464
Buggy source:
@Override protected Dialog onCreateDialog(int id){
switch (id) {
case DIALOG_SELECTTIME:
    Calendar oldTime=null;
  boolean travelAt=true;
if (routeSearch.arrival > 0) {
  travelAt=false;
  oldTime=Calendar.getInstance();
  oldTime.setTimeInMillis(routeSearch.arrival);
}
 else if (routeSearch.departure > 0) {
  oldTime=Calendar.getInstance();
  oldTime.setTimeInMillis(routeSearch.departure);
}
final Dialog dialog=new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.selectroute_dialog_timepick);
final ArrayList<CharSequence> travelAtArriveBeforeItems=new ArrayList<CharSequence>();
travelAtArriveBeforeItems.add(getText(R.string.travelAt));
travelAtArriveBeforeItems.add(getText(R.string.arriveBefore));
final Spinner travelAtArriveBeforeSpinner=(Spinner)dialog.findViewById(R.id.travelAtArriveBefore);
final ArrayAdapter<CharSequence> travelAtArriveBeforeAdapter=new ArrayAdapter<CharSequence>(this,android.R.layout.simple_spinner_item,travelAtArriveBeforeItems);
travelAtArriveBeforeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
travelAtArriveBeforeSpinner.setAdapter(travelAtArriveBeforeAdapter);
if (!travelAt) {
travelAtArriveBeforeSpinner.setSelection(1);
}
final TimePicker timePicker=(TimePicker)dialog.findViewById(R.id.timePicker);
View amPmView=((ViewGroup)timePicker.getChildAt(0)).getChildAt(2);
if (amPmView instanceof Button) {
amPmView.setOnClickListener(new OnClickListener(){
@Override public void onClick(View v){
Log.d("String_Node_Str","String_Node_Str");
if (v instanceof Button) {
if (((Button)v).getText().equals("String_Node_Str")) {
((Button)v).setText("String_Node_Str");
if (timePicker.getCurrentHour() < 12) {
timePicker.setCurrentHour(timePicker.getCurrentHour() + 12);
}
}
 else {
((Button)v).setText("String_Node_Str");
if (timePicker.getCurrentHour() >= 12) {
timePicker.setCurrentHour(timePicker.getCurrentHour() - 12);
}
}
}
}
}
);
}
if (oldTime != null) {
timePicker.setCurrentHour(oldTime.get(Calendar.HOUR_OF_DAY));
timePicker.setCurrentMinute(oldTime.get(Calendar.MINUTE));
}
final Spinner dayList=(Spinner)dialog.findViewById(R.id.dayList);
final SimpleDateFormat DATEFORMAT=new SimpleDateFormat("String_Node_Str");
ArrayList<String> dateList=new ArrayList<String>();
Calendar date=Calendar.getInstance();
int positionOfOldTime=0;
for (int i=0; i < 14; i++) {
if (oldTime != null && date.get(Calendar.DAY_OF_YEAR) == oldTime.get(Calendar.DAY_OF_YEAR)) {
positionOfOldTime=i;
}
dateList.add(DATEFORMAT.format(date.getTime()));
date.add(Calendar.DAY_OF_YEAR,1);
}
final ArrayAdapter<String> dayAdapter=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,dateList);
dayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
dayList.setAdapter(dayAdapter);
dayList.setSelection(positionOfOldTime);
final Button okButton=(Button)dialog.findViewById(R.id.okButton);
okButton.setOnClickListener(new OnClickListener(){
@Override public void onClick(View v){
try {
boolean travelAt=travelAtArriveBeforeSpinner.getSelectedItemPosition() == 0;
Date date=DATEFORMAT.parse(dayAdapter.getItem(dayList.getSelectedItemPosition()));
date.setHours(timePicker.getCurrentHour());
date.setMinutes(timePicker.getCurrentMinute());
if (travelAt) {
routeSearch.departure=date.getTime();
routeSearch.arrival=0;
}
 else {
routeSearch.departure=0;
routeSearch.arrival=date.getTime();
}
refreshMenu();
dialog.dismiss();
}
 catch (ParseException e) {
}
}
}
);
final Button resetButton=(Button)dialog.findViewById(R.id.resetButton);
resetButton.setOnClickListener(new OnClickListener(){
@Override public void onClick(View arg0){
routeSearch.departure=0;
routeSearch.arrival=0;
refreshMenu();
dialog.dismiss();
}
}
);
return dialog;
case DIALOG_TRANSPORTTYPES:
final CharSequence[] transportItems=routeSearch.getTransportArray(this);
final boolean[] checkedTransportItems={true,true,true,true,true,true,true};
AlertDialog.Builder transportBuilder=new AlertDialog.Builder(this);
transportBuilder.setTitle(R.string.transportTypes);
transportBuilder.setMultiChoiceItems(transportItems,checkedTransportItems,new DialogInterface.OnMultiChoiceClickListener(){
@Override public void onClick(DialogInterface dialog,int which,boolean isChecked){
routeSearch.transportTypes[which]=isChecked;
refreshMenu();
}
}
);
final AlertDialog transportDialog=transportBuilder.create();
transportDialog.setOnDismissListener(new OnDismissListener(){
@Override public void onDismiss(DialogInterface dialog){
int enabled=0;
for (int i=0; i < 7; i++) {
if (routeSearch.transportTypes[i]) {
enabled++;
}
}
if (enabled == 0) {
for (int i=0; i < 7; i++) {
routeSearch.transportTypes[i]=true;
}
}
}
}
);
return transportDialog;
case DIALOG_CHANGEMARGIN:
final CharSequence[] changeMarginItems={"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
AlertDialog.Builder changeBuilder=new AlertDialog.Builder(this);
changeBuilder.setTitle(R.string.setChangeMargin);
changeBuilder.setItems(changeMarginItems,new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int item){
routeSearch.changeMargin=item + 1;
refreshMenu();
}
}
);
return changeBuilder.create();
case DIALOG_CHANGEPRIORITY:
final CharSequence[] priorityItems={getText(R.string.shortTravel),getText(R.string.directRoute)};
AlertDialog.Builder priorityBuilder=new AlertDialog.Builder(this);
priorityBuilder.setTitle(R.string.prioritize);
priorityBuilder.setItems(priorityItems,new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int item){
if (item == 0) {
routeSearch.changePunish=2;
}
 else {
routeSearch.changePunish=10;
}
refreshMenu();
}
}
);
return priorityBuilder.create();
case DIALOG_PROPOSALS:
final CharSequence[] proposalItems={"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
AlertDialog.Builder changeProposals=new AlertDialog.Builder(this);
changeProposals.setTitle(R.string.setProposals);
changeProposals.setItems(proposalItems,new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int item){
switch (item) {
case 6:
routeSearch.proposals=15;
break;
case 5:
routeSearch.proposals=10;
break;
default :
routeSearch.proposals=item + 1;
}
refreshMenu();
}
}
);
return changeProposals.create();
}
return super.onCreateDialog(id);
}

Fixed version (ground truth):
@Override protected Dialog onCreateDialog(int id){
switch (id) {
case DIALOG_SELECTTIME:
    Calendar oldTime=null;
  boolean travelAt=true;
if (routeSearch.arrival > 0) {
  travelAt=false;
  oldTime=Calendar.getInstance();
  oldTime.setTimeInMillis(routeSearch.arrival);
}
 else if (routeSearch.departure > 0) {
  oldTime=Calendar.getInstance();
  oldTime.setTimeInMillis(routeSearch.departure);
}
final Dialog dialog=new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.selectroute_dialog_timepick);
final ArrayList<CharSequence> travelAtArriveBeforeItems=new ArrayList<CharSequence>();
travelAtArriveBeforeItems.add(getText(R.string.travelAt));
travelAtArriveBeforeItems.add(getText(R.string.arriveBefore));
final Spinner travelAtArriveBeforeSpinner=(Spinner)dialog.findViewById(R.id.travelAtArriveBefore);
final ArrayAdapter<CharSequence> travelAtArriveBeforeAdapter=new ArrayAdapter<CharSequence>(this,android.R.layout.simple_spinner_item,travelAtArriveBeforeItems);
travelAtArriveBeforeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
travelAtArriveBeforeSpinner.setAdapter(travelAtArriveBeforeAdapter);
if (!travelAt) {
travelAtArriveBeforeSpinner.setSelection(1);
}
final TimePicker timePicker=(TimePicker)dialog.findViewById(R.id.timePicker);
if (Build.VERSION.SDK_INT >= 11) {
View amPmView=((ViewGroup)timePicker.getChildAt(0)).getChildAt(2);
if (amPmView instanceof Button) {
amPmView.setOnClickListener(new OnClickListener(){
@Override public void onClick(View v){
Log.d("String_Node_Str","String_Node_Str");
if (v instanceof Button) {
if (((Button)v).getText().equals("String_Node_Str")) {
((Button)v).setText("String_Node_Str");
if (timePicker.getCurrentHour() < 12) {
timePicker.setCurrentHour(timePicker.getCurrentHour() + 12);
}
}
 else {
((Button)v).setText("String_Node_Str");
if (timePicker.getCurrentHour() >= 12) {
timePicker.setCurrentHour(timePicker.getCurrentHour() - 12);
}
}
}
}
}
);
}
}
 else {
timePicker.setIs24HourView(true);
}
if (oldTime != null) {
timePicker.setCurrentHour(oldTime.get(Calendar.HOUR_OF_DAY));
timePicker.setCurrentMinute(oldTime.get(Calendar.MINUTE));
}
final Spinner dayList=(Spinner)dialog.findViewById(R.id.dayList);
final SimpleDateFormat DATEFORMAT=new SimpleDateFormat("String_Node_Str");
ArrayList<String> dateList=new ArrayList<String>();
Calendar date=Calendar.getInstance();
int positionOfOldTime=0;
for (int i=0; i < 14; i++) {
if (oldTime != null && date.get(Calendar.DAY_OF_YEAR) == oldTime.get(Calendar.DAY_OF_YEAR)) {
positionOfOldTime=i;
}
dateList.add(DATEFORMAT.format(date.getTime()));
date.add(Calendar.DAY_OF_YEAR,1);
}
final ArrayAdapter<String> dayAdapter=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,dateList);
dayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
dayList.setAdapter(dayAdapter);
dayList.setSelection(positionOfOldTime);
final Button okButton=(Button)dialog.findViewById(R.id.okButton);
okButton.setOnClickListener(new OnClickListener(){
@Override public void onClick(View v){
try {
boolean travelAt=travelAtArriveBeforeSpinner.getSelectedItemPosition() == 0;
Date date=DATEFORMAT.parse(dayAdapter.getItem(dayList.getSelectedItemPosition()));
date.setHours(timePicker.getCurrentHour());
date.setMinutes(timePicker.getCurrentMinute());
if (travelAt) {
routeSearch.departure=date.getTime();
routeSearch.arrival=0;
}
 else {
routeSearch.departure=0;
routeSearch.arrival=date.getTime();
}
refreshMenu();
dialog.dismiss();
}
 catch (ParseException e) {
}
}
}
);
final Button resetButton=(Button)dialog.findViewById(R.id.resetButton);
resetButton.setOnClickListener(new OnClickListener(){
@Override public void onClick(View arg0){
routeSearch.departure=0;
routeSearch.arrival=0;
refreshMenu();
dialog.dismiss();
}
}
);
return dialog;
case DIALOG_TRANSPORTTYPES:
final CharSequence[] transportItems=routeSearch.getTransportArray(this);
final boolean[] checkedTransportItems={true,true,true,true,true,true,true};
AlertDialog.Builder transportBuilder=new AlertDialog.Builder(this);
transportBuilder.setTitle(R.string.transportTypes);
transportBuilder.setMultiChoiceItems(transportItems,checkedTransportItems,new DialogInterface.OnMultiChoiceClickListener(){
@Override public void onClick(DialogInterface dialog,int which,boolean isChecked){
routeSearch.transportTypes[which]=isChecked;
refreshMenu();
}
}
);
final AlertDialog transportDialog=transportBuilder.create();
transportDialog.setOnDismissListener(new OnDismissListener(){
@Override public void onDismiss(DialogInterface dialog){
int enabled=0;
for (int i=0; i < 7; i++) {
if (routeSearch.transportTypes[i]) {
enabled++;
}
}
if (enabled == 0) {
for (int i=0; i < 7; i++) {
routeSearch.transportTypes[i]=true;
}
}
}
}
);
return transportDialog;
case DIALOG_CHANGEMARGIN:
final CharSequence[] changeMarginItems={"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
AlertDialog.Builder changeBuilder=new AlertDialog.Builder(this);
changeBuilder.setTitle(R.string.setChangeMargin);
changeBuilder.setItems(changeMarginItems,new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int item){
routeSearch.changeMargin=item + 1;
refreshMenu();
}
}
);
return changeBuilder.create();
case DIALOG_CHANGEPRIORITY:
final CharSequence[] priorityItems={getText(R.string.shortTravel),getText(R.string.directRoute)};
AlertDialog.Builder priorityBuilder=new AlertDialog.Builder(this);
priorityBuilder.setTitle(R.string.prioritize);
priorityBuilder.setItems(priorityItems,new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int item){
if (item == 0) {
routeSearch.changePunish=2;
}
 else {
routeSearch.changePunish=10;
}
refreshMenu();
}
}
);
return priorityBuilder.create();
case DIALOG_PROPOSALS:
final CharSequence[] proposalItems={"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
AlertDialog.Builder changeProposals=new AlertDialog.Builder(this);
changeProposals.setTitle(R.string.setProposals);
changeProposals.setItems(proposalItems,new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int item){
switch (item) {
case 6:
routeSearch.proposals=15;
break;
case 5:
routeSearch.proposals=10;
break;
default :
routeSearch.proposals=item + 1;
}
refreshMenu();
}
}
);
return changeProposals.create();
}
return super.onCreateDialog(id);
}