Program: 78944
Project: 78944
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=newElement(baseElement.getElement().getElementName(),name);
    childElement.setExtends(baseElement);
    childElement.getElement().refreshStructureFromParent(module);
    return childElement;
  }
  Module root=baseElement.getModule();
  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.getDefn()) {
      throw new ExtendsException(null,baseElement.getName(),ExtendsException.DESIGN_EXCEPTION_NOT_FOUND);
    }
    DesignElementHandle 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 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=baseElement.getModule();
  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;
}