Program: 69239
Project: 69239
Buggy source:
/** 
 * Checks the current element name. Done when adding a newly created element where the element name is already set on the new element.
 * @param name the name to check.
 * @throws NameException if the element name is not allowed to change.
 */
public void checkName(String name) throws NameException {
  ElementDefn metaData=(ElementDefn)element.getDefn();
  if (name == null) {
    if (element.hasDerived() || element.hasReferences())     throw new NameException(element,name,NameException.DESIGN_EXCEPTION_HAS_REFERENCES);
    if (metaData.getNameOption() == MetaDataConstants.REQUIRED_NAME)     throw new NameException(element,name,NameException.DESIGN_EXCEPTION_NAME_REQUIRED);
    if ((module instanceof Library) && (element.getContainer() instanceof Library)) {
      throw new NameException(element,name,NameException.DESIGN_EXCEPTION_NAME_REQUIRED);
    }
  }
 else {
    PropertyDefn propDefn=(PropertyDefn)metaData.getProperty(IDesignElementModel.NAME_PROP);
    if (propDefn == null)     throw new NameException(element,name,NameException.DESIGN_EXCEPTION_NAME_FORBIDDEN);
    try {
      name=(String)propDefn.validateValue(module,name);
    }
 catch (    PropertyValueException e) {
      throw new NameException(element,name,NameException.DESIGN_EXCEPTION_INVALID_NAME);
    }
    if (element instanceof StyleElement) {
      if (!styleNamePattern.matcher(name).matches())       throw new NameException(element,name,NameException.DESIGN_EXCEPTION_INVALID_STYLE_NAME);
    }
    if (!isNameValidInContext(name))     throw new NameException(element,name,NameException.DESIGN_EXCEPTION_DUPLICATE);
    if (metaData.getNameOption() == MetaDataConstants.NO_NAME)     throw new NameException(element,name,NameException.DESIGN_EXCEPTION_NAME_FORBIDDEN);
    if (!element.isManagedByNameSpace()) {
      return;
    }
    DesignElement existedElement=new NameExecutor(element).getNameSpace(module).getElement(name);
    if (existedElement != null)     throw new NameException(element,name,NameException.DESIGN_EXCEPTION_DUPLICATE);
  }
}

Fixed version (ground truth):
/** 
 * Checks the current element name. Done when adding a newly created element where the element name is already set on the new element.
 * @param name the name to check.
 * @throws NameException if the element name is not allowed to change.
 */
public void checkName(String name) throws NameException {
  ElementDefn metaData=(ElementDefn)element.getDefn();
  if (name == null) {
    if (element.hasDerived() || element.hasReferences())     throw new NameException(element,null,NameException.DESIGN_EXCEPTION_HAS_REFERENCES);
    if (metaData.getNameOption() == MetaDataConstants.REQUIRED_NAME)     throw new NameException(element,null,NameException.DESIGN_EXCEPTION_NAME_REQUIRED);
    if ((module instanceof Library) && (element.getContainer() instanceof Library)) {
      throw new NameException(element,null,NameException.DESIGN_EXCEPTION_NAME_REQUIRED);
    }
  }
 else {
    PropertyDefn propDefn=(PropertyDefn)metaData.getProperty(IDesignElementModel.NAME_PROP);
    if (propDefn == null)     throw new NameException(element,name,NameException.DESIGN_EXCEPTION_NAME_FORBIDDEN);
    try {
      name=(String)propDefn.validateValue(module,name);
    }
 catch (    PropertyValueException e) {
      throw new NameException(element,name,NameException.DESIGN_EXCEPTION_INVALID_NAME);
    }
    if (element instanceof StyleElement) {
      if (!styleNamePattern.matcher(name).matches())       throw new NameException(element,name,NameException.DESIGN_EXCEPTION_INVALID_STYLE_NAME);
    }
    if (!isNameValidInContext(name))     throw new NameException(element,name,NameException.DESIGN_EXCEPTION_DUPLICATE);
    if (metaData.getNameOption() == MetaDataConstants.NO_NAME)     throw new NameException(element,name,NameException.DESIGN_EXCEPTION_NAME_FORBIDDEN);
    if (!element.isManagedByNameSpace()) {
      return;
    }
    DesignElement existedElement=new NameExecutor(element).getNameSpace(module).getElement(name);
    if (existedElement != null)     throw new NameException(element,name,NameException.DESIGN_EXCEPTION_DUPLICATE);
  }
}