Program: 178837
Project: 178837
Buggy source:
@Override protected void onCreate(Bundle icicle){
  super.onCreate(icicle);
  dbAdapter=new MessagesDbAdapter(this);
  dbAdapter.open();
  setContentView(R.layout.message_edit);
  setTitle(R.string.message_add_outgoing_title);
  titleEditText=(EditText)findViewById(R.id.title_edit);
  messageEditText=(EditText)findViewById(R.id.message_edit);
  Button addAttachmentButton=(Button)findViewById(R.id.add_attachment_button);
  Button removeAttachmentButton=(Button)findViewById(R.id.remove_attachment_button);
  attachmentLabel=(TextView)findViewById(R.id.attachment_label);
  attachmentLabel.setVisibility(View.GONE);
  Spinner attachmentSpinner=(Spinner)findViewById(R.id.add_attachment_spinner);
  ArrayAdapter adapter=ArrayAdapter.createFromResource(this,R.array.add_attachment_array,android.R.layout.simple_spinner_item);
  adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  attachmentSpinner.setAdapter(adapter);
  attachmentSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){
    @Override public void onItemSelected(    AdapterView adapter,    View v,    int i,    long l){
      if (i == 0) {
        attachmentType=SELECT_TEXT;
      }
 else       if (i == 1) {
        attachmentType=SELECT_AUDIO;
      }
 else       if (i == 2) {
        attachmentType=SELECT_IMAGE;
      }
 else       if (i == 3) {
        attachmentType=SELECT_VIDEO;
      }
    }
    @Override public void onNothingSelected(    AdapterView arg0){
    }
  }
);
  addAttachmentButton.setOnClickListener(new View.OnClickListener(){
    public void onClick(    View view){
      if (attachmentType != SELECT_TEXT) {
switch (attachmentType) {
case SELECT_AUDIO:
          startActivityForResult(new Intent(Intent.ACTION_PICK,MediaStore.Audio.Media.INTERNAL_CONTENT_URI),attachmentType);
        break;
case SELECT_IMAGE:
      startActivityForResult(new Intent(Intent.ACTION_PICK,MediaStore.Images.Media.INTERNAL_CONTENT_URI),attachmentType);
    break;
case SELECT_VIDEO:
  startActivityForResult(new Intent(Intent.ACTION_PICK,MediaStore.Video.Media.INTERNAL_CONTENT_URI),attachmentType);
break;
default :
break;
}
}
}
}
);
removeAttachmentButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
attachmentLabel.setVisibility(View.GONE);
attachmentUri=null;
attachmentPath=null;
}
}
);
}

Fixed version (ground truth):
@Override protected void onCreate(Bundle icicle){
  super.onCreate(icicle);
  messagesProviderHelper=new MessagesProviderHelper(this);
  setContentView(R.layout.message_edit);
  setTitle(R.string.message_add_outgoing_title);
  titleEditText=(EditText)findViewById(R.id.title_edit);
  messageEditText=(EditText)findViewById(R.id.message_edit);
  Button addAttachmentButton=(Button)findViewById(R.id.add_attachment_button);
  Button removeAttachmentButton=(Button)findViewById(R.id.remove_attachment_button);
  attachmentLabel=(TextView)findViewById(R.id.attachment_label);
  attachmentLabel.setVisibility(View.GONE);
  Spinner attachmentSpinner=(Spinner)findViewById(R.id.add_attachment_spinner);
  ArrayAdapter adapter=ArrayAdapter.createFromResource(this,R.array.add_attachment_array,android.R.layout.simple_spinner_item);
  adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  attachmentSpinner.setAdapter(adapter);
  attachmentSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){
    @Override public void onItemSelected(    AdapterView adapter,    View v,    int i,    long l){
      if (i == 0) {
        attachmentType=SELECT_TEXT;
      }
 else       if (i == 1) {
        attachmentType=SELECT_AUDIO;
      }
 else       if (i == 2) {
        attachmentType=SELECT_IMAGE;
      }
 else       if (i == 3) {
        attachmentType=SELECT_VIDEO;
      }
    }
    @Override public void onNothingSelected(    AdapterView arg0){
    }
  }
);
  addAttachmentButton.setOnClickListener(new View.OnClickListener(){
    public void onClick(    View view){
      if (attachmentType != SELECT_TEXT) {
switch (attachmentType) {
case SELECT_AUDIO:
          startActivityForResult(new Intent(Intent.ACTION_PICK,MediaStore.Audio.Media.INTERNAL_CONTENT_URI),attachmentType);
        break;
case SELECT_IMAGE:
      startActivityForResult(new Intent(Intent.ACTION_PICK,MediaStore.Images.Media.INTERNAL_CONTENT_URI),attachmentType);
    break;
case SELECT_VIDEO:
  startActivityForResult(new Intent(Intent.ACTION_PICK,MediaStore.Video.Media.INTERNAL_CONTENT_URI),attachmentType);
break;
default :
break;
}
}
}
}
);
removeAttachmentButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
attachmentLabel.setVisibility(View.GONE);
attachmentUri=null;
attachmentPath=null;
}
}
);
}