Program: 188607
Project: 188607
Buggy source:
/** 
 * Create a new panel to edit a user
 * @param user the user to edit
 */
public EditDescriptiveMetadata(final String aipId,final DescriptiveMetadataEditBundle bundleParam){
  this.aipId=aipId;
  this.bundle=bundleParam;
  HashSet<MetadataValue> newValues=null;
  if (bundle.getValues() != null) {
    newValues=new HashSet<MetadataValue>();
    for (    MetadataValue mv : bundle.getValues())     newValues.add(mv.clone());
  }
  supportedBundle=new SupportedMetadataTypeBundle(bundle.getType(),bundle.getVersion(),bundle.getId(),bundle.getRawTemplate(),newValues);
  initWidget(uiBinder.createAndBindUi(this));
  metadataXML=new TextArea();
  metadataXML.addStyleName("String_Node_Str");
  id.setText(bundle.getId());
  id.setEnabled(false);
  type.addChangeHandler(new ChangeHandler(){
    @Override public void onChange(    ChangeEvent changeEvent){
      String typeString=null, version="String_Node_Str";
      String value=type.getSelectedValue();
      if (value.contains(RodaConstants.METADATA_VERSION_SEPARATOR) && bundle.getVersion() != null) {
        typeString=value.substring(0,value.lastIndexOf(RodaConstants.METADATA_VERSION_SEPARATOR));
        version=value.substring(value.lastIndexOf(RodaConstants.METADATA_VERSION_SEPARATOR) + 1,value.length());
      }
      if (typeString == null) {
        typeString=value;
      }
      BrowserService.Util.getInstance().retrieveDescriptiveMetadataEditBundle(aipId,bundle.getId(),typeString,version,new AsyncCallback<DescriptiveMetadataEditBundle>(){
        @Override public void onFailure(        Throwable caught){
          AsyncCallbackUtils.defaultFailureTreatment(caught);
        }
        @Override public void onSuccess(        DescriptiveMetadataEditBundle editBundle){
          bundle=editBundle;
          HashSet<MetadataValue> newValues=null;
          if (bundle.getValues() != null) {
            newValues=new HashSet<MetadataValue>();
            for (            MetadataValue mv : bundle.getValues())             newValues.add(mv.clone());
          }
          supportedBundle=new SupportedMetadataTypeBundle(bundle.getType(),bundle.getVersion(),bundle.getId(),bundle.getRawTemplate(),newValues);
          updateFormOrXML();
        }
      }
);
    }
  }
);
  BrowserService.Util.getInstance().retrieveSupportedMetadata(aipId,LocaleInfo.getCurrentLocale().getLocaleName(),new AsyncCallback<List<SupportedMetadataTypeBundle>>(){
    @Override public void onFailure(    Throwable caught){
      AsyncCallbackUtils.defaultFailureTreatment(caught);
    }
    @Override public void onSuccess(    List<SupportedMetadataTypeBundle> metadataTypes){
      int selected=-1;
      int index=0;
      for (      SupportedMetadataTypeBundle b : metadataTypes) {
        if (b.getVersion() != null) {
          type.addItem(b.getLabel(),b.getType() + RodaConstants.METADATA_VERSION_SEPARATOR + b.getVersion());
        }
 else {
          type.addItem(b.getLabel(),b.getType());
        }
        String lowerCaseType=bundle.getType() != null ? bundle.getType().toLowerCase() : null;
        if (b.getType().toLowerCase().equals(lowerCaseType)) {
          String lowerCaseVersion=bundle.getVersion() != null ? bundle.getVersion().toLowerCase() : null;
          if (b.getVersion() != null && lowerCaseVersion != null) {
            if (lowerCaseVersion != null && b.getVersion().equals(lowerCaseVersion)) {
              selected=index;
            }
          }
 else           if (b.getVersion() == null && lowerCaseVersion == null) {
            selected=index;
          }
        }
        index++;
      }
      updateFormOrXML();
      if (selected >= 0) {
        type.addItem(messages.otherItem(),"String_Node_Str");
        type.setSelectedIndex(selected);
      }
 else       if ("String_Node_Str".equals(bundle.getType())) {
        type.addItem(messages.otherItem(),"String_Node_Str");
        type.setSelectedIndex(type.getItemCount() - 1);
      }
 else {
        type.addItem(messages.otherItem() + "String_Node_Str" + bundle.getType()+ "String_Node_Str",bundle.getType());
        type.addItem(messages.otherItem(),"String_Node_Str");
        type.setSelectedIndex(type.getItemCount() - 2);
      }
    }
  }
);
}

Fixed version (ground truth):
/** 
 * Create a new panel to edit a user
 * @param user the user to edit
 */
public EditDescriptiveMetadata(final String aipId,final DescriptiveMetadataEditBundle bundleParam){
  this.aipId=aipId;
  this.bundle=bundleParam;
  HashSet<MetadataValue> newValues=null;
  if (bundle.getValues() != null) {
    newValues=new HashSet<MetadataValue>();
    for (    MetadataValue mv : bundle.getValues())     newValues.add(mv.clone());
  }
  supportedBundle=new SupportedMetadataTypeBundle(bundle.getType(),bundle.getVersion(),bundle.getId(),bundle.getRawTemplate(),newValues);
  initWidget(uiBinder.createAndBindUi(this));
  metadataXML=new TextArea();
  metadataXML.addStyleName("String_Node_Str");
  id.setText(bundle.getId());
  id.setEnabled(false);
  type.addChangeHandler(new ChangeHandler(){
    @Override public void onChange(    ChangeEvent changeEvent){
      String typeString=null, version="String_Node_Str";
      String value=type.getSelectedValue();
      if (value.contains(RodaConstants.METADATA_VERSION_SEPARATOR) && bundle.getVersion() != null) {
        typeString=value.substring(0,value.lastIndexOf(RodaConstants.METADATA_VERSION_SEPARATOR));
        version=value.substring(value.lastIndexOf(RodaConstants.METADATA_VERSION_SEPARATOR) + 1,value.length());
      }
      if (typeString == null) {
        typeString=value;
      }
      BrowserService.Util.getInstance().retrieveDescriptiveMetadataEditBundle(aipId,bundle.getId(),typeString,version,new AsyncCallback<DescriptiveMetadataEditBundle>(){
        @Override public void onFailure(        Throwable caught){
          AsyncCallbackUtils.defaultFailureTreatment(caught);
        }
        @Override public void onSuccess(        DescriptiveMetadataEditBundle editBundle){
          bundle=editBundle;
          HashSet<MetadataValue> newValues=null;
          if (bundle.getValues() != null) {
            newValues=new HashSet<MetadataValue>();
            for (            MetadataValue mv : bundle.getValues())             newValues.add(mv.clone());
          }
          supportedBundle=new SupportedMetadataTypeBundle(bundle.getType(),bundle.getVersion(),bundle.getId(),bundle.getRawTemplate(),newValues);
          updateFormOrXML();
        }
      }
);
    }
  }
);
  BrowserService.Util.getInstance().retrieveSupportedMetadata(aipId,LocaleInfo.getCurrentLocale().getLocaleName(),new AsyncCallback<List<SupportedMetadataTypeBundle>>(){
    @Override public void onFailure(    Throwable caught){
      AsyncCallbackUtils.defaultFailureTreatment(caught);
    }
    @Override public void onSuccess(    List<SupportedMetadataTypeBundle> metadataTypes){
      int selected=-1;
      int index=0;
      Map<String,Integer> types=new HashMap<String,Integer>();
      for (      SupportedMetadataTypeBundle b : metadataTypes) {
        if (b.getVersion() != null) {
          type.addItem(b.getLabel(),b.getType() + RodaConstants.METADATA_VERSION_SEPARATOR + b.getVersion());
        }
 else {
          type.addItem(b.getLabel(),b.getType());
        }
        String lowerCaseType=bundle.getType() != null ? bundle.getType().toLowerCase() : null;
        if (b.getType().toLowerCase().equals(lowerCaseType)) {
          String lowerCaseVersion=bundle.getVersion() != null ? bundle.getVersion().toLowerCase() : null;
          if (b.getVersion() != null && lowerCaseVersion != null) {
            if (lowerCaseVersion != null && b.getVersion().equals(lowerCaseVersion)) {
              selected=index;
            }
          }
 else           if (b.getVersion() == null && lowerCaseVersion == null) {
            selected=index;
          }
        }
        types.put(b.getType(),index);
        index++;
      }
      updateFormOrXML();
      if (selected >= 0) {
        type.addItem(messages.otherItem(),"String_Node_Str");
        type.setSelectedIndex(selected);
      }
 else       if ("String_Node_Str".equals(bundle.getType())) {
        type.addItem(messages.otherItem(),"String_Node_Str");
        type.setSelectedIndex(type.getItemCount() - 1);
      }
 else {
        if (!types.keySet().contains(bundle.getType())) {
          type.addItem(messages.otherItem() + "String_Node_Str" + bundle.getType()+ "String_Node_Str",bundle.getType());
          type.addItem(messages.otherItem(),"String_Node_Str");
          type.setSelectedIndex(type.getItemCount() - 2);
        }
 else {
          type.addItem(messages.otherItem(),"String_Node_Str");
          type.setSelectedIndex(types.get(bundle.getType()));
        }
      }
    }
  }
);
}