Program: 28099
Project: 28099
Buggy source:
private SingletonContextImpl createSingletonEJB() throws CreateException {
  EjbInvocation ejbInv=null;
  SingletonContextImpl context;
  Object ejb;
  boolean initGotToPreInvokeTx=false;
  boolean doPostConstruct=true;
  try {
    String sessionKey=clusteredLookup.getClusteredSessionKey();
    EjbSessionDescriptor sessDesc=(EjbSessionDescriptor)ejbDescriptor;
    if (clusteredLookup.isClusteredEnabled()) {
      IMap<String,Object> singletonMap=clusteredLookup.getClusteredSingletonMap();
      if (!singletonMap.containsKey(sessionKey)) {
        context=(SingletonContextImpl)createEjbInstanceAndContext();
        ejb=singletonMap.putIfAbsent(sessionKey,context.getEJB());
        if ((ejb != null) && (ejb != context.getEJB()) && sessDesc.dontCallPostConstructOnAttach()) {
          doPostConstruct=false;
        }
      }
 else {
        context=(SingletonContextImpl)_constructEJBContextImpl(singletonMap.get(sessionKey));
        ejb=context.getEJB();
        if (sessDesc.dontCallPostConstructOnAttach()) {
          doPostConstruct=false;
        }
      }
      clusteredLookup.getClusteredUsageCount().incrementAndGet();
    }
 else {
      if (sessDesc.isClustered() && !clusteredLookup.getHazelcastCore().isEnabled()) {
        _logger.log(Level.WARNING,"String_Node_Str",sessionKey);
      }
      context=(SingletonContextImpl)createEjbInstanceAndContext();
      ejb=context.getEJB();
    }
    ejbInv=createEjbInvocation(ejb,context);
    invocationManager.preInvoke(ejbInv);
    injectEjbInstance(context);
    if (isRemote) {
      if (hasRemoteBusinessView) {
        context.setEJBRemoteBusinessObjectImpl(theRemoteBusinessObjectImpl);
      }
    }
    if (isLocal) {
      if (hasLocalBusinessView) {
        context.setEJBLocalBusinessObjectImpl(theEJBLocalBusinessObjectImpl);
      }
      if (hasOptionalLocalBusinessView) {
        context.setOptionalEJBLocalBusinessObjectImpl(theOptionalEJBLocalBusinessObjectImpl);
      }
    }
    ejbInv.transactionAttribute=postConstructInvInfo.txAttr;
    ejbInv.invocationInfo=postConstructInvInfo;
    initGotToPreInvokeTx=true;
    preInvokeTx(ejbInv);
    context.setInstanceKey(singletonInstanceKey);
    if (doPostConstruct) {
      intercept(CallbackType.POST_CONSTRUCT,context);
    }
  }
 catch (  Throwable th) {
    if (ejbInv != null) {
      ejbInv.exception=th;
    }
    singletonInitializationFailed=true;
    CreateException creEx=new CreateException("String_Node_Str" + ejbDescriptor.getName());
    creEx.initCause(th);
    throw creEx;
  }
 finally {
    initializationInProgress=false;
    if (ejbInv != null) {
      try {
        invocationManager.postInvoke(ejbInv);
        if (initGotToPreInvokeTx) {
          postInvokeTx(ejbInv);
        }
      }
 catch (      Exception pie) {
        if (ejbInv.exception != null) {
          _logger.log(Level.WARNING,"String_Node_Str",pie);
        }
 else {
          ejbInv.exception=pie;
          singletonInitializationFailed=true;
          CreateException creEx=new CreateException("String_Node_Str" + ejbDescriptor.getName());
          creEx.initCause(pie);
          throw creEx;
        }
      }
    }
  }
  context.setState(EJBContextImpl.BeanState.POOLED);
  context.touch();
  return context;
}

Fixed version (ground truth):
private SingletonContextImpl createSingletonEJB() throws CreateException {
  EjbInvocation ejbInv=null;
  SingletonContextImpl context;
  Object ejb;
  boolean initGotToPreInvokeTx=false;
  boolean doPostConstruct=true;
  try {
    String sessionKey=clusteredLookup.getClusteredSessionKey();
    EjbSessionDescriptor sessDesc=(EjbSessionDescriptor)ejbDescriptor;
    if (clusteredLookup.isClusteredEnabled()) {
      IMap<String,Object> singletonMap=clusteredLookup.getClusteredSingletonMap();
      if (!singletonMap.containsKey(sessionKey)) {
        context=(SingletonContextImpl)createEjbInstanceAndContext();
        ejb=singletonMap.putIfAbsent(sessionKey,context.getEJB());
        if ((ejb != null) && (ejb != context.getEJB()) && sessDesc.dontCallPostConstructOnAttach()) {
          doPostConstruct=false;
        }
      }
 else {
        context=(SingletonContextImpl)_constructEJBContextImpl(singletonMap.get(sessionKey));
        ejb=context.getEJB();
        createEmptyContextAndInterceptors(context);
        if (isJCDIEnabled()) {
          _createJCDIInjectionContext(context,ejb,context.getJCDIInjectionContext());
        }
        if (sessDesc.dontCallPostConstructOnAttach()) {
          doPostConstruct=false;
        }
      }
      clusteredLookup.getClusteredUsageCount().incrementAndGet();
    }
 else {
      if (sessDesc.isClustered() && !clusteredLookup.getHazelcastCore().isEnabled()) {
        _logger.log(Level.WARNING,"String_Node_Str",sessionKey);
      }
      context=(SingletonContextImpl)createEjbInstanceAndContext();
      ejb=context.getEJB();
    }
    ejbInv=createEjbInvocation(ejb,context);
    invocationManager.preInvoke(ejbInv);
    injectEjbInstance(context);
    if (isRemote) {
      if (hasRemoteBusinessView) {
        context.setEJBRemoteBusinessObjectImpl(theRemoteBusinessObjectImpl);
      }
    }
    if (isLocal) {
      if (hasLocalBusinessView) {
        context.setEJBLocalBusinessObjectImpl(theEJBLocalBusinessObjectImpl);
      }
      if (hasOptionalLocalBusinessView) {
        context.setOptionalEJBLocalBusinessObjectImpl(theOptionalEJBLocalBusinessObjectImpl);
      }
    }
    ejbInv.transactionAttribute=postConstructInvInfo.txAttr;
    ejbInv.invocationInfo=postConstructInvInfo;
    initGotToPreInvokeTx=true;
    preInvokeTx(ejbInv);
    context.setInstanceKey(singletonInstanceKey);
    if (doPostConstruct) {
      intercept(CallbackType.POST_CONSTRUCT,context);
    }
  }
 catch (  Throwable th) {
    if (ejbInv != null) {
      ejbInv.exception=th;
    }
    singletonInitializationFailed=true;
    CreateException creEx=new CreateException("String_Node_Str" + ejbDescriptor.getName());
    creEx.initCause(th);
    throw creEx;
  }
 finally {
    initializationInProgress=false;
    if (ejbInv != null) {
      try {
        invocationManager.postInvoke(ejbInv);
        if (initGotToPreInvokeTx) {
          postInvokeTx(ejbInv);
        }
      }
 catch (      Exception pie) {
        if (ejbInv.exception != null) {
          _logger.log(Level.WARNING,"String_Node_Str",pie);
        }
 else {
          ejbInv.exception=pie;
          singletonInitializationFailed=true;
          CreateException creEx=new CreateException("String_Node_Str" + ejbDescriptor.getName());
          creEx.initCause(pie);
          throw creEx;
        }
      }
    }
  }
  context.setState(EJBContextImpl.BeanState.POOLED);
  context.touch();
  return context;
}