Program: 11841
Project: 11841
Buggy source:
/** 
 * Generates a properties file using JET, with   {@link org.eclipse.emf.codegen.merge.properties.PropertyMerger merging}capability. <p>The encoding used for the generated file is "ISO-8859-1".  {@link org.eclipse.emf.codegen.util.CodeGenUtil#unicodeEscapeEncode(String) Unicode escape encoding} isperformed to represent non-Latin characters.
 * @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 jetEmitter the <code>JETEmitter</code> to use for generating the text.
 * @param arguments the argument array to pass to the <code>JETEmitter</code>'s{@link JETEmitter#generate(Monitor,Object[]) generate(Monitor, Object[])} method. If null, an array willbe constructed containing only the  {@link #generatingObject object} for which code is being generated. 
 * @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#dynamicTemplates dynamicTemplates}<li>  {@link Generator.Options#resourceSet resourceSet}</ul>
 */
protected void generateProperties(String targetPathName,JETEmitter jetEmitter,Object[] arguments,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 changed=false;
    if (arguments == null) {
      arguments=new Object[]{generatingObject};
    }
    setLineDelimiter(getLineDelimiter(targetFile,PROPERTIES_ENCODING));
    String emitterResult=CodeGenUtil.unicodeEscapeEncode(jetEmitter.generate(createMonitor(monitor,1),arguments,getLineDelimiter()));
    byte[] bytes=emitterResult.toString().getBytes(PROPERTIES_ENCODING);
    if (exists(targetFile)) {
      PropertyMerger propertyMerger=new PropertyMerger();
      propertyMerger.setSourceProperties(emitterResult);
      monitor.subTask(CodeGenEcorePlugin.INSTANCE.getString("String_Node_Str",new Object[]{targetFile}));
      String oldProperties=propertyMerger.createPropertiesForInputStream(createInputStream(targetFile));
      propertyMerger.setTargetProperties(oldProperties);
      monitor.subTask(CodeGenEcorePlugin.INSTANCE.getString("String_Node_Str",new Object[]{targetFile}));
      propertyMerger.merge();
      String mergedResult=propertyMerger.getTargetProperties();
      changed=!mergedResult.equals(oldProperties);
      if (changed) {
        if (isReadOnly(targetFile) && validateEdit(targetFile,createMonitor(monitor,1))) {
          propertyMerger.setTargetProperties(propertyMerger.createPropertiesForInputStream(createInputStream(targetFile)));
          propertyMerger.merge();
          mergedResult=propertyMerger.getTargetProperties();
        }
        bytes=mergedResult.getBytes(PROPERTIES_ENCODING);
      }
    }
 else {
      changed=true;
      monitor.worked(1);
    }
    if (changed) {
      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) {
          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(bytes);
      outputStream.close();
    }
  }
 catch (  Exception exception) {
    CodeGenEcorePlugin.INSTANCE.log(exception);
  }
 finally {
    setLineDelimiter(null);
    monitor.done();
  }
}

Fixed version (ground truth):
/** 
 * Generates a properties file using JET, with   {@link org.eclipse.emf.codegen.merge.properties.PropertyMerger merging}capability. <p>The encoding used for the generated file is "ISO-8859-1".  {@link org.eclipse.emf.codegen.util.CodeGenUtil#unicodeEscapeEncode(String) Unicode escape encoding} isperformed to represent non-Latin characters.
 * @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 jetEmitter the <code>JETEmitter</code> to use for generating the text.
 * @param arguments the argument array to pass to the <code>JETEmitter</code>'s{@link JETEmitter#generate(Monitor,Object[]) generate(Monitor, Object[])} method. If null, an array willbe constructed containing only the  {@link #generatingObject object} for which code is being generated. 
 * @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#dynamicTemplates dynamicTemplates}<li>  {@link Generator.Options#resourceSet resourceSet}</ul>
 */
protected void generateProperties(String targetPathName,JETEmitter jetEmitter,Object[] arguments,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 changed=false;
    if (arguments == null) {
      arguments=new Object[]{generatingObject};
    }
    setLineDelimiter(getLineDelimiter(targetFile,PROPERTIES_ENCODING));
    String emitterResult=CodeGenUtil.unicodeEscapeEncode(jetEmitter.generate(createMonitor(monitor,1),arguments,getLineDelimiter()));
    byte[] bytes=emitterResult.toString().getBytes(PROPERTIES_ENCODING);
    if (exists(targetFile)) {
      PropertyMerger propertyMerger=new PropertyMerger();
      propertyMerger.setSourceProperties(emitterResult);
      monitor.subTask(CodeGenEcorePlugin.INSTANCE.getString("String_Node_Str",new Object[]{targetFile}));
      String oldProperties=propertyMerger.createPropertiesForInputStream(createInputStream(targetFile));
      propertyMerger.setTargetProperties(oldProperties);
      monitor.subTask(CodeGenEcorePlugin.INSTANCE.getString("String_Node_Str",new Object[]{targetFile}));
      propertyMerger.merge();
      String mergedResult=propertyMerger.getTargetProperties();
      changed=!mergedResult.equals(oldProperties);
      if (changed) {
        if (isReadOnly(targetFile) && validateEdit(targetFile,createMonitor(monitor,1))) {
          propertyMerger.setTargetProperties(propertyMerger.createPropertiesForInputStream(createInputStream(targetFile)));
          propertyMerger.merge();
          mergedResult=propertyMerger.getTargetProperties();
        }
        bytes=mergedResult.getBytes(PROPERTIES_ENCODING);
      }
    }
 else {
      changed=true;
      monitor.worked(1);
    }
    if (changed) {
      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) {
          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(bytes);
      outputStream.close();
    }
  }
 catch (  Exception exception) {
    CodeGenEcorePlugin.INSTANCE.log(exception);
  }
 finally {
    setLineDelimiter(null);
    monitor.done();
  }
}