Program: 73219
Project: 73219
Buggy source:
/** 
 * Add a new entry to this query that represents the given attribute. The name of the entry will be set to the name of the attribute, and the attribute will be attached to the entry, so that if the attribute is updated, then the entry is updated. If the attribute contains an instance of ParameterEditorStyle, then defer to the style to create the entry, otherwise just create a default entry. The style used in a default entry depends on the class of the attribute and on its declared type, but defaults to a one-line entry if there is no obviously better style. Only the first style that is found is used to create an entry.
 * @param attribute The attribute to create an entry for.
 */
public void addStyledEntry(Settable attribute){
  boolean foundStyle=false;
  try {
    _addingStyledEntryFor=attribute;
    if (attribute instanceof NamedObj) {
      Iterator<?> styles=((NamedObj)attribute).attributeList(ParameterEditorStyle.class).iterator();
      while (styles.hasNext() && !foundStyle) {
        ParameterEditorStyle style=(ParameterEditorStyle)styles.next();
        try {
          style.addEntry(this);
          foundStyle=true;
        }
 catch (        IllegalActionException ex) {
        }
      }
    }
    if (!foundStyle) {
      String name=attribute.getName();
      String displayName=attribute.getDisplayName();
      try {
        JComponent component=null;
        if (attribute instanceof IntRangeParameter) {
          int current=((IntRangeParameter)attribute).getCurrentValue();
          int min=((IntRangeParameter)attribute).getMinValue();
          int max=((IntRangeParameter)attribute).getMaxValue();
          component=addSlider(name,displayName,current,min,max);
          attachParameter(attribute,name);
          foundStyle=true;
        }
 else         if (attribute instanceof DoubleRangeParameter) {
          double current=((DoubleToken)((DoubleRangeParameter)attribute).getToken()).doubleValue();
          double max=((DoubleToken)((DoubleRangeParameter)attribute).max.getToken()).doubleValue();
          double min=((DoubleToken)((DoubleRangeParameter)attribute).min.getToken()).doubleValue();
          int precision=((IntToken)((DoubleRangeParameter)attribute).precision.getToken()).intValue();
          int quantized=((int)Math.round(((current - min) * precision) / (max - min)));
          component=addSlider(name,displayName,quantized,0,precision);
          attachParameter(attribute,name);
          foundStyle=true;
        }
 else         if (attribute instanceof ColorAttribute) {
          component=addColorChooser(name,displayName,attribute.getExpression());
          attachParameter(attribute,name);
          foundStyle=true;
        }
 else         if (attribute instanceof CustomQueryBoxParameter) {
          JLabel label=new JLabel(displayName + "String_Node_Str");
          label.setBackground(_background);
          component=((CustomQueryBoxParameter)attribute).createQueryBox(this,attribute);
          _addPair(name,label,component,component);
          attachParameter(attribute,name);
          foundStyle=true;
        }
 else         if (attribute instanceof FileParameter || attribute instanceof FilePortParameter) {
          URI modelURI=URIAttribute.getModelURI((NamedObj)attribute);
          File directory=null;
          if (modelURI != null) {
            if (modelURI.getScheme().equals("String_Node_Str")) {
              File modelFile=new File(modelURI);
              directory=modelFile.getParentFile();
            }
          }
          URI base=null;
          if (directory != null) {
            base=directory.toURI();
          }
          boolean allowFiles=true;
          boolean allowDirectories=false;
          Parameter marker=(Parameter)((NamedObj)attribute).getAttribute("String_Node_Str",Parameter.class);
          if (marker != null) {
            Token value=marker.getToken();
            if (value instanceof BooleanToken) {
              allowFiles=((BooleanToken)value).booleanValue();
            }
          }
          marker=(Parameter)((NamedObj)attribute).getAttribute("String_Node_Str",Parameter.class);
          if (marker != null) {
            Token value=marker.getToken();
            if (value instanceof BooleanToken) {
              allowDirectories=((BooleanToken)value).booleanValue();
            }
          }
          if (!allowFiles && !allowDirectories) {
            return;
          }
          boolean isOutput=false;
          if (attribute instanceof FileParameter && ((FileParameter)attribute).isOutput()) {
            isOutput=true;
          }
          component=addFileChooser(name,displayName,attribute.getExpression(),base,directory,allowFiles,allowDirectories,isOutput,preferredBackgroundColor(attribute),preferredForegroundColor(attribute));
          attachParameter(attribute,name);
          foundStyle=true;
        }
 else         if (attribute instanceof PasswordAttribute) {
          component=addPassword(name,displayName,"String_Node_Str");
          attachParameter(attribute,name);
          foundStyle=true;
        }
 else         if (attribute instanceof Parameter && (((Parameter)attribute).getChoices() != null)) {
          Parameter castAttribute=(Parameter)attribute;
          component=addChoice(name,displayName,castAttribute.getChoices(),castAttribute.getExpression(),true,preferredBackgroundColor(attribute),preferredForegroundColor(attribute));
          attachParameter(attribute,name);
          foundStyle=true;
        }
 else         if ((attribute instanceof NamedObj) && ((((NamedObj)attribute).getAttribute("String_Node_Str") != null) || ((NamedObj)attribute).getAttribute("String_Node_Str") != null)) {
          int widthValue=30;
          int heightValue=10;
          Attribute widthAttribute=((NamedObj)attribute).getAttribute("String_Node_Str");
          if (widthAttribute instanceof Variable) {
            Token token=((Variable)widthAttribute).getToken();
            if (token instanceof IntToken) {
              widthValue=((IntToken)token).intValue();
            }
          }
          Attribute heightAttribute=((NamedObj)attribute).getAttribute("String_Node_Str");
          if (heightAttribute instanceof Variable) {
            Token token=((Variable)heightAttribute).getToken();
            if (token instanceof IntToken) {
              heightValue=((IntToken)token).intValue();
            }
          }
          component=addTextArea(name,displayName,attribute.getExpression(),preferredBackgroundColor(attribute),preferredForegroundColor(attribute),heightValue,widthValue);
          attachParameter(attribute,name);
          foundStyle=true;
        }
 else         if (attribute instanceof Variable) {
          Type declaredType=((Variable)attribute).getDeclaredType();
          Token current=((Variable)attribute).getToken();
          if (declaredType == BaseType.BOOLEAN) {
            if (attribute.getExpression().equals("String_Node_Str") || attribute.getExpression().equals("String_Node_Str")) {
              component=addCheckBox(name,displayName,((BooleanToken)current).booleanValue());
              attachParameter(attribute,name);
              foundStyle=true;
            }
          }
        }
        if (attribute.getVisibility() == Settable.NOT_EDITABLE) {
          if (component == null) {
            String defaultValue=attribute.getExpression();
            component=addDisplay(name,displayName,defaultValue);
            attachParameter(attribute,name);
            foundStyle=true;
          }
 else           if (component instanceof JTextComponent) {
            component.setBackground(_background);
            ((JTextComponent)component).setEditable(false);
          }
 else {
            component.setEnabled(false);
          }
        }
      }
 catch (      IllegalActionException ex) {
      }
    }
    String defaultValue=attribute.getExpression();
    if (defaultValue == null) {
      defaultValue="String_Node_Str";
    }
    if (!(foundStyle)) {
      addTextArea(attribute.getName(),attribute.getDisplayName(),defaultValue,preferredBackgroundColor(attribute),preferredForegroundColor(attribute),2,DEFAULT_ENTRY_WIDTH);
      attachParameter(attribute,attribute.getName());
    }
  }
  finally {
    _addingStyledEntryFor=null;
  }
}

Fixed version (ground truth):
/** 
 * Add a new entry to this query that represents the given attribute. The name of the entry will be set to the name of the attribute, and the attribute will be attached to the entry, so that if the attribute is updated, then the entry is updated. If the attribute contains an instance of ParameterEditorStyle, then defer to the style to create the entry, otherwise just create a default entry. The style used in a default entry depends on the class of the attribute and on its declared type, but defaults to a one-line entry if there is no obviously better style. Only the first style that is found is used to create an entry.
 * @param attribute The attribute to create an entry for.
 */
public void addStyledEntry(Settable attribute){
  boolean foundStyle=false;
  try {
    _addingStyledEntryFor=attribute;
    if (attribute instanceof NamedObj) {
      Iterator<?> styles=((NamedObj)attribute).attributeList(ParameterEditorStyle.class).iterator();
      while (styles.hasNext() && !foundStyle) {
        ParameterEditorStyle style=(ParameterEditorStyle)styles.next();
        try {
          style.addEntry(this);
          foundStyle=true;
        }
 catch (        IllegalActionException ex) {
        }
      }
    }
    if (!foundStyle) {
      String name=attribute.getName();
      String displayName=attribute.getDisplayName();
      try {
        JComponent component=null;
        if (attribute instanceof IntRangeParameter) {
          int current=((IntRangeParameter)attribute).getCurrentValue();
          int min=((IntRangeParameter)attribute).getMinValue();
          int max=((IntRangeParameter)attribute).getMaxValue();
          component=addSlider(name,displayName,current,min,max);
          attachParameter(attribute,name);
          foundStyle=true;
        }
 else         if (attribute instanceof DoubleRangeParameter) {
          double current=((DoubleToken)((DoubleRangeParameter)attribute).getToken()).doubleValue();
          double max=((DoubleToken)((DoubleRangeParameter)attribute).max.getToken()).doubleValue();
          double min=((DoubleToken)((DoubleRangeParameter)attribute).min.getToken()).doubleValue();
          int precision=((IntToken)((DoubleRangeParameter)attribute).precision.getToken()).intValue();
          int quantized=((int)Math.round(((current - min) * precision) / (max - min)));
          component=addSlider(name,displayName,quantized,0,precision);
          attachParameter(attribute,name);
          foundStyle=true;
        }
 else         if (attribute instanceof ColorAttribute) {
          component=addColorChooser(name,displayName,attribute.getExpression());
          attachParameter(attribute,name);
          foundStyle=true;
        }
 else         if (attribute instanceof CustomQueryBoxParameter) {
          JLabel label=new JLabel(displayName + "String_Node_Str");
          label.setBackground(_background);
          component=((CustomQueryBoxParameter)attribute).createQueryBox(this,attribute);
          _addPair(name,label,component,component);
          attachParameter(attribute,name);
          foundStyle=true;
        }
 else         if (attribute instanceof FileParameter || attribute instanceof FilePortParameter) {
          URI modelURI=URIAttribute.getModelURI((NamedObj)attribute);
          File directory=null;
          if (modelURI != null) {
            if (modelURI.getScheme().equals("String_Node_Str")) {
              File modelFile=new File(modelURI);
              directory=modelFile.getParentFile();
            }
          }
          URI base=null;
          if (directory != null) {
            base=directory.toURI();
          }
          boolean allowFiles=true;
          boolean allowDirectories=false;
          Parameter marker=(Parameter)((NamedObj)attribute).getAttribute("String_Node_Str",Parameter.class);
          if (marker != null) {
            Token value=marker.getToken();
            if (value instanceof BooleanToken) {
              allowFiles=((BooleanToken)value).booleanValue();
            }
          }
          marker=(Parameter)((NamedObj)attribute).getAttribute("String_Node_Str",Parameter.class);
          if (marker != null) {
            Token value=marker.getToken();
            if (value instanceof BooleanToken) {
              allowDirectories=((BooleanToken)value).booleanValue();
            }
          }
          if (!allowFiles && !allowDirectories) {
            return;
          }
          boolean isOutput=false;
          if (attribute instanceof FileParameter && ((FileParameter)attribute).isOutput()) {
            isOutput=true;
          }
          component=addFileChooser(name,displayName,attribute.getExpression(),base,directory,allowFiles,allowDirectories,isOutput,preferredBackgroundColor(attribute),preferredForegroundColor(attribute));
          attachParameter(attribute,name);
          foundStyle=true;
        }
 else         if (attribute instanceof PasswordAttribute) {
          component=addPassword(name,displayName,"String_Node_Str");
          attachParameter(attribute,name);
          foundStyle=true;
        }
 else         if (attribute instanceof Parameter && (((Parameter)attribute).getChoices() != null)) {
          Parameter castAttribute=(Parameter)attribute;
          component=addChoice(name,displayName,castAttribute.getChoices(),castAttribute.getExpression(),true,preferredBackgroundColor(attribute),preferredForegroundColor(attribute));
          attachParameter(attribute,name);
          foundStyle=true;
        }
 else         if ((attribute instanceof NamedObj) && ((((NamedObj)attribute).getAttribute("String_Node_Str") != null) || ((NamedObj)attribute).getAttribute("String_Node_Str") != null)) {
          int widthValue=30;
          int heightValue=10;
          Attribute widthAttribute=((NamedObj)attribute).getAttribute("String_Node_Str");
          if (widthAttribute instanceof Variable) {
            Token token=((Variable)widthAttribute).getToken();
            if (token instanceof IntToken) {
              widthValue=((IntToken)token).intValue();
            }
          }
          Attribute heightAttribute=((NamedObj)attribute).getAttribute("String_Node_Str");
          if (heightAttribute instanceof Variable) {
            Token token=((Variable)heightAttribute).getToken();
            if (token instanceof IntToken) {
              heightValue=((IntToken)token).intValue();
            }
          }
          component=addTextArea(name,displayName,attribute.getExpression(),preferredBackgroundColor(attribute),preferredForegroundColor(attribute),heightValue,widthValue);
          attachParameter(attribute,name);
          foundStyle=true;
        }
 else         if (attribute instanceof Variable) {
          Type declaredType=((Variable)attribute).getDeclaredType();
          Token current=((Variable)attribute).getToken();
          if (declaredType == BaseType.BOOLEAN) {
            if (attribute.getExpression().equals("String_Node_Str") || attribute.getExpression().equals("String_Node_Str")) {
              component=addCheckBox(name,displayName,((BooleanToken)current).booleanValue());
              attachParameter(attribute,name);
              foundStyle=true;
            }
          }
        }
        if (attribute.getVisibility() == Settable.NOT_EDITABLE) {
          if (component == null) {
            String defaultValue=attribute.getExpression();
            component=addDisplay(name,displayName,defaultValue);
            attachParameter(attribute,name);
            foundStyle=true;
          }
 else           if (component instanceof JTextComponent) {
            component.setBackground(_background);
            ((JTextComponent)component).setEditable(false);
          }
 else {
            component.setEnabled(false);
          }
        }
      }
 catch (      IllegalActionException ex) {
      }
    }
    String defaultValue=attribute.getExpression();
    if (defaultValue == null) {
      defaultValue="String_Node_Str";
    }
    if (!(foundStyle)) {
      JTextArea area=addTextArea(attribute.getName(),attribute.getDisplayName(),defaultValue,preferredBackgroundColor(attribute),preferredForegroundColor(attribute),1,DEFAULT_ENTRY_WIDTH);
      area.setRows(Math.min(5,area.getLineCount()));
      attachParameter(attribute,attribute.getName());
    }
  }
  finally {
    _addingStyledEntryFor=null;
  }
}