Program: 178548
Project: 178548
Buggy source:
/** 
 * Parse a TAP line.
 * @param tapLine TAP line
 */
public void parseLine(String tapLine){
  TapElement tapElement=TapElementFactory.createTapElement(tapLine);
  if (tapElement == null || state.isInYaml()) {
    String trimmedLine=tapLine.trim();
    Text text=TapElementFactory.createTextElement(tapLine);
    if (state.isInYaml()) {
      boolean yamlEndMarkReached=trimmedLine.equals("String_Node_Str") && (tapLine.equals(state.getYamlIndentation() + "String_Node_Str") || text.getIndentation() < state.getYamlIndentation().length());
      if (yamlEndMarkReached) {
        state.setInYaml(false);
        parseDiagnostics();
      }
 else {
        state.getDiagnosticBuffer().append(tapLine);
        state.getDiagnosticBuffer().append('\n');
      }
    }
 else {
      if (trimmedLine.equals("String_Node_Str")) {
        if (text.getIndentation() < baseIndentation) {
          throw new ParserException("String_Node_Str" + "String_Node_Str" + tapLine);
        }
        state.setInYaml(true);
        state.setYamlIndentation(text.getIndentationString());
      }
 else {
        state.getTestSet().getTapLines().add(text);
        state.setLastParsedElement(text);
      }
    }
    return;
  }
  int indentation=tapElement.getIndentation();
  if (indentation < baseIndentation) {
    baseIndentation=indentation;
  }
  if (indentation != state.getIndentationLevel()) {
    if (indentation > state.getIndentationLevel()) {
      StreamStatus parentState=state;
      pushState(indentation);
      TapElement lastParentElement=parentState.getLastParsedElement();
      if (lastParentElement instanceof TestResult) {
        final TestResult lastTestResult=(TestResult)lastParentElement;
        if (lastTestResult.getSubtest() == null) {
          lastTestResult.setSubtest(state.getTestSet());
          state.attachedToParent=true;
        }
      }
    }
 else {
      do {
        StreamStatus prevState=state;
        state=states.pop();
        if (!prevState.attachedToParent) {
          state.looseSubtests=prevState.getTestSet();
        }
      }
 while (indentation < state.getIndentationLevel());
    }
  }
  if (tapElement instanceof Header) {
    if (state.getTestSet().getHeader() != null) {
      throw new ParserException("String_Node_Str");
    }
    if (!state.isFirstLine()) {
      throw new ParserException("String_Node_Str" + "String_Node_Str");
    }
    state.getTestSet().setHeader((Header)tapElement);
  }
 else   if (tapElement instanceof Plan) {
    if (state.getTestSet().getPlan() != null) {
      throw new ParserException("String_Node_Str");
    }
    if (state.getTestSet().getTestResults().size() <= 0 && state.getTestSet().getBailOuts().size() <= 0) {
      state.setPlanBeforeTestResult(true);
    }
    state.getTestSet().setPlan((Plan)tapElement);
  }
 else   if (tapElement instanceof TestResult) {
    parseDiagnostics();
    final TestResult testResult=(TestResult)tapElement;
    if (testResult.getTestNumber() == 0) {
      if (state.getTestSet().getPlan() != null && state.isPlanBeforeTestResult() == false) {
        return;
      }
      if (state.getTestSet().getPlan() != null && state.getTestSet().getPlan().getLastTestNumber() == state.getTestSet().getTestResults().size()) {
        return;
      }
      testResult.setTestNumber(state.getTestSet().getNextTestNumber());
    }
    state.getTestSet().addTestResult(testResult);
    if (state.looseSubtests != null) {
      testResult.setSubtest(state.looseSubtests);
      state.looseSubtests=null;
    }
  }
 else   if (tapElement instanceof Footer) {
    state.getTestSet().setFooter((Footer)tapElement);
  }
 else   if (tapElement instanceof BailOut) {
    state.getTestSet().addBailOut((BailOut)tapElement);
  }
 else   if (tapElement instanceof Comment) {
    final Comment comment=(Comment)tapElement;
    state.getTestSet().addComment(comment);
    if (state.getLastParsedElement() instanceof TestResult) {
      ((TestResult)state.getLastParsedElement()).addComment(comment);
    }
  }
  state.setFirstLine(false);
  if (!(tapElement instanceof Comment)) {
    state.setLastParsedElement(tapElement);
  }
}

Fixed version (ground truth):
/** 
 * Parse a TAP line.
 * @param tapLine TAP line
 */
public void parseLine(String tapLine){
  TapElement tapElement=TapElementFactory.createTapElement(tapLine);
  if (tapElement == null || state.isInYaml()) {
    String trimmedLine=tapLine.trim();
    Text text=TapElementFactory.createTextElement(tapLine);
    if (state.isInYaml()) {
      boolean yamlEndMarkReached=trimmedLine.equals("String_Node_Str") && (tapLine.equals(state.getYamlIndentation() + "String_Node_Str") || text.getIndentation() < state.getYamlIndentation().length());
      if (yamlEndMarkReached) {
        state.setInYaml(false);
        parseDiagnostics();
      }
 else {
        state.getDiagnosticBuffer().append(tapLine);
        state.getDiagnosticBuffer().append('\n');
      }
    }
 else {
      if (trimmedLine.equals("String_Node_Str")) {
        if (text.getIndentation() < baseIndentation) {
          throw new ParserException("String_Node_Str" + "String_Node_Str" + tapLine);
        }
        state.setInYaml(true);
        state.setYamlIndentation(text.getIndentationString());
      }
 else {
        state.getTestSet().getTapLines().add(text);
        state.setLastParsedElement(text);
      }
    }
    return;
  }
  int indentation=tapElement.getIndentation();
  if (indentation < baseIndentation) {
    baseIndentation=indentation;
  }
  if (indentation != state.getIndentationLevel()) {
    if (indentation > state.getIndentationLevel()) {
      StreamStatus parentState=state;
      pushState(indentation);
      TapElement lastParentElement=parentState.getLastParsedElement();
      if (lastParentElement instanceof TestResult) {
        final TestResult lastTestResult=(TestResult)lastParentElement;
        if (lastTestResult.getSubtest() == null) {
          lastTestResult.setSubtest(state.getTestSet());
          state.attachedToParent=true;
        }
      }
    }
 else {
      do {
        StreamStatus prevState=state;
        state=states.pop();
        if (!prevState.attachedToParent) {
          state.looseSubtests=prevState.getTestSet();
        }
      }
 while (indentation < state.getIndentationLevel());
    }
  }
  if (tapElement instanceof Header) {
    if (state.getTestSet().getHeader() != null) {
      throw new ParserException("String_Node_Str");
    }
    if (!state.isFirstLine()) {
      throw new ParserException("String_Node_Str" + "String_Node_Str");
    }
    state.getTestSet().setHeader((Header)tapElement);
  }
 else   if (tapElement instanceof Plan) {
    Plan currentPlan=(Plan)tapElement;
    if (state.getTestSet().getPlan() != null) {
      if (currentPlan.getInitialTestNumber() != 1 || currentPlan.getLastTestNumber() != 0) {
        throw new ParserException("String_Node_Str");
      }
    }
 else {
      state.getTestSet().setPlan(currentPlan);
    }
    if (state.getTestSet().getTestResults().size() <= 0 && state.getTestSet().getBailOuts().size() <= 0) {
      state.setPlanBeforeTestResult(true);
    }
  }
 else   if (tapElement instanceof TestResult) {
    parseDiagnostics();
    final TestResult testResult=(TestResult)tapElement;
    if (testResult.getTestNumber() == 0) {
      if (state.getTestSet().getPlan() != null && state.isPlanBeforeTestResult() == false) {
        return;
      }
      if (state.getTestSet().getPlan() != null && state.getTestSet().getPlan().getLastTestNumber() == state.getTestSet().getTestResults().size()) {
        return;
      }
      testResult.setTestNumber(state.getTestSet().getNextTestNumber());
    }
    state.getTestSet().addTestResult(testResult);
    if (state.looseSubtests != null) {
      testResult.setSubtest(state.looseSubtests);
      state.looseSubtests=null;
    }
  }
 else   if (tapElement instanceof Footer) {
    state.getTestSet().setFooter((Footer)tapElement);
  }
 else   if (tapElement instanceof BailOut) {
    state.getTestSet().addBailOut((BailOut)tapElement);
  }
 else   if (tapElement instanceof Comment) {
    final Comment comment=(Comment)tapElement;
    state.getTestSet().addComment(comment);
    if (state.getLastParsedElement() instanceof TestResult) {
      ((TestResult)state.getLastParsedElement()).addComment(comment);
    }
  }
  state.setFirstLine(false);
  if (!(tapElement instanceof Comment)) {
    state.setLastParsedElement(tapElement);
  }
}