Program: 45268
Project: 45268
Buggy source:
public void execute(final Editor editor,DataContext dataContext){
  if (editor == null)   return;
  SelectionModel selectionModel=editor.getSelectionModel();
  final Project project=editor.getProject();
  if (project == null)   return;
  PsiDocumentManager psiManager=PsiDocumentManager.getInstance(project);
  PsiFile psiFile=psiManager.getPsiFile(editor.getDocument());
  if (!(psiFile instanceof PsiJavaFile)) {
    return;
  }
  PsiJavaFile javaFile=(PsiJavaFile)psiFile;
  PsiFile props=findMessagesDotProperties(project,javaFile);
  if (props == null) {
    Messages.showErrorDialog("String_Node_Str","String_Node_Str");
    return;
  }
  if (!(props instanceof PropertiesFile)) {
    Messages.showErrorDialog("String_Node_Str","String_Node_Str");
    return;
  }
  final PropertiesFile propsFile=(PropertiesFile)props;
  PsiElement e=findSelectedPsiElement(selectionModel,javaFile);
  while (e != null) {
    if (e instanceof PsiExpression)     break;
    e=e.getParent();
  }
  if (e == null) {
    Messages.showErrorDialog("String_Node_Str","String_Node_Str");
    return;
  }
  final PsiExpression exp=(PsiExpression)e;
  final PsiClassType stringType=PsiType.getJavaLangString(PsiManager.getInstance(project),e.getResolveScope());
  if (exp.getType() == null || !exp.getType().equals(stringType)) {
    Messages.showErrorDialog("String_Node_Str","String_Node_Str");
    return;
  }
  final String key=getResourceName(javaFile);
  if (key == null)   return;
  final StringBuilder propertyValue=new StringBuilder();
  final StringBuilder expression=new StringBuilder();
  new Runnable(){
    int numArgs=0;
    public void run(){
      process(exp);
    }
    private void process(    PsiElement exp){
      if (exp instanceof PsiLiteralExpression) {
        PsiLiteralExpression lit=(PsiLiteralExpression)exp;
        if (lit.getType().equals(stringType)) {
          escapeAndAppend(lit.getValue().toString());
          return;
        }
      }
      if (exp instanceof PsiBinaryExpression) {
        PsiBinaryExpression binExp=(PsiBinaryExpression)exp;
        if (binExp.getOperationTokenType() == JavaTokenType.PLUS) {
          process(binExp.getLOperand());
          process(binExp.getROperand());
          return;
        }
      }
      propertyValue.append('{').append(numArgs++).append('}');
      if (expression.length() > 0)       expression.append(',');
      expression.append(exp.getText());
    }
    /** 
 * Takes the literal string value and appends that to <tt>propertyValue</tt> with proper escaping.
 */
    private void escapeAndAppend(    String value){
      for (      char ch : value.toCharArray()) {
switch (ch) {
case '\'':
          propertyValue.append("String_Node_Str");
        break;
case '{':
case '}':
      propertyValue.append('\'').append(ch).append('\'');
    break;
default :
  propertyValue.append(ch);
}
}
}
}
.run();
ApplicationManager.getApplication().runWriteAction(new Runnable(){
public void run(){
try {
propsFile.addPropertyAfter(PropertiesElementFactory.createProperty(project,key,propertyValue.toString()),findAnchor(propsFile,key));
}
 catch (IncorrectOperationException x) {
Messages.showErrorDialog(x.getMessage(),"String_Node_Str");
return;
}
expression.insert(0,"String_Node_Str" + toJavaIdentifier(key) + "String_Node_Str");
expression.append("String_Node_Str");
TextRange tr=exp.getTextRange();
editor.getDocument().deleteString(tr.getStartOffset(),tr.getEndOffset());
EditorModificationUtil.insertStringAtCaret(editor,expression.toString());
}
private Property findAnchor(PropertiesFile propsFile,String key){
List<Property> list=propsFile.getProperties();
for (int i=0; i < list.size() - 1; i++) {
Property prev=list.get(i);
Property next=list.get(i + 1);
if (prev.getKey().compareTo(key) < 0 && key.compareTo(next.getKey()) < 0) return prev;
}
if (list.isEmpty()) return null;
return list.get(list.size() - 1);
}
}
);
}

Fixed version (ground truth):
public void execute(final Editor editor,DataContext dataContext){
  if (editor == null)   return;
  SelectionModel selectionModel=editor.getSelectionModel();
  final Project project=editor.getProject();
  if (project == null)   return;
  PsiDocumentManager psiManager=PsiDocumentManager.getInstance(project);
  PsiFile psiFile=psiManager.getPsiFile(editor.getDocument());
  if (!(psiFile instanceof PsiJavaFile)) {
    return;
  }
  PsiJavaFile javaFile=(PsiJavaFile)psiFile;
  PsiFile props=findMessagesDotProperties(project,javaFile);
  if (props == null) {
    Messages.showErrorDialog("String_Node_Str","String_Node_Str");
    return;
  }
  if (!(props instanceof PropertiesFile)) {
    Messages.showErrorDialog("String_Node_Str","String_Node_Str");
    return;
  }
  final PropertiesFile propsFile=(PropertiesFile)props;
  PsiElement e=findSelectedPsiElement(selectionModel,javaFile);
  while (e != null) {
    if (e instanceof PsiExpression)     break;
    e=e.getParent();
  }
  if (e == null) {
    Messages.showErrorDialog("String_Node_Str","String_Node_Str");
    return;
  }
  final PsiExpression exp=(PsiExpression)e;
  final PsiClassType stringType=PsiType.getJavaLangString(PsiManager.getInstance(project),e.getResolveScope());
  if (exp.getType() == null || !exp.getType().equals(stringType)) {
    Messages.showErrorDialog("String_Node_Str","String_Node_Str");
    return;
  }
  final String key=getResourceName(javaFile);
  if (key == null)   return;
  final StringBuilder propertyValue=new StringBuilder();
  final StringBuilder expression=new StringBuilder();
  new Runnable(){
    int numArgs=0;
    public void run(){
      process(exp);
    }
    private void process(    PsiElement exp){
      if (exp instanceof PsiLiteralExpression) {
        PsiLiteralExpression lit=(PsiLiteralExpression)exp;
        if (lit.getType().equals(stringType)) {
          escapeAndAppend(lit.getValue().toString());
          return;
        }
      }
      if (exp instanceof PsiBinaryExpression) {
        PsiBinaryExpression binExp=(PsiBinaryExpression)exp;
        if (binExp.getOperationTokenType() == JavaTokenType.PLUS) {
          process(binExp.getLOperand());
          process(binExp.getROperand());
          return;
        }
      }
      propertyValue.append('{').append(numArgs++).append('}');
      if (expression.length() > 0)       expression.append(',');
      expression.append(exp.getText());
    }
    /** 
 * Takes the literal string value and appends that to <tt>propertyValue</tt> with proper escaping.
 */
    private void escapeAndAppend(    String value){
      for (      char ch : value.toCharArray()) {
switch (ch) {
case '\'':
          propertyValue.append("String_Node_Str");
        break;
case '{':
case '}':
      propertyValue.append('\'').append(ch).append('\'');
    break;
case ' ':
  if (propertyValue.length() == 0)   propertyValue.append('\\');
default :
propertyValue.append(ch);
}
}
}
}
.run();
ApplicationManager.getApplication().runWriteAction(new Runnable(){
public void run(){
try {
propsFile.addPropertyAfter(PropertiesElementFactory.createProperty(project,key,propertyValue.toString()),findAnchor(propsFile,key));
}
 catch (IncorrectOperationException x) {
Messages.showErrorDialog(x.getMessage(),"String_Node_Str");
return;
}
expression.insert(0,"String_Node_Str" + toJavaIdentifier(key) + "String_Node_Str");
expression.append("String_Node_Str");
TextRange tr=exp.getTextRange();
editor.getDocument().deleteString(tr.getStartOffset(),tr.getEndOffset());
EditorModificationUtil.insertStringAtCaret(editor,expression.toString());
}
private Property findAnchor(PropertiesFile propsFile,String key){
List<Property> list=propsFile.getProperties();
for (int i=0; i < list.size() - 1; i++) {
Property prev=list.get(i);
Property next=list.get(i + 1);
if (prev.getKey().compareTo(key) < 0 && key.compareTo(next.getKey()) < 0) return prev;
}
if (list.isEmpty()) return null;
return list.get(list.size() - 1);
}
}
);
}