Program: 78800
Project: 78800
Buggy source:
/** 
 * Creates one new element based on the given element. The new element will extends the given one. The element must be extendable.
 * @param baseElement the base element.
 * @param name the optional new element name
 * @return the handle to the new element.
 * @throws ExtendsException if the the base element is in a library that is not included in this module, or if the "extends" relationship is illegal
 */
public DesignElementHandle newElementFrom(DesignElementHandle baseElement,String name) throws ExtendsException {
  if (baseElement == null)   return null;
  if (baseElement.getRoot().getElement() == module) {
    DesignElementHandle childElement=null;
    if (baseElement instanceof ExtendedItemHandle) {
      String extensionName=baseElement.getStringProperty(ExtendedItem.EXTENSION_NAME_PROP);
      childElement=this.newExtendedItem(name,extensionName,(ExtendedItemHandle)baseElement);
      childElement.getElement().refreshStructureFromParent(module);
    }
 else {
      childElement=newElement(baseElement.getElement().getElementName(),name);
      childElement.setExtends(baseElement);
      childElement.getElement().refreshStructureFromParent(module);
    }
    return childElement;
  }
  Module root=(Module)baseElement.getRoot().getElement();
  if (root instanceof Library) {
    Library lib=module.getLibraryByLocation(root.getLocation());
    if (lib == null) {
      throw new ExtendsException(null,baseElement.getElement(),ExtendsException.DESIGN_EXCEPTION_PARENT_NOT_INCLUDE);
    }
    DesignElement base=lib.getElementByID(baseElement.getID());
    if (base == null || base.getDefn() != baseElement.getElement().getDefn()) {
      throw new ExtendsException(null,baseElement.getName(),ExtendsException.DESIGN_EXCEPTION_NOT_FOUND);
    }
    DesignElementHandle childElement=null;
    if (baseElement instanceof ExtendedItemHandle) {
      String extensionName=baseElement.getStringProperty(ExtendedItem.EXTENSION_NAME_PROP);
      childElement=this.newExtendedItem(name,extensionName,(ExtendedItemHandle)base.getHandle(lib));
      childElement.getElement().refreshStructureFromParent(module);
    }
 else {
      childElement=newElement(base.getElementName(),name);
      childElement.setExtends(base.getHandle(lib));
      childElement.getElement().refreshStructureFromParent(module);
    }
    return childElement;
  }
  return null;
}

Fixed version (ground truth):
/** 
 * Creates one new element based on the given element. The new element will extends the given one. The element must be extendable.
 * @param name the optional new element name
 * @param baseElement the base element
 * @return the handle to the new element.
 * @throws ExtendsException if the "extends" relationship is illegal
 */
private DesignElementHandle newElementFrom(String name,DesignElementHandle baseElement) throws ExtendsException {
  DesignElementHandle childElement=null;
  if (baseElement instanceof ExtendedItemHandle) {
    String extensionName=baseElement.getStringProperty(ExtendedItem.EXTENSION_NAME_PROP);
    childElement=newExtendedItem(name,extensionName,(ExtendedItemHandle)baseElement);
    childElement.getElement().refreshStructureFromParent(module);
  }
 else {
    childElement=newElement(baseElement.getElement().getElementName(),name);
    if (childElement.getElement() instanceof IOdaExtendableElementModel) {
      String extensionId=(String)baseElement.getProperty(IOdaExtendableElementModel.EXTENSION_ID_PROP);
      childElement.getElement().setProperty(IOdaExtendableElementModel.EXTENSION_ID_PROP,extensionId);
    }
    childElement.setExtends(baseElement);
    childElement.getElement().refreshStructureFromParent(module);
  }
  return childElement;
}