Program: 14325
Project: 14325
Buggy source:
@Override public void fireEvent(final ClockTick event){
  if (Bootstrap.isFinished() && Topology.isEnabledLocally(LoadBalancing.class) && Topology.isEnabled(Eucalyptus.class)) {
    final EntityTransaction db=Entities.get(LoadBalancerServoInstance.class);
    final LoadBalancerServoInstance sample=LoadBalancerServoInstance.withState(LoadBalancerServoInstance.STATE.Pending.name());
    List<LoadBalancerServoInstance> instances=null;
    try {
      instances=Entities.query(sample);
      db.commit();
    }
 catch (    NoSuchElementException ex) {
      db.rollback();
    }
catch (    Exception ex) {
      db.rollback();
      LOG.warn("String_Node_Str");
    }
    if (instances == null || instances.size() == 0)     return;
    final List<String> param=Lists.newArrayList();
    final Map<String,String> latestState=Maps.newHashMap();
    final Map<String,String> addressMap=Maps.newHashMap();
    for (    final LoadBalancerServoInstance instance : instances) {
      String instanceId=instance.getInstanceId();
      if (instanceId == null || !instanceId.startsWith("String_Node_Str"))       continue;
      param.clear();
      param.add(instanceId);
      String instanceState=null;
      String address=null;
      try {
        final List<RunningInstancesItemType> result=EucalyptusActivityTasks.getInstance().describeInstances(param);
        if (result.isEmpty())         throw new Exception("String_Node_Str");
        instanceState=result.get(0).getStateName();
        address=result.get(0).getIpAddress();
      }
 catch (      final Exception ex) {
        LOG.warn("String_Node_Str",ex);
        continue;
      }
      if (instanceState.equals("String_Node_Str")) {
        latestState.put(instanceId,LoadBalancerServoInstance.STATE.InService.name());
        if (address != null)         addressMap.put(instanceId,address);
      }
 else       if (instanceState.equals("String_Node_Str")) {
        latestState.put(instanceId,LoadBalancerServoInstance.STATE.Pending.name());
      }
 else {
        latestState.put(instanceId,LoadBalancerServoInstance.STATE.Error.name());
      }
    }
    List<LoadBalancerServoInstance> newInServiceInstances=Lists.newArrayList();
    for (    final String instanceId : latestState.keySet()) {
      String nextState=latestState.get(instanceId);
      if (nextState == "String_Node_Str")       continue;
      final EntityTransaction dbUpdate=Entities.get(LoadBalancerServoInstance.class);
      try {
        final LoadBalancerServoInstance instance=Entities.uniqueResult(LoadBalancerServoInstance.named(instanceId));
        instance.setState(Enum.valueOf(LoadBalancerServoInstance.STATE.class,nextState));
        if (addressMap.containsKey(instanceId))         instance.setAddress(addressMap.get(instanceId));
        Entities.persist(instance);
        dbUpdate.commit();
        if (nextState.equals(LoadBalancerServoInstance.STATE.InService.name()))         newInServiceInstances.add(instance);
      }
 catch (      NoSuchElementException ex) {
        dbUpdate.rollback();
        LOG.error("String_Node_Str" + instanceId,ex);
      }
catch (      Exception ex) {
        dbUpdate.rollback();
        LOG.error("String_Node_Str" + instanceId + "String_Node_Str",ex);
      }
    }
    for (    LoadBalancerServoInstance servo : newInServiceInstances) {
      final LoadBalancer lb=servo.getAvailabilityZone().getLoadbalancer();
      final LoadBalancerDnsRecord dns=lb.getDns();
      try {
        EucalyptusActivityTasks.getInstance().addARecord(dns.getZone(),dns.getName(),servo.getAddress());
      }
 catch (      Exception ex) {
        LOG.error("String_Node_Str",ex);
        continue;
      }
      final EntityTransaction db2=Entities.get(LoadBalancerServoInstance.class);
      try {
        LoadBalancerServoInstance update=Entities.uniqueResult(servo);
        update.setDns(dns);
        Entities.persist(update);
        db2.commit();
      }
 catch (      Exception ex) {
        db2.rollback();
        LOG.error("String_Node_Str");
      }
    }
  }
}

Fixed version (ground truth):
@Override public void fireEvent(final ClockTick event){
  if (Bootstrap.isFinished() && Topology.isEnabledLocally(LoadBalancing.class) && Topology.isEnabled(Eucalyptus.class)) {
    final EntityTransaction db=Entities.get(LoadBalancerServoInstance.class);
    final LoadBalancerServoInstance sample=LoadBalancerServoInstance.withState(LoadBalancerServoInstance.STATE.Pending.name());
    List<LoadBalancerServoInstance> instances=null;
    try {
      instances=Entities.query(sample);
      db.commit();
    }
 catch (    NoSuchElementException ex) {
      db.rollback();
    }
catch (    Exception ex) {
      db.rollback();
      LOG.warn("String_Node_Str");
    }
    if (instances == null || instances.size() == 0)     return;
    final List<String> param=Lists.newArrayList();
    final Map<String,String> latestState=Maps.newHashMap();
    final Map<String,String> addressMap=Maps.newHashMap();
    for (    final LoadBalancerServoInstance instance : instances) {
      String instanceId=instance.getInstanceId();
      if (instanceId == null || !instanceId.startsWith("String_Node_Str"))       continue;
      param.clear();
      param.add(instanceId);
      String instanceState=null;
      String address=null;
      try {
        final List<RunningInstancesItemType> result=EucalyptusActivityTasks.getInstance().describeSystemInstances(param);
        if (result.isEmpty())         throw new Exception("String_Node_Str");
        instanceState=result.get(0).getStateName();
        address=result.get(0).getIpAddress();
      }
 catch (      final Exception ex) {
        LOG.warn("String_Node_Str",ex);
        continue;
      }
      if (instanceState.equals("String_Node_Str")) {
        latestState.put(instanceId,LoadBalancerServoInstance.STATE.InService.name());
        if (address != null)         addressMap.put(instanceId,address);
      }
 else       if (instanceState.equals("String_Node_Str")) {
        latestState.put(instanceId,LoadBalancerServoInstance.STATE.Pending.name());
      }
 else {
        latestState.put(instanceId,LoadBalancerServoInstance.STATE.Error.name());
      }
    }
    List<LoadBalancerServoInstance> newInServiceInstances=Lists.newArrayList();
    for (    final String instanceId : latestState.keySet()) {
      String nextState=latestState.get(instanceId);
      if (nextState == "String_Node_Str")       continue;
      final EntityTransaction dbUpdate=Entities.get(LoadBalancerServoInstance.class);
      try {
        final LoadBalancerServoInstance instance=Entities.uniqueResult(LoadBalancerServoInstance.named(instanceId));
        instance.setState(Enum.valueOf(LoadBalancerServoInstance.STATE.class,nextState));
        if (addressMap.containsKey(instanceId))         instance.setAddress(addressMap.get(instanceId));
        Entities.persist(instance);
        dbUpdate.commit();
        if (nextState.equals(LoadBalancerServoInstance.STATE.InService.name()))         newInServiceInstances.add(instance);
      }
 catch (      NoSuchElementException ex) {
        dbUpdate.rollback();
        LOG.error("String_Node_Str" + instanceId,ex);
      }
catch (      Exception ex) {
        dbUpdate.rollback();
        LOG.error("String_Node_Str" + instanceId + "String_Node_Str",ex);
      }
    }
    for (    LoadBalancerServoInstance servo : newInServiceInstances) {
      final LoadBalancer lb=servo.getAvailabilityZone().getLoadbalancer();
      final LoadBalancerDnsRecord dns=lb.getDns();
      try {
        EucalyptusActivityTasks.getInstance().addARecord(dns.getZone(),dns.getName(),servo.getAddress());
      }
 catch (      Exception ex) {
        LOG.error("String_Node_Str",ex);
        continue;
      }
      final EntityTransaction db2=Entities.get(LoadBalancerServoInstance.class);
      try {
        LoadBalancerServoInstance update=Entities.uniqueResult(servo);
        update.setDns(dns);
        Entities.persist(update);
        db2.commit();
      }
 catch (      Exception ex) {
        db2.rollback();
        LOG.error("String_Node_Str");
      }
    }
  }
}