Program: 11842
Project: 11842
Buggy source:
/** 
 * Generates an icon using a   {@link org.eclipse.emf.codegen.util.GIFEmitter GIFEmitter} to colourize a grey-scale GIFimage. The colours to use are calculated from one or, optionally, two text keys. 
 * @param targetPathName the path name of the target file. This should be a workspace path; when running standalone,it will be converted to a platform resource URI that should be mapped to a physical file URI by the {@link #getURIConverter() URIConverter}.
 * @param gifEmitter the <code>GIFEmitter</code> to use for generating the icon.
 * @param parentKey the key used to determine the first colour set.
 * @param childKey the key used to determine the second colour set. If null, this key is ignored.
 * @param overwrite whether an existing file should be overritten.
 * @param monitor the <code>Monitor</code> through which to report progress.<p>This method also consults the following  {@link Generator#getOptions() generator options}: <ul> <li>  {@link Generator.Options#redirectionPattern redirectionPattern}<li>  {@link Generator.Options#forceOverwrite forceOverwrite}<li>  {@link Generator.Options#resourceSet resourceSet}</ul>
 */
protected void generateGIF(String targetPathName,GIFEmitter gifEmitter,String parentKey,String childKey,boolean overwrite,Monitor monitor){
  try {
    monitor.beginTask("String_Node_Str",3);
    URI targetFile=toURI(targetPathName);
    monitor.subTask(CodeGenEcorePlugin.INSTANCE.getString("String_Node_Str",new Object[]{targetFile}));
    URI targetDirectory=targetFile.trimSegments(1);
    ensureContainerExists(targetDirectory,createMonitor(monitor,1));
    boolean exists=exists(targetFile);
    if (!exists || overwrite) {
      byte[] emitterResult=gifEmitter.generateGIF(parentKey,childKey);
      monitor.worked(1);
      String redirection=getGenerator().getOptions().redirectionPattern;
      boolean redirect=redirection != null && redirection.indexOf("String_Node_Str") != -1;
      if (redirect) {
        String baseName=MessageFormat.format(redirection,new Object[]{targetFile.lastSegment()});
        targetFile=targetDirectory.appendSegment(baseName);
        monitor.subTask(CodeGenEcorePlugin.INSTANCE.getString("String_Node_Str",new Object[]{targetFile}));
      }
      if (isReadOnly(targetFile)) {
        if (getGenerator().getOptions().forceOverwrite) {
          validateEdit(targetFile,createMonitor(monitor,1));
          setWriteable(targetFile);
        }
 else {
          targetFile=targetDirectory.appendSegment("String_Node_Str" + targetFile.lastSegment() + "String_Node_Str");
          monitor.subTask(CodeGenEcorePlugin.INSTANCE.getString("String_Node_Str",new Object[]{targetFile}));
        }
      }
      OutputStream outputStream=createOutputStream(targetFile);
      outputStream.write(emitterResult);
      outputStream.close();
    }
  }
 catch (  Exception exception) {
    CodeGenEcorePlugin.INSTANCE.log(exception);
  }
 finally {
    monitor.done();
  }
}

Fixed version (ground truth):
/** 
 * Generates an icon using a   {@link org.eclipse.emf.codegen.util.GIFEmitter GIFEmitter} to colourize a grey-scale GIFimage. The colours to use are calculated from one or, optionally, two text keys. 
 * @param targetPathName the path name of the target file. This should be a workspace path; when running stand-alone,it will be converted to a platform resource URI that should be mapped to a physical file URI by the {@link #getURIConverter() URIConverter}.
 * @param gifEmitter the <code>GIFEmitter</code> to use for generating the icon.
 * @param parentKey the key used to determine the first colour set.
 * @param childKey the key used to determine the second colour set. If null, this key is ignored.
 * @param overwrite whether an existing file should be overwritten.
 * @param monitor the <code>Monitor</code> through which to report progress.<p>This method also consults the following  {@link Generator#getOptions() generator options}: <ul> <li>  {@link Generator.Options#redirectionPattern redirectionPattern}<li>  {@link Generator.Options#forceOverwrite forceOverwrite}<li>  {@link Generator.Options#resourceSet resourceSet}</ul>
 */
protected void generateGIF(String targetPathName,GIFEmitter gifEmitter,String parentKey,String childKey,boolean overwrite,Monitor monitor){
  try {
    monitor.beginTask("String_Node_Str",3);
    URI targetFile=toURI(targetPathName);
    monitor.subTask(CodeGenEcorePlugin.INSTANCE.getString("String_Node_Str",new Object[]{targetFile}));
    URI targetDirectory=targetFile.trimSegments(1);
    ensureContainerExists(targetDirectory,createMonitor(monitor,1));
    boolean exists=exists(targetFile);
    if (!exists || overwrite) {
      byte[] emitterResult=gifEmitter.generateGIF(parentKey,childKey);
      monitor.worked(1);
      String redirection=getGenerator().getOptions().redirectionPattern;
      boolean redirect=redirection != null && redirection.indexOf("String_Node_Str") != -1;
      if (redirect) {
        String baseName=MessageFormat.format(redirection,new Object[]{targetFile.lastSegment()});
        targetFile=targetDirectory.appendSegment(baseName);
        monitor.subTask(CodeGenEcorePlugin.INSTANCE.getString("String_Node_Str",new Object[]{targetFile}));
      }
      if (isReadOnly(targetFile)) {
        if (getGenerator().getOptions().forceOverwrite) {
          validateEdit(targetFile,createMonitor(monitor,1));
          setWriteable(targetFile);
        }
 else {
          targetFile=targetDirectory.appendSegment("String_Node_Str" + targetFile.lastSegment() + "String_Node_Str");
          monitor.subTask(CodeGenEcorePlugin.INSTANCE.getString("String_Node_Str",new Object[]{targetFile}));
        }
      }
      OutputStream outputStream=createOutputStream(targetFile);
      outputStream.write(emitterResult);
      outputStream.close();
    }
  }
 catch (  Exception exception) {
    CodeGenEcorePlugin.INSTANCE.log(exception);
  }
 finally {
    monitor.done();
  }
}