Program: 58267
Project: 58267
Buggy source:
/** 
 * Applies EditorConfig rules for the given file.
 * @param dataObject
 */
public void applyRulesToFile(DataObject dataObject) throws Exception {
  HashMap<String,String> keyedRules=parseRulesForFile(dataObject);
  FileObject fileObject=dataObject.getPrimaryFile();
  EditorCookie cookie=getEditorCookie(fileObject);
  boolean isOpenedInEditor=cookie != null && cookie.getDocument() != null;
  if (isOpenedInEditor) {
    LOG.log(Level.INFO,"String_Node_Str");
    StyledDocument document=cookie.getDocument();
    NbDocument.runAtomicAsUser(document,() -> {
      try {
        cookie.saveDocument();
      }
 catch (      IOException ex) {
        Exceptions.printStackTrace(ex);
      }
    }
);
  }
  StringBuilder content=new StringBuilder(fileObject.asText());
  boolean changed=false;
  boolean charsetChange=false;
  boolean styleChanged=false;
  for (  Map.Entry<String,String> rule : keyedRules.entrySet()) {
    final String key=rule.getKey();
    final String value=rule.getValue();
    LOG.log(Level.INFO,"String_Node_Str",new Object[]{key,value});
switch (key) {
case EditorConfigConstant.CHARSET:
      Charset currentCharset=NetBeansFileUtil.guessCharset(fileObject);
    Charset requestedCharset=EditorConfigPropertyMapper.mapCharset(keyedRules.get(EditorConfigConstant.CHARSET));
  if (!currentCharset.equals(requestedCharset)) {
    charsetChange=true;
  }
break;
case EditorConfigConstant.END_OF_LINE:
changed=XLineEndingOperation.doChangeLineEndings(content,EditorConfigPropertyMapper.normalizeLineEnding(keyedRules.get(EditorConfigConstant.END_OF_LINE))) || changed;
break;
case EditorConfigConstant.INDENT_SIZE:
styleChanged=IndentSizeOperation.doIndentSize(dataObject,value) || styleChanged;
break;
case EditorConfigConstant.INDENT_STYLE:
styleChanged=IndentStyleOperation.doIndentStyle(dataObject,key) || styleChanged;
break;
case EditorConfigConstant.INSERT_FINAL_NEWLINE:
changed=XFinalNewLineOperation.doFinalNewLine(content,value,EditorConfigPropertyMapper.normalizeLineEnding(keyedRules.get(EditorConfigConstant.END_OF_LINE))) || changed;
break;
case EditorConfigConstant.TAB_WIDTH:
styleChanged=XTabWidthOperation.doTabWidth(dataObject,value) || styleChanged;
break;
case EditorConfigConstant.TRIM_TRAILING_WHITESPACE:
changed=XTrimTrailingWhitespacesOperation.doTrimTrailingWhitespaces(content,value,EditorConfigPropertyMapper.normalizeLineEnding(keyedRules.get(EditorConfigConstant.END_OF_LINE))) || changed;
break;
default :
LOG.log(Level.WARNING,"String_Node_Str",key);
break;
}
}
flushFile(fileObject,content,changed,charsetChange,EditorConfigPropertyMapper.mapCharset(keyedRules.get(EditorConfigConstant.CHARSET)),isOpenedInEditor,cookie);
flushStyles(fileObject,styleChanged);
}

Fixed version (ground truth):
/** 
 * Applies EditorConfig rules for the given file.
 * @param dataObject
 */
public void applyRulesToFile(DataObject dataObject) throws Exception {
  HashMap<String,String> keyedRules=parseRulesForFile(dataObject);
  FileObject fileObject=dataObject.getPrimaryFile();
  EditorCookie cookie=getEditorCookie(dataObject);
  boolean isOpenedInEditor=cookie != null && cookie.getDocument() != null;
  if (isOpenedInEditor) {
    LOG.log(Level.INFO,"String_Node_Str");
    StyledDocument document=cookie.getDocument();
    NbDocument.runAtomicAsUser(document,() -> {
      try {
        cookie.saveDocument();
      }
 catch (      IOException ex) {
        Exceptions.printStackTrace(ex);
      }
    }
);
  }
  StringBuilder content=new StringBuilder(fileObject.asText());
  boolean fileChange=false;
  boolean charsetChange=false;
  boolean styleChange=false;
  for (  Map.Entry<String,String> rule : keyedRules.entrySet()) {
    final String key=rule.getKey();
    final String value=rule.getValue();
    LOG.log(Level.INFO,"String_Node_Str",new Object[]{key,value});
switch (key) {
case EditorConfigConstant.CHARSET:
      Charset currentCharset=NetBeansFileUtil.guessCharset(fileObject);
    Charset requestedCharset=EditorConfigPropertyMapper.mapCharset(keyedRules.get(EditorConfigConstant.CHARSET));
  if (!currentCharset.equals(requestedCharset)) {
    charsetChange=true;
  }
break;
case EditorConfigConstant.END_OF_LINE:
fileChange=XLineEndingOperation.doChangeLineEndings(content,EditorConfigPropertyMapper.normalizeLineEnding(keyedRules.get(EditorConfigConstant.END_OF_LINE))) || fileChange;
StyledDocument document=NbDocument.getDocument(dataObject);
if (document != null) {
if (!document.getProperty(BaseDocument.READ_LINE_SEPARATOR_PROP).equals(EditorConfigPropertyMapper.normalizeLineEnding(keyedRules.get(EditorConfigConstant.END_OF_LINE)))) {
document.putProperty(BaseDocument.READ_LINE_SEPARATOR_PROP,EditorConfigPropertyMapper.normalizeLineEnding(keyedRules.get(EditorConfigConstant.END_OF_LINE)));
LOG.log(Level.INFO,"String_Node_Str");
}
 else {
LOG.log(Level.INFO,"String_Node_Str");
}
}
break;
case EditorConfigConstant.INDENT_SIZE:
styleChange=IndentSizeOperation.doIndentSize(dataObject,value) || styleChange;
break;
case EditorConfigConstant.INDENT_STYLE:
styleChange=IndentStyleOperation.doIndentStyle(dataObject,key) || styleChange;
break;
case EditorConfigConstant.INSERT_FINAL_NEWLINE:
fileChange=XFinalNewLineOperation.doFinalNewLine(content,value,EditorConfigPropertyMapper.normalizeLineEnding(keyedRules.get(EditorConfigConstant.END_OF_LINE))) || fileChange;
break;
case EditorConfigConstant.TAB_WIDTH:
styleChange=XTabWidthOperation.doTabWidth(dataObject,value) || styleChange;
break;
case EditorConfigConstant.TRIM_TRAILING_WHITESPACE:
fileChange=XTrimTrailingWhitespacesOperation.doTrimTrailingWhitespaces(content,value,EditorConfigPropertyMapper.normalizeLineEnding(keyedRules.get(EditorConfigConstant.END_OF_LINE))) || fileChange;
break;
default :
LOG.log(Level.WARNING,"String_Node_Str",key);
break;
}
}
flushFile(fileObject,content,fileChange,charsetChange,EditorConfigPropertyMapper.mapCharset(keyedRules.get(EditorConfigConstant.CHARSET)),isOpenedInEditor,cookie);
flushStyles(fileObject,styleChange);
}