Program: 77017
Project: 77017
Buggy source:
/** 
 * Inserts the HTML specified as a string after the the end of the given element. <p>Consider the following structure (the <code>elem</code> parameter is <b>in bold</b>).</p> <pre> &lt;body&gt; | <b>&lt;div&gt;</b> /  \ &lt;p&gt;   &lt;p&gt; </pre> <p>Invoking <code>insertAfterEnd(elem, "&lt;ul&gt;&lt;li&gt;")</code> results in the following structure (new elements are <font style="color: red;">in red</font>).</p> <pre> &lt;body&gt; /  \ <b>&lt;div&gt;</b> <font style="color: red;">&lt;ul&gt;</font> / \    \ &lt;p&gt; &lt;p&gt;  <font style="color: red;">&lt;li&gt;</font> </pre> <p>Unlike the <code>insertBeforeEnd</code> method, new elements become <em>siblings</em> of the specified element, not children.</p> <p>If either <code>elem</code> or <code>htmlText</code> parameter is <code>null</code>, no changes are made to the document.</p> <p>For this to work correctly, the document must have an <code>HTMLEditorKit.Parser</code> set. This will be the case if the document was created from an HTMLEditorKit via the <code>createDefaultDocument</code> method.</p>
 * @param elem the element the content is inserted after
 * @param htmlText the string to be parsed and inserted after <code>elem</code>
 * @throws IllegalStateException if an HTMLEditorKit.Parser has notbeen set on the document
 * @since 1.3
 */
public void insertAfterEnd(Element elem,String htmlText) throws BadLocationException, IOException {
  verifyParser();
  if (elem != null) {
    Element parent=elem.getParentElement();
    if (parent != null) {
      int offset=elem.getEndOffset();
      if (offset > getLength()) {
        offset--;
      }
 else       if (elem.isLeaf() && getText(offset - 1,1).charAt(0) == NEWLINE[0]) {
        offset--;
      }
      insertHTML(parent,offset,htmlText,false);
    }
  }
}

Fixed version (ground truth):
/** 
 * Inserts the HTML specified as a string after the the end of the given element. <p>Consider the following structure (the <code>elem</code> parameter is <b>in bold</b>).</p> <pre> &lt;body&gt; | <b>&lt;div&gt;</b> /  \ &lt;p&gt;   &lt;p&gt; </pre> <p>Invoking <code>insertAfterEnd(elem, "&lt;ul&gt;&lt;li&gt;")</code> results in the following structure (new elements are <font style="color: red;">in red</font>).</p> <pre> &lt;body&gt; /  \ <b>&lt;div&gt;</b> <font style="color: red;">&lt;ul&gt;</font> / \    \ &lt;p&gt; &lt;p&gt;  <font style="color: red;">&lt;li&gt;</font> </pre> <p>Unlike the <code>insertBeforeEnd</code> method, new elements become <em>siblings</em> of the specified element, not children.</p> <p>If either <code>elem</code> or <code>htmlText</code> parameter is <code>null</code>, no changes are made to the document.</p> <p>For this to work correctly, the document must have an <code>HTMLEditorKit.Parser</code> set. This will be the case if the document was created from an HTMLEditorKit via the <code>createDefaultDocument</code> method.</p>
 * @param elem the element the content is inserted after
 * @param htmlText the string to be parsed and inserted after <code>elem</code>
 * @throws IllegalStateException if an HTMLEditorKit.Parser has notbeen set on the document
 * @throws BadLocationException if insertion is impossible because ofa structural issue
 * @throws IOException if an I/O exception occurs
 * @since 1.3
 */
public void insertAfterEnd(Element elem,String htmlText) throws BadLocationException, IOException {
  verifyParser();
  if (elem != null) {
    Element parent=elem.getParentElement();
    if (parent != null) {
      int offset=elem.getEndOffset();
      if (offset > getLength()) {
        offset--;
      }
 else       if (elem.isLeaf() && getText(offset - 1,1).charAt(0) == NEWLINE[0]) {
        offset--;
      }
      insertHTML(parent,offset,htmlText,false);
    }
  }
}