Program: 75924
Project: 75924
Buggy source:
/** 
 * If the specified effigy already contains a tableau named "textTableau", then return that tableau; otherwise, create a new instance of TextEditorTableau in the specified effigy, and name it "textTableau" and return that tableau. If the specified effigy is not an instance of TextEffigy, but contains an instance of TextEffigy, then open a tableau for that effigy.  If it is a PtolemyEffigy, then create a text effigy with the MoML representation of the model. Finally, if is not a TextEffigy or a PtolemyEffigy, and it does not contain a TextEffigy, then attempt to open its URL and display its date by creating a text effigy, which will then be contained by the specified effigy. If all of this fails, then do not create a tableau and return null. It is the responsibility of callers of this method to check the return value and call show().
 * @param effigy The effigy.
 * @return A text editor tableau, or null if one cannot befound or created.
 * @exception Exception If the factory should be able to create atableau for the effigy, but something goes wrong.
 */
public Tableau createTableau(Effigy effigy) throws Exception {
  if (effigy instanceof TextEffigy) {
    TextEditorTableau tableau=(TextEditorTableau)effigy.getEntity("String_Node_Str");
    if (tableau == null) {
      tableau=new TextEditorTableau((TextEffigy)effigy,"String_Node_Str");
    }
    tableau.setEditable(effigy.isModifiable());
    return tableau;
  }
 else {
    List effigies=effigy.entityList(TextEffigy.class);
    if (effigies.size() > 0) {
      TextEffigy textEffigy=(TextEffigy)effigies.get(0);
      return createTableau(textEffigy);
    }
 else {
      URL url=effigy.url.getURL();
      TextEffigy textEffigy;
      if (effigy instanceof PtolemyEffigy) {
        String moml=((PtolemyEffigy)effigy).getModel().exportMoML();
        textEffigy=TextEffigy.newTextEffigy(effigy,moml);
      }
 else {
        textEffigy=TextEffigy.newTextEffigy(effigy,url,url);
      }
      TextEditorTableau textTableau=(TextEditorTableau)createTableau(textEffigy);
      textTableau.setEditable(false);
      if (url != null) {
        textEffigy.identifier.setExpression(url.toExternalForm());
      }
      return textTableau;
    }
  }
}

Fixed version (ground truth):
/** 
 * If the specified effigy is a TextEffigy and it already contains a tableau named "textTableau", then return that tableau; otherwise, create a new instance of TextEditorTableau in the specified effigy, and name it "textTableau" and return that tableau. If the specified effigy is not an instance of TextEffigy, but contains an instance of TextEffigy, then open a tableau for that effigy.  If it is a PtolemyEffigy, then create a text effigy with the MoML representation of the model. Finally, if is not a TextEffigy or a PtolemyEffigy, and it does not contain a TextEffigy, then attempt to open its URL and display its date by creating a text effigy, which will then be contained by the specified effigy. If all of this fails, then do not create a tableau and return null. It is the responsibility of callers of this method to check the return value and call show().
 * @param effigy The effigy.
 * @return A text editor tableau, or null if one cannot befound or created.
 * @exception Exception If the factory should be able to create atableau for the effigy, but something goes wrong.
 */
public Tableau createTableau(Effigy effigy) throws Exception {
  if (effigy instanceof TextEffigy) {
    TextEditorTableau tableau=(TextEditorTableau)effigy.getEntity("String_Node_Str");
    if (tableau == null) {
      tableau=new TextEditorTableau((TextEffigy)effigy,"String_Node_Str");
    }
    tableau.setEditable(effigy.isModifiable());
    return tableau;
  }
 else {
    Iterator effigies=effigy.entityList(TextEffigy.class).iterator();
    while (effigies.hasNext()) {
      TextEffigy textEffigy=(TextEffigy)effigies.next();
      if (textEffigy.getName().equals("String_Node_Str")) {
        return createTableau(textEffigy);
      }
    }
    URL url=effigy.url.getURL();
    TextEffigy textEffigy;
    if (effigy instanceof PtolemyEffigy) {
      String moml=((PtolemyEffigy)effigy).getModel().exportMoML();
      textEffigy=TextEffigy.newTextEffigy(effigy,moml);
      textEffigy.setModifiable(false);
      textEffigy.setName("String_Node_Str");
    }
 else {
      textEffigy=TextEffigy.newTextEffigy(effigy,url,url);
      textEffigy.setName("String_Node_Str");
    }
    TextEditorTableau textTableau=(TextEditorTableau)createTableau(textEffigy);
    if (url != null) {
      textEffigy.identifier.setExpression(url.toExternalForm());
    }
    return textTableau;
  }
}