Program: 5464
Project: 5464
Buggy source:
/** 
 * Insert a links's reading from it's capabilities and make the appropriate relations such as Link-Reading , Capability-reading
 * @param sourceId , link's source id.
 * @param targetId , target's source id.
 * @param capabilityName , capability's id.
 * @param rssiValue , the RSSI value of the link.
 * @param readingValue , value of a sensor reading.
 * @param timestamp , a timestamp.
 * @throws UnknownNodeIdException , cannot find node by id exception.
 * @throws UnknownCapabilityIdException , cannot find capability by id exception.
 */
public void insertReading(final String sourceId,final String targetId,final String capabilityName,final double readingValue,final double rssiValue,final Date timestamp) throws UnknownNodeIdException, UnknownCapabilityIdException {
  Node source=NodeController.getInstance().getByID(sourceId);
  if (source == null)   throw new UnknownNodeIdException(sourceId);
  Node target=NodeController.getInstance().getByID(targetId);
  if (target == null)   throw new UnknownNodeIdException(targetId);
  Link link=LinkController.getInstance().getByID(sourceId,targetId);
  if (link == null) {
    link=new Link();
    link.setSource(sourceId);
    link.setTarget(sourceId);
    link.setEncrypted(false);
    link.setVirtual(false);
    Rssi rssi=new Rssi();
    rssi.setDatatype("String_Node_Str");
    rssi.setUnit("String_Node_Str");
    rssi.setValue("String_Node_Str");
    link.setRssi(rssi);
    link.setSetup(source.getSetup());
    LinkController.getInstance().add(link);
  }
  Capability capability=CapabilityController.getInstance().getByID(capabilityName);
  if (capability == null) {
    capability=new Capability();
    capability.setName(capabilityName);
    capability.setDatatype("String_Node_Str");
    capability.setDefaultvalue("String_Node_Str");
    capability.setUnit("String_Node_Str");
    CapabilityController.getInstance().add(capability);
  }
  if (link.getCapabilities() == null) {
    link.setCapabilities(new ArrayList<Capability>());
  }
  if (!link.getCapabilities().contains(capability)) {
    link.getCapabilities().add(capability);
  }
  if (capability.getLinks() == null) {
    capability.setLinks(new HashSet<Link>());
  }
  capability.getLinks().add(link);
  LinkController.getInstance().update(link);
  LinkReading reading=new LinkReading();
  reading.setLink(link);
  reading.setCapability(capability);
  reading.setReading(readingValue);
  reading.setRssiValue(rssiValue);
  reading.setTimestamp(timestamp);
  if (link.getReadings() == null) {
    link.setReadings(new HashSet<LinkReading>());
  }
  link.getReadings().add(reading);
  if (capability.getLinkReadings() == null) {
    capability.setLinkReadings(new HashSet<LinkReading>());
  }
  capability.getLinkReadings().add(reading);
  LinkReadingController.getInstance().add(reading);
}

Fixed version (ground truth):
/** 
 * Insert a links's reading from it's capabilities and make the appropriate relations such as Link-Reading , Capability-reading
 * @param sourceId , link's source id.
 * @param targetId , target's source id.
 * @param capabilityName , capability's id.
 * @param rssiValue , the RSSI value of the link.
 * @param readingValue , value of a sensor reading.
 * @param timestamp , a timestamp.
 * @throws UnknownNodeIdException , cannot find node by id exception.
 * @throws UnknownCapabilityIdException , cannot find capability by id exception.
 */
public void insertReading(final String sourceId,final String targetId,final String capabilityName,final double readingValue,final double rssiValue,final Date timestamp) throws UnknownNodeIdException, UnknownCapabilityIdException {
  Node source=NodeController.getInstance().getByID(sourceId);
  if (source == null)   throw new UnknownNodeIdException(sourceId);
  Node target=NodeController.getInstance().getByID(targetId);
  if (target == null)   throw new UnknownNodeIdException(targetId);
  Link link=LinkController.getInstance().getByID(sourceId,targetId);
  if (link == null) {
    link=new Link();
    link.setSource(sourceId);
    link.setTarget(targetId);
    link.setEncrypted(false);
    link.setVirtual(false);
    Rssi rssi=new Rssi();
    rssi.setDatatype("String_Node_Str");
    rssi.setUnit("String_Node_Str");
    rssi.setValue("String_Node_Str");
    link.setRssi(rssi);
    source.getSetup().getLink().add(link);
    link.setSetup(source.getSetup());
    LinkController.getInstance().add(link);
  }
  Capability capability=CapabilityController.getInstance().getByID(capabilityName);
  if (capability == null) {
    capability=new Capability();
    capability.setName(capabilityName);
    capability.setDatatype("String_Node_Str");
    capability.setDefaultvalue("String_Node_Str");
    capability.setUnit("String_Node_Str");
    CapabilityController.getInstance().add(capability);
  }
  if (link.getCapabilities() == null) {
    link.setCapabilities(new ArrayList<Capability>());
  }
  if (!link.getCapabilities().contains(capability)) {
    link.getCapabilities().add(capability);
  }
  if (capability.getLinks() == null) {
    capability.setLinks(new HashSet<Link>());
  }
  capability.getLinks().add(link);
  LinkController.getInstance().update(link);
  LinkReading reading=new LinkReading();
  reading.setLink(link);
  reading.setCapability(capability);
  reading.setReading(readingValue);
  reading.setRssiValue(rssiValue);
  reading.setTimestamp(timestamp);
  if (link.getReadings() == null) {
    link.setReadings(new HashSet<LinkReading>());
  }
  link.getReadings().add(reading);
  if (capability.getLinkReadings() == null) {
    capability.setLinkReadings(new HashSet<LinkReading>());
  }
  capability.getLinkReadings().add(reading);
  LinkReadingController.getInstance().add(reading);
}