nus-yam/ex-repair huggingface dataset:
Program: 75042
Project: 75042
Buggy source:
public static void createFolders(IContainer container) throws CoreException {
  if (!container.exists()) {
    if (container instanceof IFolder) {
      createFolders(container.getParent());
      ((IFolder)container).create(true,false,null);
    }
  }
}

Fixed version (ground truth):
public static void createFolders(IContainer container) throws CoreException {
  if (!container.exists()) {
    if (container instanceof IFolder) {
      createFolders(container.getParent());
      ((IFolder)container).create(true,true,null);
    }
  }
}
Program: 75043
Project: 75043
Buggy source:
public static void closeConsole(){
  IConsoleManager manager=ConsolePlugin.getDefault().getConsoleManager();
  OutputConsole console=EclipsePlugin.getDefault().getConsole();
  if (console != null) {
    manager.removeConsoles(new IConsole[]{console});
  }
}

Fixed version (ground truth):
public static void closeConsole(){
  IConsoleManager manager=ConsolePlugin.getDefault().getConsoleManager();
  OutputConsole console=EclipsePlugin.getDefault().getConsole();
  if (console != null)   manager.removeConsoles(new IConsole[]{console});
}
Program: 75045
Project: 75045
Buggy source:
public Control createContents(Composite parent){
  _toolkit=new FormToolkit(getShell().getDisplay());
  _form=_toolkit.createScrolledForm(parent);
  _form.setLayoutData(new GridData(GridData.FILL_BOTH));
  _form.setBackground(null);
  _form.getBody().setLayout(new TableWrapLayout());
  _createSection1();
  _createSection2();
  _createSection3();
  _createSection4();
  _createSection5();
  initialize();
  checkState();
  return parent;
}

Fixed version (ground truth):
public Control createContents(Composite parent){
  _toolkit=new FormToolkit(getShell().getDisplay());
  _form=_toolkit.createScrolledForm(parent);
  _form.setLayoutData(new GridData(GridData.FILL_BOTH));
  _form.setBackground(parent.getBackground());
  _form.getBody().setLayout(new TableWrapLayout());
  _createSection1();
  _createSection2();
  _createSection3();
  _createSection4();
  _createSection5();
  initialize();
  checkState();
  return parent;
}
Program: 75046
Project: 75046
Buggy source:
public void initializeDefaultPreferences(){
  IPreferenceStore store=EclipsePlugin.getDefault().getPreferenceStore();
  IProject ptIIProject=ResourcesPlugin.getWorkspace().getRoot().getProject("String_Node_Str");
  if (ptIIProject.exists()) {
    store.setDefault(PreferenceConstants.PTII,ptIIProject.getLocation().toOSString());
    IFile sourceList=ptIIProject.getFile("String_Node_Str");
    if (sourceList.exists())     store.setDefault(PreferenceConstants.BACKTRACK_SOURCE_LIST,sourceList.getLocation().toOSString());
 else     store.setDefault(PreferenceConstants.BACKTRACK_SOURCE_LIST,"String_Node_Str");
    store.setDefault(PreferenceConstants.BACKTRACK_ROOT,ptIIProject.getLocation().toOSString());
    store.setDefault(PreferenceConstants.BACKTRACK_GENERATE_CONFIGURATION,true);
    IFile configuration=ptIIProject.getFile("String_Node_Str");
    store.setDefault(PreferenceConstants.BACKTRACK_CONFIGURATION,configuration.getLocation().toOSString());
  }
 else {
    store.setDefault(PreferenceConstants.PTII,"String_Node_Str");
    store.setDefault(PreferenceConstants.BACKTRACK_SOURCE_LIST,"String_Node_Str");
    store.setDefault(PreferenceConstants.BACKTRACK_ROOT,"String_Node_Str");
    store.setDefault(PreferenceConstants.BACKTRACK_GENERATE_CONFIGURATION,false);
    store.setDefault(PreferenceConstants.BACKTRACK_CONFIGURATION,"String_Node_Str");
  }
  store.setDefault(PreferenceConstants.BACKTRACK_PREFIX,"String_Node_Str");
  store.setDefault(PreferenceConstants.BACKTRACK_OVERWRITE,false);
}

Fixed version (ground truth):
public void initializeDefaultPreferences(){
  IPreferenceStore store=EclipsePlugin.getDefault().getPreferenceStore();
  IProject ptIIProject=ResourcesPlugin.getWorkspace().getRoot().getProject("String_Node_Str");
  if (ptIIProject.exists()) {
    store.setDefault(PreferenceConstants.PTII,ptIIProject.getFullPath().toOSString());
    IFile sourceList=ptIIProject.getFile("String_Node_Str");
    if (sourceList.exists())     store.setDefault(PreferenceConstants.BACKTRACK_SOURCE_LIST,sourceList.getLocation().toOSString());
 else     store.setDefault(PreferenceConstants.BACKTRACK_SOURCE_LIST,"String_Node_Str");
    store.setDefault(PreferenceConstants.BACKTRACK_ROOT,ptIIProject.getFullPath().toOSString());
    store.setDefault(PreferenceConstants.BACKTRACK_GENERATE_CONFIGURATION,true);
    IFile configuration=ptIIProject.getFile("String_Node_Str");
    store.setDefault(PreferenceConstants.BACKTRACK_CONFIGURATION,configuration.getLocation().toOSString());
  }
 else {
    store.setDefault(PreferenceConstants.PTII,"String_Node_Str");
    store.setDefault(PreferenceConstants.BACKTRACK_SOURCE_LIST,"String_Node_Str");
    store.setDefault(PreferenceConstants.BACKTRACK_ROOT,"String_Node_Str");
    store.setDefault(PreferenceConstants.BACKTRACK_GENERATE_CONFIGURATION,false);
    store.setDefault(PreferenceConstants.BACKTRACK_CONFIGURATION,"String_Node_Str");
  }
  store.setDefault(PreferenceConstants.BACKTRACK_PREFIX,"String_Node_Str");
  store.setDefault(PreferenceConstants.BACKTRACK_OVERWRITE,false);
}
Program: 75047
Project: 75047
Buggy source:
/** 
 * Creates the field editors. Field editors are abstractions of the common GUI blocks needed to manipulate various types of preferences. Each field editor knows how to save and restore itself.
 */
public void createFieldEditors(){
  _setDefault();
  Composite parent=getFieldEditorParent();
  addField(new DirectoryFieldEditor(PreferenceConstants.PTII,"String_Node_Str",getFieldEditorParent()){
    protected void fireValueChanged(    String property,    Object oldValue,    Object newValue){
      if (property == VALUE && isValid()) {
        String PTII=getStringValue();
        IPreferenceStore store=EclipsePlugin.getDefault().getPreferenceStore();
        File sourceList=new File(PTII + "String_Node_Str");
        if (sourceList.exists())         store.setValue(PreferenceConstants.BACKTRACK_SOURCE_LIST,sourceList.getPath());
      }
      super.fireValueChanged(property,oldValue,newValue);
    }
  }
);
  Label space=new Label(parent,0);
  GridData gridData=new GridData();
  gridData.horizontalSpan=3;
  gridData.grabExcessVerticalSpace=true;
  space.setLayoutData(gridData);
  Label logo=new Label(parent,0);
  gridData=new GridData();
  gridData.horizontalSpan=3;
  gridData.horizontalAlignment=SWT.CENTER;
  logo.setLayoutData(gridData);
  ImageDescriptor descriptor=ImageDescriptor.createFromFile(EclipsePlugin.class,"String_Node_Str");
  logo.setImage(descriptor.createImage());
}

Fixed version (ground truth):
/** 
 * Creates the field editors. Field editors are abstractions of the common GUI blocks needed to manipulate various types of preferences. Each field editor knows how to save and restore itself.
 */
public void createFieldEditors(){
  Composite parent=getFieldEditorParent();
  DirectoryFieldEditor directoryFieldEditor=new DirectoryFieldEditor(PreferenceConstants.PTII,"String_Node_Str",getFieldEditorParent()){
    protected void fireValueChanged(    String property,    Object oldValue,    Object newValue){
      if (property == VALUE && isValid()) {
        String PTII=getStringValue();
        IPreferenceStore store=EclipsePlugin.getDefault().getPreferenceStore();
        File sourceList=new File(PTII + "String_Node_Str");
        if (sourceList.exists())         store.setValue(PreferenceConstants.BACKTRACK_SOURCE_LIST,sourceList.getPath());
      }
      super.fireValueChanged(property,oldValue,newValue);
    }
  }
;
  addField(directoryFieldEditor);
  Label space=new Label(parent,0);
  GridData gridData=new GridData();
  gridData.horizontalSpan=3;
  gridData.grabExcessVerticalSpace=true;
  space.setLayoutData(gridData);
  Label logo=new Label(parent,0);
  gridData=new GridData();
  gridData.horizontalSpan=3;
  gridData.horizontalAlignment=SWT.CENTER;
  logo.setLayoutData(gridData);
  ImageDescriptor descriptor=ImageDescriptor.createFromFile(EclipsePlugin.class,"String_Node_Str");
  logo.setImage(descriptor.createImage());
}
Program: 75051
Project: 75051
Buggy source:
/** 
 * Find the first appearance of any of the given characters in a string.
 * @param s The string.
 * @param chars The array of characters.
 * @param startPos The starting position from which the search begins.
 * @return The index of the first appearance of any of the givencharacters in the string, or -1 if none of them is found.
 */
public static int indexOf(String s,char[] chars,int startPos){
  int pos=-1;
  for (int i=0; i < chars.length; i++) {
    int newPos=s.indexOf(chars[i],startPos);
    if (pos == -1 || newPos < pos)     pos=newPos;
  }
  return pos;
}

Fixed version (ground truth):
/** 
 * Find the first appearance of any of the given characters in a string.
 * @param s The string.
 * @param chars The array of characters.
 * @param startPos The starting position from which the search begins.
 * @return The index of the first appearance of any of the givencharacters in the string, or -1 if none of them is found.
 */
public static int indexOf(String s,char[] chars,int startPos){
  int pos=-1;
  for (int i=0; i < chars.length; i++) {
    int newPos=s.indexOf(chars[i],startPos);
    if (newPos != -1 && (pos == -1 || newPos < pos))     pos=newPos;
  }
  return pos;
}
Program: 75052
Project: 75052
Buggy source:
protected static void _outputConfig() throws Exception {
  if (_configName != null) {
    SourceOutputStream stream=SourceOutputStream.getStream(_configName,_overwrite);
    Set classSet=new HashSet();
    classSet.addAll(_classes);
    ConfigParser parser=new ConfigParser();
    parser.parseConfigFile(ConfigParser.DEFAULT_SYSTEM_ID,classSet);
    if (_prefix != null && _prefix.length() > 0)     parser.addPackagePrefix(_prefix,classSet);
    OutputStreamWriter writer=new OutputStreamWriter(stream);
    XmlOutput.outputXmlTree(parser.getTree(),writer);
    writer.close();
  }
}

Fixed version (ground truth):
protected static void _outputConfig() throws Exception {
  if (_configName != null) {
    SourceOutputStream stream=SourceOutputStream.getStream(_configName,_overwrite);
    Set classSet=new HashSet();
    classSet.addAll(_classes);
    ConfigParser parser=new ConfigParser();
    parser.addExcludedFile(new File(_configName).getCanonicalPath());
    parser.parseConfigFile(ConfigParser.DEFAULT_SYSTEM_ID,classSet);
    if (_prefix != null && _prefix.length() > 0)     parser.addPackagePrefix(_prefix,classSet);
    OutputStreamWriter writer=new OutputStreamWriter(stream);
    XmlOutput.outputXmlTree(parser.getTree(),writer);
    writer.close();
  }
}
Program: 75053
Project: 75053
Buggy source:
public void parseConfigFile(String fileName,Set includedClasses) throws Exception {
  XmlParser parser=new XmlParser();
  BufferedReader br=new BufferedReader(new FileReader(fileName));
  ConfigXmlHandler handler=new ConfigXmlHandler(_xmlTree,fileName,includedClasses);
  parser.setHandler(handler);
  parser.parse(fileName,null,br);
  _xmlTree.setElementName("String_Node_Str");
  _xmlTree.setAttribute("String_Node_Str","String_Node_Str");
  _xmlTree.setAttribute("String_Node_Str","String_Node_Str");
}

Fixed version (ground truth):
public void parseConfigFile(String fileName,Set includedClasses,boolean backtrackingElement) throws Exception {
  XmlParser parser=new XmlParser();
  BufferedReader br=new BufferedReader(new FileReader(fileName));
  ConfigXmlHandler handler=new ConfigXmlHandler(_xmlTree,fileName,includedClasses);
  handler.addExcludedFiles(_excludedFiles);
  parser.setHandler(handler);
  parser.parse(fileName,null,br);
  if (backtrackingElement) {
    _xmlTree.setElementName("String_Node_Str");
    _xmlTree.setAttribute("String_Node_Str","String_Node_Str");
    _xmlTree.setAttribute("String_Node_Str","String_Node_Str");
  }
}
Program: 75054
Project: 75054
Buggy source:
public void startElement(String elname) throws Exception {
  super.startElement(elname);
  if (elname.equals("String_Node_Str")) {
    String fileName=currentTree.getAttribute("String_Node_Str");
    try {
      String newName=PTOLEMY_PATH + fileName;
      File newFile=new File(newName);
      if (!newFile.exists()) {
        File oldFile=new File(systemId);
        newName=oldFile.getParent() + "String_Node_Str" + fileName;
      }
      ConfigParser subparser=new ConfigParser(currentTree);
      subparser.parseConfigFile(newName,includedClasses);
    }
 catch (    Exception e) {
    }
  }
}

Fixed version (ground truth):
public void startElement(String elname) throws Exception {
  super.startElement(elname);
  if (elname.equals("String_Node_Str")) {
    String fileName=currentTree.getAttribute("String_Node_Str");
    try {
      String newName=PathFinder.getPtolemyPath() + fileName;
      File newFile=new File(newName);
      if (!newFile.exists()) {
        File oldFile=new File(systemId);
        newName=oldFile.getParent() + "String_Node_Str" + fileName;
        newFile=new File(newName);
      }
      String canonicalPath=newFile.getCanonicalPath();
      if (!_excludedFiles.contains(canonicalPath)) {
        ConfigParser subparser=new ConfigParser(currentTree);
        subparser.addExcludedFiles(_excludedFiles);
        subparser.parseConfigFile(newName,includedClasses,false);
      }
    }
 catch (    Exception e) {
    }
  }
}
Program: 75055
Project: 75055
Buggy source:
public void processingInstruction(String target,String data) throws Exception {
  if (target.equals("String_Node_Str")) {
    StringReader dataReader=new StringReader(data);
    XmlParser newParser=new XmlParser();
    ConfigXmlHandler newHandler=new ConfigXmlHandler(currentTree,systemId,includedClasses);
    newParser.setHandler(newHandler);
    newParser.parse(systemId,null,dataReader);
    dataReader.close();
  }
}

Fixed version (ground truth):
public void processingInstruction(String target,String data) throws Exception {
  if (target.equals("String_Node_Str")) {
    StringReader dataReader=new StringReader(data);
    XmlParser newParser=new XmlParser();
    ConfigXmlHandler newHandler=new ConfigXmlHandler(currentTree,systemId,includedClasses);
    newHandler.addExcludedFiles(_excludedFiles);
    newParser.setHandler(newHandler);
    newParser.parse(systemId,null,dataReader);
    dataReader.close();
  }
}
Program: 75056
Project: 75056
Buggy source:
public Object resolveEntity(String publicId,String systemId) throws Exception {
  if (publicId != null && publicId.equals(MoMLParser.MoML_PUBLIC_ID_1)) {
    return new StringReader(MoMLParser.MoML_DTD_1);
  }
 else {
    return null;
  }
}

Fixed version (ground truth):
public Object resolveEntity(String publicId,String systemId) throws Exception {
  if (publicId != null && publicId.equals(MoML_PUBLIC_ID_1)) {
    return new StringReader(MoML_DTD_1);
  }
 else {
    return null;
  }
}
Program: 75059
Project: 75059
Buggy source:
public void $RESTORE(long timestamp,boolean trim){
  if (timestamp <= $RECORD$$CHECKPOINT.getTopTimestamp()) {
    $CHECKPOINT=$RECORD$$CHECKPOINT.restore($CHECKPOINT,this,timestamp,trim);
    FieldRecord.popState($RECORDS);
  }
}

Fixed version (ground truth):
public void $RESTORE(long timestamp,boolean trim){
  if (timestamp <= $RECORD$$CHECKPOINT.getTopTimestamp()) {
    $CHECKPOINT=$RECORD$$CHECKPOINT.restore($CHECKPOINT,this,timestamp,trim);
    FieldRecord.popState($RECORDS);
    $RESTORE(timestamp,trim);
  }
}
Program: 75060
Project: 75060
Buggy source:
public void $RESTORE_ANONYMOUS(long timestamp,boolean trim){
  $RECORD$i.restore(i,timestamp,trim);
  position=$RECORD$position.restore(position,timestamp,trim);
  if (timestamp <= $RECORD$$CHECKPOINT.getTopTimestamp()) {
    $CHECKPOINT=$RECORD$$CHECKPOINT.restore($CHECKPOINT,new _PROXY_(),timestamp,trim);
    FieldRecord.popState($RECORDS);
  }
}

Fixed version (ground truth):
public void $RESTORE_ANONYMOUS(long timestamp,boolean trim){
  $RECORD$i.restore(i,timestamp,trim);
  position=$RECORD$position.restore(position,timestamp,trim);
  if (timestamp <= $RECORD$$CHECKPOINT.getTopTimestamp()) {
    $CHECKPOINT=$RECORD$$CHECKPOINT.restore($CHECKPOINT,new _PROXY_(),timestamp,trim);
    FieldRecord.popState($RECORDS);
    $RESTORE_ANONYMOUS(timestamp,trim);
  }
}
Program: 75065
Project: 75065
Buggy source:
public void $RESTORE(long timestamp,boolean trim){
  keys=(Set)$RECORD$keys.restore(keys,timestamp,trim);
  values=(Collection)$RECORD$values.restore(values,timestamp,trim);
  if (timestamp <= $RECORD$$CHECKPOINT.getTopTimestamp()) {
    $CHECKPOINT=$RECORD$$CHECKPOINT.restore($CHECKPOINT,this,timestamp,trim);
    FieldRecord.popState($RECORDS);
  }
}

Fixed version (ground truth):
public void $RESTORE(long timestamp,boolean trim){
  keys=(Set)$RECORD$keys.restore(keys,timestamp,trim);
  values=(Collection)$RECORD$values.restore(values,timestamp,trim);
  if (timestamp <= $RECORD$$CHECKPOINT.getTopTimestamp()) {
    $CHECKPOINT=$RECORD$$CHECKPOINT.restore($CHECKPOINT,this,timestamp,trim);
    FieldRecord.popState($RECORDS);
    $RESTORE(timestamp,trim);
  }
}
Program: 75067
Project: 75067
Buggy source:
public void $RESTORE(long timestamp,boolean trim){
  if (timestamp <= $RECORD$$CHECKPOINT.getTopTimestamp()) {
    $CHECKPOINT=$RECORD$$CHECKPOINT.restore($CHECKPOINT,this,timestamp,trim);
    FieldRecord.popState($RECORDS);
  }
}

Fixed version (ground truth):
public void $RESTORE(long timestamp,boolean trim){
  if (timestamp <= $RECORD$$CHECKPOINT.getTopTimestamp()) {
    $CHECKPOINT=$RECORD$$CHECKPOINT.restore($CHECKPOINT,this,timestamp,trim);
    FieldRecord.popState($RECORDS);
    $RESTORE(timestamp,trim);
  }
}
Program: 75069
Project: 75069
Buggy source:
public void $RESTORE(long timestamp,boolean trim){
  threshold=$RECORD$threshold.restore(threshold,timestamp,trim);
  buckets=(HashEntry[])$RECORD$buckets.restore(buckets,timestamp,trim);
  modCount=$RECORD$modCount.restore(modCount,timestamp,trim);
  size=$RECORD$size.restore(size,timestamp,trim);
  keys=(Set)$RECORD$keys.restore(keys,timestamp,trim);
  values=(Collection)$RECORD$values.restore(values,timestamp,trim);
  entries=(Set)$RECORD$entries.restore(entries,timestamp,trim);
  if (timestamp <= $RECORD$$CHECKPOINT.getTopTimestamp()) {
    $CHECKPOINT=$RECORD$$CHECKPOINT.restore($CHECKPOINT,this,timestamp,trim);
    FieldRecord.popState($RECORDS);
  }
}

Fixed version (ground truth):
public void $RESTORE(long timestamp,boolean trim){
  threshold=$RECORD$threshold.restore(threshold,timestamp,trim);
  buckets=(HashEntry[])$RECORD$buckets.restore(buckets,timestamp,trim);
  modCount=$RECORD$modCount.restore(modCount,timestamp,trim);
  size=$RECORD$size.restore(size,timestamp,trim);
  keys=(Set)$RECORD$keys.restore(keys,timestamp,trim);
  values=(Collection)$RECORD$values.restore(values,timestamp,trim);
  entries=(Set)$RECORD$entries.restore(entries,timestamp,trim);
  if (timestamp <= $RECORD$$CHECKPOINT.getTopTimestamp()) {
    $CHECKPOINT=$RECORD$$CHECKPOINT.restore($CHECKPOINT,this,timestamp,trim);
    FieldRecord.popState($RECORDS);
    $RESTORE(timestamp,trim);
  }
}
Program: 75070
Project: 75070
Buggy source:
public Class loadClass(File classFile) throws FileNotFoundException, IOException, LinkageError, ClassNotFoundException {
  FileInputStream inputStream=new FileInputStream(classFile);
  byte[] buffer=new byte[inputStream.available()];
  inputStream.read(buffer);
  try {
    return defineClass(null,buffer,0,buffer.length);
  }
 catch (  LinkageError e) {
    String errorPrefix="String_Node_Str";
    String message=e.getMessage();
    if (message.startsWith(errorPrefix)) {
      String path=message.substring(errorPrefix.length());
      String classFullName=path.replace('/','.');
      return loadClass(classFullName);
    }
 else     throw e;
  }
}

Fixed version (ground truth):
public Class loadClass(File classFile) throws FileNotFoundException, IOException, LinkageError, ClassNotFoundException {
  FileInputStream inputStream=new FileInputStream(classFile);
  byte[] buffer=new byte[inputStream.available()];
  inputStream.read(buffer);
  try {
    return defineClass(null,buffer,0,buffer.length);
  }
 catch (  IllegalAccessError e) {
    String errorPrefix="String_Node_Str";
    String message=e.getMessage();
    if (message.startsWith(errorPrefix)) {
      String className=message.substring(errorPrefix.length());
      int pos;
      if ((pos=className.indexOf(' ')) >= 0)       className=className.substring(0,pos);
      return loadClass(className);
    }
 else     throw e;
  }
catch (  LinkageError e) {
    String errorPrefix="String_Node_Str";
    String message=e.getMessage();
    if (message.startsWith(errorPrefix)) {
      String path=message.substring(errorPrefix.length());
      String classFullName=path.replace('/','.');
      return loadClass(classFullName);
    }
 else     throw e;
  }
}
Program: 75071
Project: 75071
Buggy source:
/** 
 * Retun true if all the refinements can resolve their states with the current step size.
 * @return True if all the refinements can resolve their states with thecurrent step size.
 */
public boolean isStateAccurate(){
  boolean result=true;
  CTDirector dir=(CTDirector)(((Actor)getContainer()).getExecutiveDirector());
  if (_enabledRefinements != null) {
    Iterator refinements=_enabledRefinements.iterator();
    while (refinements.hasNext()) {
      Actor refinement=(Actor)refinements.next();
      if (refinement instanceof CTStepSizeControlActor) {
        result=result && ((CTStepSizeControlActor)refinement).isStateAccurate();
      }
    }
  }
  return result;
}

Fixed version (ground truth):
/** 
 * Retun true if all the refinements can resolve their states with the current step size.
 * @return True if all the refinements can resolve their states with thecurrent step size.
 */
public boolean isStateAccurate(){
  boolean result=true;
  if (_enabledRefinements != null) {
    Iterator refinements=_enabledRefinements.iterator();
    while (refinements.hasNext()) {
      Actor refinement=(Actor)refinements.next();
      if (refinement instanceof CTStepSizeControlActor) {
        result=result && ((CTStepSizeControlActor)refinement).isStateAccurate();
      }
    }
  }
  return result;
}
Program: 75075
Project: 75075
Buggy source:
/** 
 * Initialize the execution.  Create the IconViewScreen3D frame if it hasn't been set using the place() method.
 * @exception IllegalActionException If the base class throws it.
 */
public void initialize() throws IllegalActionException {
  super.initialize();
  _frameNumber=0;
  _frameWidth=_getHorizontalPixels();
  _frameHeight=_getVerticalPixels();
}

Fixed version (ground truth):
/** 
 * Initialize the execution.  Create the IconViewScreen3D frame if it hasn't been set using the place() method.
 * @exception IllegalActionException If the base class throws it.
 */
public void initialize() throws IllegalActionException {
  super.initialize();
  _frameNumber=0;
  _frameWidth=((IntToken)horizontalResolution.getToken()).intValue();
  _frameHeight=((IntToken)verticalResolution.getToken()).intValue();
}
Program: 75078
Project: 75078
Buggy source:
private static void _addInnerClasses(Set crossAnalysis,String classFileName,String packageName){
  File topFile=new File(classFileName);
  File path=topFile.getParentFile();
  String className=topFile.getName().substring(0,topFile.getName().length() - 6);
  File[] files=path.listFiles(new InnerClassFilter(className));
  for (int i=0; i < files.length; i++) {
    File file=files[i];
    className=file.getName().substring(0,file.getName().length() - 6);
    if (packageName != null)     className=packageName + "String_Node_Str" + className;
    crossAnalysis.add(className);
  }
}

Fixed version (ground truth):
private static void _addInnerClasses(Set crossAnalysis,String classFileName,String packageName){
  File topFile=new File(classFileName);
  File path=topFile.getParentFile();
  if (path == null)   path=new File("String_Node_Str");
  String className=topFile.getName().substring(0,topFile.getName().length() - 6);
  File[] files=path.listFiles(new InnerClassFilter(className));
  for (int i=0; i < files.length; i++) {
    File file=files[i];
    className=file.getName().substring(0,file.getName().length() - 6);
    if (packageName != null)     className=packageName + "String_Node_Str" + className;
    crossAnalysis.add(className);
  }
}
Program: 75079
Project: 75079
Buggy source:
public int compare(Object o1,Object o2){
  if (o1.getClass().isInstance(o2))   return 0;
  Class[] classes=new Class[]{FieldDeclaration.class,TypeDeclaration.class,MethodDeclaration.class};
  for (int i=0; i < classes.length; i++)   if (classes[i].isInstance(o1))   for (int j=i + 1; j < classes.length; j++)   if (classes[j].isInstance(o2))   return -1;
  return 1;
}

Fixed version (ground truth):
public int compare(Object o1,Object o2){
  if (o1.getClass().isInstance(o2))   return 0;
  Class[] classes=new Class[]{FieldDeclaration.class,TypeDeclaration.class,MethodDeclaration.class,Initializer.class};
  for (int i=0; i < classes.length; i++)   if (classes[i].isInstance(o1))   for (int j=i + 1; j < classes.length; j++)   if (classes[j].isInstance(o2))   return -1;
  return 1;
}
Program: 75080
Project: 75080
Buggy source:
/** 
 * Get the simple class name of a class (not including any "." or "$"). The same function is provided in   {@link Class} class in Java 1.5.
 * @param c The class object.
 * @return The simple name of the class object.
 */
private String _getSimpleClassName(Class c){
  String name=c.getName();
  int lastSeparator1=name.lastIndexOf('.');
  int lastSeparator2=name.lastIndexOf('$');
  int lastSeparator=lastSeparator1 >= lastSeparator2 ? lastSeparator1 : lastSeparator2;
  return name.substring(lastSeparator + 1);
}

Fixed version (ground truth):
/** 
 * Get the simple class name of a class (not including any "." or "$"). The same function is provided in   {@link Class} class in Java 1.5.
 * @param c The class object.
 * @return The simple name of the class object.
 */
private String _getSimpleClassName(Class c){
  String name=c.getName();
  int lastSeparator1=name.lastIndexOf('.');
  int lastSeparator2=name.lastIndexOf('$');
  int lastSeparator=lastSeparator1 >= lastSeparator2 ? lastSeparator1 : lastSeparator2;
  name=name.substring(lastSeparator + 1);
  String newName=name;
  char ch=newName.charAt(0);
  while (ch >= '0' && ch <= '9' && newName.length() > 1) {
    newName=newName.substring(1);
    ch=newName.charAt(0);
  }
  if (newName.length() == 0)   return name;
 else   return newName;
}
Program: 75081
Project: 75081
Buggy source:
/** 
 * Sort a list or body declarations according to the Java compiler convention.
 * @param bodyDeclarations The list of body declarations.
 * @see #_sortBodyDeclarations(AbstractTypeDeclaration)
 * @see #_sortBodyDeclarations(AnonymousClassDeclaration)
 */
private static void _sortBodyDeclarations(List bodyDeclarations){
  Object[] bodyArray=bodyDeclarations.toArray();
  Arrays.sort(bodyArray,new Comparator(){
    public int compare(    Object o1,    Object o2){
      if (o1.getClass().isInstance(o2))       return 0;
      Class[] classes=new Class[]{FieldDeclaration.class,TypeDeclaration.class,MethodDeclaration.class};
      for (int i=0; i < classes.length; i++)       if (classes[i].isInstance(o1))       for (int j=i + 1; j < classes.length; j++)       if (classes[j].isInstance(o2))       return -1;
      return 1;
    }
  }
);
  bodyDeclarations.clear();
  bodyDeclarations.addAll(Arrays.asList(bodyArray));
}

Fixed version (ground truth):
/** 
 * Sort a list or body declarations according to the Java compiler convention.
 * @param bodyDeclarations The list of body declarations.
 * @see #_sortBodyDeclarations(AbstractTypeDeclaration)
 * @see #_sortBodyDeclarations(AnonymousClassDeclaration)
 */
private static void _sortBodyDeclarations(List bodyDeclarations){
  Object[] bodyArray=bodyDeclarations.toArray();
  Arrays.sort(bodyArray,new Comparator(){
    public int compare(    Object o1,    Object o2){
      if (o1.getClass().isInstance(o2))       return 0;
      Class[] classes=new Class[]{FieldDeclaration.class,TypeDeclaration.class,MethodDeclaration.class,Initializer.class};
      for (int i=0; i < classes.length; i++)       if (classes[i].isInstance(o1))       for (int j=i + 1; j < classes.length; j++)       if (classes[j].isInstance(o2))       return -1;
      return 1;
    }
  }
);
  bodyDeclarations.clear();
  bodyDeclarations.addAll(Arrays.asList(bodyArray));
}
Program: 75084
Project: 75084
Buggy source:
/** 
 * Add a handler (@link AssignmentTransformer) to the type analyzer. The handler refactors the AST while the type analyzer traverses it.
 * @param analyzer The type analyzer.
 * @param root The root of the AST.
 */
public void beforeTraverse(TypeAnalyzer analyzer,CompilationUnit root){
  AssignmentTransformer assignmentTransformer=new AssignmentTransformer();
  ConstructorTransformer constructorTransformer=new ConstructorTransformer();
  _handlers.add(assignmentTransformer);
  _handlers.add(constructorTransformer);
  analyzer.getHandlers().addAliasHandler(assignmentTransformer);
  analyzer.getHandlers().addAssignmentHandler(assignmentTransformer);
  analyzer.getHandlers().addClassHandler(assignmentTransformer);
  analyzer.getHandlers().addCrossAnalysisHandler(assignmentTransformer);
  analyzer.getHandlers().addClassHandler(constructorTransformer);
  analyzer.getHandlers().addConstructorHandler(constructorTransformer);
  analyzer.getHandlers().addCrossAnalysisHandler(constructorTransformer);
  analyzer.getHandlers().addMethodDeclarationHandler(constructorTransformer);
}

Fixed version (ground truth):
/** 
 * Add a handler (@link AssignmentTransformer) to the type analyzer. The handler refactors the AST while the type analyzer traverses it.
 * @param analyzer The type analyzer.
 * @param root The root of the AST.
 */
public void beforeTraverse(TypeAnalyzer analyzer,CompilationUnit root){
  AssignmentTransformer assignmentTransformer=new AssignmentTransformer();
  ConstructorTransformer constructorTransformer=new ConstructorTransformer();
  _handlers.add(assignmentTransformer);
  _handlers.add(constructorTransformer);
  analyzer.getHandlers().addAliasHandler(assignmentTransformer);
  analyzer.getHandlers().addAssignmentHandler(assignmentTransformer);
  analyzer.getHandlers().addClassHandler(assignmentTransformer);
  analyzer.getHandlers().addCrossAnalysisHandler(assignmentTransformer);
  analyzer.getHandlers().addMethodDeclarationHandler(assignmentTransformer);
  analyzer.getHandlers().addClassHandler(constructorTransformer);
  analyzer.getHandlers().addConstructorHandler(constructorTransformer);
  analyzer.getHandlers().addCrossAnalysisHandler(constructorTransformer);
  analyzer.getHandlers().addMethodDeclarationHandler(constructorTransformer);
}
Program: 75085
Project: 75085
Buggy source:
/** 
 * Resolve a method in the given class with an array of arguments.
 * @param owner The class where the method belongs to. If it is null, the current class is assumed, and all the enclosing classes are searched, if necessary.
 * @param methodName The name of the method.
 * @param arguments The array of arguments.
 * @return The return type and the owner of the method, or <tt>null</tt>if the method cannot be found.
 * @see #_getMethodType(Class,String,Type[])
 */
private TypeAndOwner _resolveMethod(Class owner,String methodName,Type[] arguments){
  Set handledSet=new HashSet();
  Stack previousClasses=_state.getPreviousClasses();
  int previousNum=previousClasses.size();
  Class oldOwner=owner;
  if (owner == null)   owner=_state.getCurrentClass();
  do {
    Type type=_getMethodType(owner,methodName,arguments);
    if (type != null)     return new TypeAndOwner(type,Type.createType(owner.getName()));
    handledSet.add(owner);
    owner=null;
    if (oldOwner == null)     while (owner == null && previousNum > 0) {
      owner=(Class)previousClasses.get(--previousNum);
      if (handledSet.contains(owner))       owner=null;
    }
  }
 while (owner != null);
  return null;
}

Fixed version (ground truth):
/** 
 * Resolve a method in the given class with an array of arguments.
 * @param owner The class where the method belongs to. If it is null, the current class is assumed, and all the enclosing classes are searched, if necessary.
 * @param methodName The name of the method.
 * @param arguments The array of arguments.
 * @return The return type and the owner of the method, or <tt>null</tt>if the method cannot be found.
 * @see #_getMethodType(Class,String,Type[])
 */
private TypeAndOwner _resolveMethod(Class owner,String methodName,Type[] arguments){
  Set handledSet=new HashSet();
  Stack previousClasses=_state.getPreviousClasses();
  int previousNum=previousClasses.size();
  Class oldOwner=owner;
  if (owner == null)   owner=_state.getCurrentClass();
  do {
    Type type=_getMethodType(owner,methodName,arguments);
    if (type != null)     return new TypeAndOwner(type,Type.createType(owner.getName()));
    handledSet.add(owner);
    owner=null;
    if (oldOwner == null)     while (owner == null && previousNum > 0) {
      previousNum--;
      Object previousObject=previousClasses.get(previousNum);
      if (previousObject instanceof Class) {
        owner=(Class)previousObject;
        if (handledSet.contains(owner))         owner=null;
      }
    }
  }
 while (owner != null);
  return null;
}
Program: 75088
Project: 75088
Buggy source:
/** 
 * Get the previous class stack. The previous class stack stores all the entered but not exited class definitions, not including the current class. Each element in the stack is of type   {@link Class}. The bottom element in the stack is always <tt>null</tt>.
 * @return The previous class stack.
 * @see #setPreviousClasses(Stack)
 */
public Stack getPreviousClasses(){
  return _previousClasses;
}

Fixed version (ground truth):
/** 
 * Get the previous class stack. The previous class stack stores all the entered but not exited class definitions as well as blocks, not including the current class. Each element in the stack is either of type   {@link Class} or type {@link Hashtable}. The bottom element in the stack is always <tt>null</tt>. <p> An element of type   {@link Hashtable} means the previous entity isa block, where classes can also be defined in it. In that case, simple class names are the keys of the table, and  {@link Class}objects are its values.
 * @return The previous class stack.
 * @see #setPreviousClasses(Stack)
 */
public Stack getPreviousClasses(){
  return _previousClasses;
}
Program: 75089
Project: 75089
Buggy source:
/** 
 * Create an AST name node with a name string (possibly partitioned with ".").
 * @param ast The {@link AST} object.
 * @param name The name.
 * @return The AST name node.
 */
public static Name createName(AST ast,String name){
  int oldPos=0;
  Name fullName=null;
  while (oldPos != -1) {
    int pos=indexOf(name,new char[]{'.','$'},oldPos);
    String subname=pos == -1 ? name.substring(oldPos) : name.substring(oldPos,pos);
    if (fullName == null)     fullName=ast.newSimpleName(subname);
 else     fullName=ast.newQualifiedName(fullName,ast.newSimpleName(subname));
    if (pos == -1)     oldPos=-1;
 else     oldPos=pos + 1;
  }
  return fullName;
}

Fixed version (ground truth):
/** 
 * Create an AST name node with a name string (possibly partitioned with ".").
 * @param ast The {@link AST} object.
 * @param name The name.
 * @return The AST name node.
 */
public static Name createName(AST ast,String name){
  int oldPos=0;
  Name fullName=null;
  while (oldPos != -1) {
    int pos=indexOf(name,new char[]{'.','$'},oldPos);
    String subname=pos == -1 ? name.substring(oldPos) : name.substring(oldPos,pos);
    char c=subname.charAt(0);
    while (c >= '0' && c <= '9') {
      subname=subname.substring(1);
      c=subname.charAt(0);
    }
    if (fullName == null)     fullName=ast.newSimpleName(subname);
 else     fullName=ast.newQualifiedName(fullName,ast.newSimpleName(subname));
    if (pos == -1)     oldPos=-1;
 else     oldPos=pos + 1;
  }
  return fullName;
}
Program: 75092
Project: 75092
Buggy source:
private MethodDeclaration _createGetCheckpointMethod(AST ast,CompilationUnit root,TypeAnalyzerState state,boolean isAnonymous){
  String methodName=_getGetCheckpointMethodName(isAnonymous);
  Class currentClass=state.getCurrentClass();
  Class parent=currentClass.getSuperclass();
  if (hasMethod(currentClass,methodName,new Class[0]))   throw new ASTDuplicatedMethodException(currentClass.getName(),methodName);
  if (parent != null && (state.getCrossAnalyzedTypes().contains(parent.getName())) || hasMethod(parent,methodName,new Class[]{Checkpoint.class}))   return null;
  MethodDeclaration method=ast.newMethodDeclaration();
  method.setName(ast.newSimpleName(methodName));
  String typeName=getClassName(Checkpoint.class,state,root);
  method.setReturnType(createType(ast,typeName));
  Block body=ast.newBlock();
  method.setBody(body);
  ReturnStatement returnStatement=ast.newReturnStatement();
  returnStatement.setExpression(ast.newSimpleName(CHECKPOINT_NAME));
  body.statements().add(returnStatement);
  method.setModifiers(Modifier.PUBLIC | Modifier.FINAL);
  addToLists(_checkParentMethods,parent.getName(),method);
  return method;
}

Fixed version (ground truth):
private MethodDeclaration _createGetCheckpointMethod(AST ast,CompilationUnit root,TypeAnalyzerState state,boolean isAnonymous){
  String methodName=_getGetCheckpointMethodName(isAnonymous);
  Class currentClass=state.getCurrentClass();
  Class parent=currentClass.getSuperclass();
  if (hasMethod(currentClass,methodName,new Class[0]))   throw new ASTDuplicatedMethodException(currentClass.getName(),methodName);
  if (!isAnonymous && parent != null && (state.getCrossAnalyzedTypes().contains(parent.getName()) || hasMethod(parent,methodName,new Class[]{})))   return null;
  MethodDeclaration method=ast.newMethodDeclaration();
  method.setName(ast.newSimpleName(methodName));
  String typeName=getClassName(Checkpoint.class,state,root);
  method.setReturnType(createType(ast,typeName));
  Block body=ast.newBlock();
  method.setBody(body);
  ReturnStatement returnStatement=ast.newReturnStatement();
  returnStatement.setExpression(ast.newSimpleName(CHECKPOINT_NAME));
  body.statements().add(returnStatement);
  method.setModifiers(Modifier.PUBLIC | Modifier.FINAL);
  if (!isAnonymous)   addToLists(_checkParentMethods,parent.getName(),method);
  return method;
}
Program: 75093
Project: 75093
Buggy source:
/** 
 * Create the field declaration for the checkpoint record.
 * @param ast The {@link AST} object.
 * @param root The root of the AST.
 * @param state The current state of the type analyzer.
 * @return The field declaration, or <tt>null</tt> if the field alreadyexists in the class or its superclasses.
 */
private FieldDeclaration _createCheckpointRecord(AST ast,CompilationUnit root,TypeAnalyzerState state){
  Class currentClass=state.getCurrentClass();
  Class parent=currentClass.getSuperclass();
  if (parent != null && (state.getCrossAnalyzedTypes().contains(parent.getName()) || isFieldDuplicated(parent,CHECKPOINT_NAME)))   return null;
  VariableDeclarationFragment fragment=ast.newVariableDeclarationFragment();
  fragment.setName(ast.newSimpleName(CHECKPOINT_RECORD_NAME));
  ClassInstanceCreation creation=ast.newClassInstanceCreation();
  String typeName=getClassName(CheckpointRecord.class,state,root);
  creation.setName(createName(ast,typeName));
  fragment.setInitializer(creation);
  FieldDeclaration record=ast.newFieldDeclaration(fragment);
  record.setType(createType(ast,typeName));
  record.setModifiers(Modifier.PRIVATE);
  addToLists(_checkParentFields,parent.getName(),record);
  return record;
}

Fixed version (ground truth):
/** 
 * Create the field declaration for the checkpoint record.
 * @param ast The {@link AST} object.
 * @param root The root of the AST.
 * @param state The current state of the type analyzer.
 * @return The field declaration, or <tt>null</tt> if the field alreadyexists in the class or its superclasses.
 */
private FieldDeclaration _createCheckpointRecord(AST ast,CompilationUnit root,TypeAnalyzerState state){
  Class currentClass=state.getCurrentClass();
  Class parent=currentClass.getSuperclass();
  if (parent != null && (state.getCrossAnalyzedTypes().contains(parent.getName()) || isFieldDuplicated(parent,CHECKPOINT_RECORD_NAME)))   return null;
  VariableDeclarationFragment fragment=ast.newVariableDeclarationFragment();
  fragment.setName(ast.newSimpleName(CHECKPOINT_RECORD_NAME));
  ClassInstanceCreation creation=ast.newClassInstanceCreation();
  String typeName=getClassName(CheckpointRecord.class,state,root);
  creation.setName(createName(ast,typeName));
  fragment.setInitializer(creation);
  FieldDeclaration record=ast.newFieldDeclaration(fragment);
  record.setType(createType(ast,typeName));
  record.setModifiers(Modifier.PROTECTED);
  addToLists(_checkParentFields,parent.getName(),record);
  return record;
}
Program: 75098
Project: 75098
Buggy source:
/** 
 * Consume a token from the <i>input</i> port and display the token as an image.  If a token is not available, do nothing.
 * @exception IllegalActionException If there is no director, orif the base class throws it.
 */
public boolean postfire() throws IllegalActionException {
  if (input.hasToken(0)) {
    Token in=input.get(0);
    if (!(in instanceof ImageToken)) {
      throw new IllegalActionException(this,"String_Node_Str" + in);
    }
    if (_frame != null) {
      List tokens=new LinkedList();
      tokens.add(in);
      _effigy.setTokens(tokens);
    }
 else     if (_picture != null) {
      Image image=((ImageToken)in).asAWTImage();
      int xsize=image.getWidth(null);
      int ysize=image.getHeight(null);
      if ((_oldxsize != xsize) || (_oldysize != ysize)) {
        if (_debugging) {
          _debug("String_Node_Str");
        }
        _oldxsize=xsize;
        _oldysize=ysize;
        Container container=_picture.getParent();
        if (_picture != null) {
          container.remove(_picture);
        }
        _picture=new Picture(xsize,ysize);
        _picture.setImage(image);
        _picture.setBackground(null);
        container.add("String_Node_Str",_picture);
        container.validate();
        container.invalidate();
        container.repaint();
        container.doLayout();
        Container c=container.getParent();
        while (c.getParent() != null) {
          c.invalidate();
          c.validate();
          c=c.getParent();
          if (c instanceof JFrame) {
            ((JFrame)c).pack();
          }
        }
      }
 else {
        _picture.setImage(((ImageToken)in).asAWTImage());
        _picture.displayImage();
        _picture.repaint();
      }
    }
  }
  return super.postfire();
}

Fixed version (ground truth):
/** 
 * Consume a token from the <i>input</i> port and display the token as an image.  If a token is not available, do nothing.
 * @exception IllegalActionException If there is no director, orif the base class throws it.
 */
public boolean postfire() throws IllegalActionException {
  if (input.hasToken(0)) {
    final Token in=input.get(0);
    if (!(in instanceof ImageToken)) {
      throw new IllegalActionException(this,"String_Node_Str" + in);
    }
    Runnable doDisplay=new Runnable(){
      public void run(){
        _display(in);
      }
    }
;
    SwingUtilities.invokeLater(doDisplay);
  }
  return super.postfire();
}
Program: 75099
Project: 75099
Buggy source:
/** 
 * Construct an empty window. After constructing this, it is necessary to call setVisible(true) to make the frame appear and setTableau() to associate it with a tableau.
 */
public ImageWindow(){
  super(null,null);
  this.getContentPane().setLayout(new BorderLayout(15,15));
}

Fixed version (ground truth):
/** 
 * Construct an empty window. After constructing this, it is necessary to call setVisible(true) to make the frame appear and setTableau() to associate it with a tableau.
 */
public ImageWindow(){
  super(null,null);
}
Program: 75100
Project: 75100
Buggy source:
/** 
 * Initialize this actor. If place has not been called, then create a frame to display the image in.
 * @exception IllegalActionException If a contained method throws it.
 */
public void initialize() throws IllegalActionException {
  super.initialize();
  if (_container == null) {
    if (_tableau == null) {
      Effigy containerEffigy=Configuration.findEffigy(toplevel());
      if (containerEffigy == null) {
        throw new IllegalActionException(this,"String_Node_Str" + toplevel().getFullName());
      }
      try {
        _effigy=new TokenEffigy(containerEffigy,containerEffigy.uniqueName("String_Node_Str"));
        _effigy.identifier.setExpression(getFullName());
        _frame=new ImageWindow();
        _tableau=new ImageTableau(_effigy,"String_Node_Str",_frame,_oldxsize,_oldysize);
        _tableau.setTitle(getName());
        _frame.setTableau(_tableau);
        _windowProperties.setProperties(_frame);
        Component[] components=_frame.getContentPane().getComponents();
        if (components.length > 0) {
          _pictureSize.setSize(components[0]);
        }
        _tableau.show();
      }
 catch (      Exception ex) {
        throw new IllegalActionException(this,null,ex,"String_Node_Str");
      }
    }
 else {
      _effigy.clear();
      if (_frame != null) {
        _frame.toFront();
      }
    }
  }
  if (_frame != null) {
    _frame.setVisible(true);
    _frame.toFront();
  }
}

Fixed version (ground truth):
/** 
 * Initialize this actor. If place has not been called, then create a frame to display the image in.
 * @exception IllegalActionException If a contained method throws it.
 */
public void initialize() throws IllegalActionException {
  super.initialize();
  Runnable doDisplay=new Runnable(){
    public void run(){
      _createOrShowWindow();
    }
  }
;
  SwingUtilities.invokeLater(doDisplay);
}
Program: 75101
Project: 75101
Buggy source:
/** 
 * Display the specified token.
 * @param token The token to append.
 * @exception If the token is not an ImageToken.
 */
public void display(ImageToken token) throws IllegalActionException {
  Image image=token.asAWTImage();
  if (image == null) {
    throw new IllegalActionException(this,"String_Node_Str");
  }
 else {
    int xsize=image.getWidth(null);
    int ysize=image.getHeight(null);
    if ((_oldxsize != xsize) || (_oldysize != ysize)) {
      if (_debugging) {
        _debug("String_Node_Str");
      }
      _oldxsize=xsize;
      _oldysize=ysize;
      Container container=_picture.getParent();
      if (_picture != null) {
        container.remove(_picture);
      }
      _picture=new Picture(xsize,ysize);
      _picture.setImage(image);
      _picture.setBackground(null);
      container.add("String_Node_Str",_picture);
      container.validate();
      container.invalidate();
      container.repaint();
      container.doLayout();
      Container c=container.getParent();
      while (c.getParent() != null) {
        c.invalidate();
        c.validate();
        c=c.getParent();
      }
      while (c.getParent() != null) {
        c=c.getParent();
      }
      if (c instanceof JFrame) {
        ((JFrame)c).pack();
      }
    }
 else {
      _picture.setImage(image);
    }
    _picture.displayImage();
    _picture.repaint();
    Thread.yield();
  }
}

Fixed version (ground truth):
/** 
 * Display the specified token.
 * @param token The token to append.
 * @exception If the token is not an ImageToken.
 */
public void display(ImageToken token) throws IllegalActionException {
  Image image=token.asAWTImage();
  if (image == null) {
    throw new IllegalActionException(this,"String_Node_Str");
  }
 else {
    int xsize=image.getWidth(null);
    int ysize=image.getHeight(null);
    if ((_oldxsize != xsize) || (_oldysize != ysize)) {
      if (_debugging) {
        _debug("String_Node_Str");
      }
      _oldxsize=xsize;
      _oldysize=ysize;
      Container container=_picture.getParent();
      Container top=container.getParent();
      while (top.getParent() != null) {
        top=top.getParent();
      }
      JFrame castTop=(JFrame)top;
      if (_picture != null) {
        castTop.getContentPane().remove(_picture);
      }
      _picture=new Picture(xsize,ysize);
      _picture.setImage(image);
      _picture.setBackground(null);
      castTop.getContentPane().add(_picture,BorderLayout.CENTER);
      castTop.getContentPane().validate();
      castTop.pack();
    }
 else {
      _picture.setImage(image);
    }
    _picture.displayImage();
    _picture.repaint();
    Thread.yield();
  }
}