Program: 79015
Project: 79015
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.getModule() == this.module) {
    DesignElementHandle childElement=newElement(baseElement.getElement().getElementName(),name);
    childElement.setExtends(baseElement);
    childElement.getElement().refreshStructureFromParent();
    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();
    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.getModule() == this.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;
}