Program: 112178
Project: 112178
Buggy source:
public void activateAndRegisterSubscriptionIfRequired(final IBaseResource theSubscription){
  boolean subscriptionTypeApplies=BaseSubscriptionSubscriber.subscriptionTypeApplies(myCtx,theSubscription,myChannelType);
  if (subscriptionTypeApplies == false) {
    return;
  }
  final IPrimitiveType<?> status=myCtx.newTerser().getSingleValueOrNull(theSubscription,BaseSubscriptionInterceptor.SUBSCRIPTION_STATUS,IPrimitiveType.class);
  String statusString=status.getValueAsString();
  final String requestedStatus=Subscription.SubscriptionStatus.REQUESTED.toCode();
  final String activeStatus=Subscription.SubscriptionStatus.ACTIVE.toCode();
  if (requestedStatus.equals(statusString)) {
    if (TransactionSynchronizationManager.isSynchronizationActive()) {
      TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter(){
        @Override public void afterCommit(){
          activateSubscription(status,activeStatus,theSubscription,requestedStatus);
        }
      }
);
    }
 else {
      activateSubscription(status,activeStatus,theSubscription,requestedStatus);
    }
  }
 else   if (activeStatus.equals(statusString)) {
    if (!mySubscriptionInterceptor.hasSubscription(theSubscription.getIdElement())) {
      ourLog.info("String_Node_Str",theSubscription.getIdElement().toUnqualified().getValue());
    }
    mySubscriptionInterceptor.registerSubscription(theSubscription.getIdElement(),theSubscription);
  }
 else {
    if (mySubscriptionInterceptor.hasSubscription(theSubscription.getIdElement())) {
      ourLog.info("String_Node_Str",statusString,theSubscription.getIdElement().toUnqualified().getValue());
    }
    mySubscriptionInterceptor.unregisterSubscription(theSubscription.getIdElement());
  }
}

Fixed version (ground truth):
public void activateAndRegisterSubscriptionIfRequired(final IBaseResource theSubscription){
  boolean subscriptionTypeApplies=BaseSubscriptionSubscriber.subscriptionTypeApplies(myCtx,theSubscription,myChannelType);
  if (subscriptionTypeApplies == false) {
    return;
  }
  final IPrimitiveType<?> status=myCtx.newTerser().getSingleValueOrNull(theSubscription,BaseSubscriptionInterceptor.SUBSCRIPTION_STATUS,IPrimitiveType.class);
  String statusString=status.getValueAsString();
  final String requestedStatus=Subscription.SubscriptionStatus.REQUESTED.toCode();
  final String activeStatus=Subscription.SubscriptionStatus.ACTIVE.toCode();
  if (requestedStatus.equals(statusString)) {
    if (TransactionSynchronizationManager.isSynchronizationActive()) {
      TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter(){
        @Override public void afterCommit(){
          Future<?> activationFuture=myTaskExecutor.submit(new Runnable(){
            @Override public void run(){
              activateSubscription(activeStatus,theSubscription,requestedStatus);
            }
          }
);
          if (ourWaitForSubscriptionActivationSynchronouslyForUnitTest) {
            try {
              activationFuture.get(5,TimeUnit.SECONDS);
            }
 catch (            Exception e) {
              ourLog.error("String_Node_Str",e);
            }
          }
        }
      }
);
    }
 else {
      activateSubscription(activeStatus,theSubscription,requestedStatus);
    }
  }
 else   if (activeStatus.equals(statusString)) {
    if (!mySubscriptionInterceptor.hasSubscription(theSubscription.getIdElement())) {
      ourLog.info("String_Node_Str",theSubscription.getIdElement().toUnqualified().getValue());
    }
    mySubscriptionInterceptor.registerSubscription(theSubscription.getIdElement(),theSubscription);
  }
 else {
    if (mySubscriptionInterceptor.hasSubscription(theSubscription.getIdElement())) {
      ourLog.info("String_Node_Str",statusString,theSubscription.getIdElement().toUnqualified().getValue());
    }
    mySubscriptionInterceptor.unregisterSubscription(theSubscription.getIdElement());
  }
}