Program: 73177
Project: 73177
Buggy source:
/** 
 * Create the first tableau for the given effigy, using the tableau factory.  This is called after an effigy is first opened, or when a new effigy is created.  If the method fails to create a tableau, then it removes the effigy from the directory. This prevents us from having lingering effigies that have no user interface.
 * @return A tableau for the specified effigy, or null if nonecan be opened.
 * @param effigy The effigy for which to create a tableau.
 */
public Tableau createPrimaryTableau(final Effigy effigy){
  TableauFactory factory=null;
  if (effigy instanceof PtolemyEffigy) {
    NamedObj model=((PtolemyEffigy)effigy).getModel();
    if (model != null) {
      Iterator factories=model.attributeList(TableauFactory.class).iterator();
      while (factories.hasNext() && (factory == null)) {
        factory=(TableauFactory)factories.next();
        try {
          Tableau tableau=factory.createTableau(effigy);
          if (tableau != null) {
            if (effigy.masterEffigy() == effigy) {
              tableau.setMaster(true);
            }
            tableau.setEditable(effigy.isModifiable());
            tableau.show();
            return tableau;
          }
        }
 catch (        Exception ex) {
          factory=null;
        }
      }
    }
  }
  factory=(TableauFactory)getAttribute("String_Node_Str");
  if (factory != null) {
    try {
      Tableau tableau=factory.createTableau(effigy);
      if (tableau == null) {
        throw new Exception("String_Node_Str");
      }
      if (effigy.getContainer() instanceof ModelDirectory) {
        tableau.setMaster(true);
      }
      tableau.setEditable(effigy.isModifiable());
      tableau.show();
      return tableau;
    }
 catch (    Exception ex) {
      boolean calledMessageHandler=false;
      try {
        if (effigy.getContainer() instanceof ModelDirectory) {
          if (effigy instanceof PtolemyEffigy) {
            if (((PtolemyEffigy)effigy).getModel() != null) {
              MessageHandler.error("String_Node_Str" + ((PtolemyEffigy)effigy).getModel().getFullName(),ex);
            }
 else {
              MessageHandler.error("String_Node_Str" + effigy,ex);
            }
            calledMessageHandler=true;
          }
 else {
            MessageHandler.error("String_Node_Str" + effigy.identifier.getExpression(),ex);
            calledMessageHandler=true;
          }
        }
        effigy.setContainer(null);
      }
 catch (      Throwable throwable) {
        calledMessageHandler=false;
        throw new InternalErrorException(this,throwable,null);
      }
      if (effigy instanceof PtolemyEffigy) {
        NamedObj object=((PtolemyEffigy)effigy).getModel();
        String filename=StringUtilities.objectToSourceFileName(object);
        try {
          URL toRead=getClass().getClassLoader().getResource(filename);
          if (toRead == null) {
            toRead=ClassUtilities.sourceResource(filename);
          }
          if (toRead != null) {
            return openModel(null,toRead,toRead.toExternalForm());
          }
 else {
            MessageHandler.error("String_Node_Str" + object.getFullName());
          }
        }
 catch (        Exception exception) {
          MessageHandler.error("String_Node_Str" + object.getFullName(),exception);
        }
      }
      if (!calledMessageHandler) {
        MessageHandler.error("String_Node_Str" + effigy.identifier.getExpression(),ex);
      }
    }
  }
  return null;
}

Fixed version (ground truth):
/** 
 * Create the first tableau for the given effigy, using the tableau factory.  This is called after an effigy is first opened, or when a new effigy is created.  If the method fails to create a tableau, then it removes the effigy from the directory. This prevents us from having lingering effigies that have no user interface.
 * @return A tableau for the specified effigy, or null if nonecan be opened.
 * @param effigy The effigy for which to create a tableau.
 */
public Tableau createPrimaryTableau(final Effigy effigy){
  TableauFactory factory=null;
  if (effigy instanceof PtolemyEffigy) {
    NamedObj model=((PtolemyEffigy)effigy).getModel();
    if (model != null) {
      Iterator factories=model.attributeList(TableauFactory.class).iterator();
      while (factories.hasNext() && (factory == null)) {
        factory=(TableauFactory)factories.next();
        try {
          Tableau tableau=factory.createTableau(effigy);
          if (tableau != null) {
            if (effigy.masterEffigy() == effigy) {
              tableau.setMaster(true);
            }
            tableau.setEditable(effigy.isModifiable());
            tableau.show();
            return tableau;
          }
        }
 catch (        Exception ex) {
          factory=null;
        }
      }
    }
  }
  factory=(TableauFactory)getAttribute("String_Node_Str");
  if (factory != null) {
    try {
      Tableau tableau=factory.createTableau(effigy);
      if (tableau == null) {
        throw new Exception("String_Node_Str");
      }
      if (effigy.getContainer() instanceof ModelDirectory) {
        tableau.setMaster(true);
      }
      tableau.setEditable(effigy.isModifiable());
      tableau.show();
      return tableau;
    }
 catch (    Exception ex) {
      boolean calledMessageHandler=false;
      try {
        if (effigy.getContainer() instanceof ModelDirectory) {
          if (effigy instanceof PtolemyEffigy) {
            if (((PtolemyEffigy)effigy).getModel() != null) {
              MessageHandler.error("String_Node_Str" + ((PtolemyEffigy)effigy).getModel().getFullName(),ex);
            }
 else {
              MessageHandler.error("String_Node_Str" + effigy,ex);
            }
            calledMessageHandler=true;
          }
 else {
            MessageHandler.error("String_Node_Str" + effigy.identifier.getExpression(),ex);
            calledMessageHandler=true;
          }
        }
        effigy.setContainer(null);
      }
 catch (      Throwable throwable) {
        calledMessageHandler=false;
        throw new InternalErrorException(this,throwable,null);
      }
      if (effigy instanceof PtolemyEffigy) {
        NamedObj object=((PtolemyEffigy)effigy).getModel();
        String filename=StringUtilities.objectToSourceFileName(object);
        try {
          URL toRead=getClass().getClassLoader().getResource(filename);
          if (toRead == null) {
            toRead=ClassUtilities.sourceResource(filename);
            System.out.println("String_Node_Str" + filename + "String_Node_Str"+ toRead);
          }
          if (toRead != null) {
            return openModel(null,toRead,toRead.toExternalForm());
          }
 else {
            MessageHandler.error("String_Node_Str" + object.getFullName());
          }
        }
 catch (        Exception exception) {
          MessageHandler.error("String_Node_Str" + object.getFullName(),exception);
        }
      }
      if (!calledMessageHandler) {
        MessageHandler.error("String_Node_Str" + effigy.identifier.getExpression(),ex);
      }
    }
  }
  return null;
}