Program: 141079
Project: 141079
Buggy source:
@Override public void write(final Design design) throws IOException {
  checkNotNull(design,"String_Node_Str");
  final BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(this.out,Globals.DEFAULT_CHARSET));
  checkNotNull(design,"String_Node_Str");
  bw.append(HEADER_SECTION);
  bw.append(NEWLINE);
  bw.append(Eoulsan2DesignReader.DESIGN_FORMAT_VERSION_METADATA_KEY);
  bw.append(EQUAL_SEPARATOR);
  bw.append(Eoulsan2DesignReader.FORMAT_VERSION);
  bw.append(NEWLINE);
  for (  Map.Entry<String,String> e : design.getMetadata().entrySet()) {
    bw.append(e.getKey());
    bw.append(EQUAL_SEPARATOR);
    bw.append(e.getValue());
    bw.append(NEWLINE);
  }
  bw.append(NEWLINE);
  if (!design.getExperiments().isEmpty()) {
    bw.append(EXPERIMENT_SECTION);
    bw.append(NEWLINE);
  }
  for (  Experiment e : design.getExperiments()) {
    final String expId=e.getId();
    bw.append(EXPERIMENT_FIELD_PREFIX + expId + DOT_SEPARATOR+ EXPERIMENT_NAME_SUFFIX+ EQUAL_SEPARATOR+ e.getName()+ NEWLINE);
    for (    Map.Entry<String,String> m : e.getMetadata().entrySet()) {
      bw.append(EXPERIMENT_FIELD_PREFIX + expId + DOT_SEPARATOR+ m.getKey());
      bw.append(EQUAL_SEPARATOR);
      bw.append(m.getValue());
      bw.append(NEWLINE);
    }
    bw.append(NEWLINE);
  }
  bw.append(COLUMN_SECTION);
  bw.append(NEWLINE);
  bw.append(SAMPLE_ID_FIELDNAME);
  bw.append(TAB_SEPARATOR);
  bw.append(SAMPLE_NAME_FIELDNAME);
  final List<String> sampleMDKeys=getAllSamplesMetadataKeys(design);
  for (  String key : sampleMDKeys) {
    if (SampleMetadata.UUID_KEY.equals(key)) {
      continue;
    }
    bw.append(TAB_SEPARATOR);
    bw.append(key);
  }
  for (  Experiment experiment : design.getExperiments()) {
    final String prefix=EXPERIMENT_FIELD_PREFIX + experiment.getId() + DOT_SEPARATOR;
    final List<String> experimentMDKeys=getExperimentSampleAllMetadataKeys(experiment);
    for (    String key : experimentMDKeys) {
      bw.append(TAB_SEPARATOR);
      bw.append(prefix);
      bw.append(key);
    }
  }
  if (sampleMDKeys.contains(UUID_KEY)) {
    bw.append(TAB_SEPARATOR);
    bw.append(UUID_KEY);
  }
  bw.append(NEWLINE);
  for (  Sample sample : design.getSamples()) {
    bw.append(sample.getId());
    bw.append(TAB_SEPARATOR);
    bw.append(sample.getName());
    final SampleMetadata smd=sample.getMetadata();
    for (    String key : sampleMDKeys) {
      if (UUID_KEY.equals(key)) {
        continue;
      }
      bw.append(TAB_SEPARATOR);
      if (smd.contains(key)) {
        bw.append(smd.get(key));
      }
    }
    for (    Experiment experiment : design.getExperiments()) {
      final ExperimentSampleMetadata expSampleMetadata=experiment.getExperimentSample(sample).getMetadata();
      final List<String> experimentMDKeys=getExperimentSampleAllMetadataKeys(experiment);
      for (      String key : experimentMDKeys) {
        bw.append(TAB_SEPARATOR);
        if (expSampleMetadata.contains(key)) {
          bw.append(expSampleMetadata.get(key));
        }
      }
    }
    if (sampleMDKeys.contains(UUID_KEY)) {
      bw.append(TAB_SEPARATOR);
      bw.append(smd.get(UUID_KEY));
    }
    bw.append(NEWLINE);
  }
  bw.close();
}

Fixed version (ground truth):
@Override public void write(final Design design) throws IOException {
  checkNotNull(design,"String_Node_Str");
  final BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(this.out,Globals.DEFAULT_CHARSET));
  checkNotNull(design,"String_Node_Str");
  bw.append(HEADER_SECTION);
  bw.append(NEWLINE);
  bw.append(Eoulsan2DesignReader.DESIGN_FORMAT_VERSION_METADATA_KEY);
  bw.append(EQUAL_SEPARATOR);
  bw.append(Eoulsan2DesignReader.FORMAT_VERSION);
  bw.append(NEWLINE);
  for (  Map.Entry<String,String> e : design.getMetadata().entrySet()) {
    bw.append(e.getKey());
    bw.append(EQUAL_SEPARATOR);
    bw.append(e.getValue());
    bw.append(NEWLINE);
  }
  bw.append(NEWLINE);
  if (!design.getExperiments().isEmpty()) {
    bw.append(EXPERIMENT_SECTION);
    bw.append(NEWLINE);
  }
  for (  Experiment e : design.getExperiments()) {
    final String expId=e.getId();
    bw.append(EXPERIMENT_FIELD_PREFIX);
    bw.append(expId).append(DOT_SEPARATOR);
    bw.append(EXPERIMENT_NAME_SUFFIX);
    bw.append(EQUAL_SEPARATOR);
    bw.append(e.getName());
    bw.append(NEWLINE);
    for (    Map.Entry<String,String> m : e.getMetadata().entrySet()) {
      bw.append(EXPERIMENT_FIELD_PREFIX);
      bw.append(expId);
      bw.append(DOT_SEPARATOR);
      bw.append(m.getKey());
      bw.append(EQUAL_SEPARATOR);
      bw.append(m.getValue());
      bw.append(NEWLINE);
    }
    bw.append(NEWLINE);
  }
  bw.append(COLUMN_SECTION);
  bw.append(NEWLINE);
  bw.append(SAMPLE_ID_FIELDNAME);
  bw.append(TAB_SEPARATOR);
  bw.append(SAMPLE_NAME_FIELDNAME);
  final List<String> sampleMDKeys=getAllSamplesMetadataKeys(design);
  for (  String key : sampleMDKeys) {
    if (SampleMetadata.UUID_KEY.equals(key)) {
      continue;
    }
    bw.append(TAB_SEPARATOR);
    bw.append(key);
  }
  for (  Experiment experiment : design.getExperiments()) {
    final String prefix=EXPERIMENT_FIELD_PREFIX + experiment.getId() + DOT_SEPARATOR;
    final List<String> experimentMDKeys=getExperimentSampleAllMetadataKeys(experiment);
    for (    String key : experimentMDKeys) {
      bw.append(TAB_SEPARATOR);
      bw.append(prefix);
      bw.append(key);
    }
  }
  if (sampleMDKeys.contains(UUID_KEY)) {
    bw.append(TAB_SEPARATOR);
    bw.append(UUID_KEY);
  }
  bw.append(NEWLINE);
  for (  Sample sample : design.getSamples()) {
    bw.append(sample.getId());
    bw.append(TAB_SEPARATOR);
    bw.append(sample.getName());
    final SampleMetadata smd=sample.getMetadata();
    for (    String key : sampleMDKeys) {
      if (UUID_KEY.equals(key)) {
        continue;
      }
      bw.append(TAB_SEPARATOR);
      if (smd.contains(key)) {
        bw.append(smd.get(key));
      }
    }
    for (    Experiment experiment : design.getExperiments()) {
      final ExperimentSampleMetadata expSampleMetadata=experiment.getExperimentSample(sample).getMetadata();
      final List<String> experimentMDKeys=getExperimentSampleAllMetadataKeys(experiment);
      for (      String key : experimentMDKeys) {
        bw.append(TAB_SEPARATOR);
        if (expSampleMetadata.contains(key)) {
          bw.append(expSampleMetadata.get(key));
        }
      }
    }
    if (sampleMDKeys.contains(UUID_KEY)) {
      bw.append(TAB_SEPARATOR);
      bw.append(smd.get(UUID_KEY));
    }
    bw.append(NEWLINE);
  }
  bw.close();
}