Program: 77015
Project: 77015
Buggy source:
/** 
 * Inserts the HTML specified as a string before the start 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>insertBeforeStart(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; /  \ <font style="color: red;">&lt;ul&gt;</font> <b>&lt;div&gt;</b> /    /  \ <font style="color: red;">&lt;li&gt;</font> &lt;p&gt;  &lt;p&gt; </pre> <p>Unlike the <code>insertAfterStart</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 before
 * @param htmlText the string to be parsed and inserted before <code>elem</code>
 * @throws IllegalStateException if an HTMLEditorKit.Parser has notbeen set on the document
 * @since 1.3
 */
public void insertBeforeStart(Element elem,String htmlText) throws BadLocationException, IOException {
  verifyParser();
  if (elem != null) {
    Element parent=elem.getParentElement();
    if (parent != null) {
      insertHTML(parent,elem.getStartOffset(),htmlText,false);
    }
  }
}

Fixed version (ground truth):
/** 
 * Inserts the HTML specified as a string before the start 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>insertBeforeStart(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; /  \ <font style="color: red;">&lt;ul&gt;</font> <b>&lt;div&gt;</b> /    /  \ <font style="color: red;">&lt;li&gt;</font> &lt;p&gt;  &lt;p&gt; </pre> <p>Unlike the <code>insertAfterStart</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 before
 * @param htmlText the string to be parsed and inserted before <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 insertBeforeStart(Element elem,String htmlText) throws BadLocationException, IOException {
  verifyParser();
  if (elem != null) {
    Element parent=elem.getParentElement();
    if (parent != null) {
      insertHTML(parent,elem.getStartOffset(),htmlText,false);
    }
  }
}