Buggy code:
public class EntityBeanSynchronizationInterceptor extends AbstractEJBInterceptor { private final Object threadLock = new Object ( ) ; private final OwnableReentrantLock lock = new OwnableReentrantLock ( ) ; @ Override public Object processInvocation ( InterceptorContext context ) throws Exception { final EntityBeanComponent component = getComponent ( context , EntityBeanComponent . class ) ; final EntityBeanComponentInstance instance = ( ( EntityBeanComponentInstance ) ( context . getPrivateData ( ComponentInstance . class ) ) ) ; if ( ( instance . getPrimaryKey ( ) ) == null ) { return context . proceed ( ) ; } final TransactionSynchronizationRegistry transactionSynchronizationRegistry = component . getTransactionSynchronizationRegistry ( ) ; if ( EjbLogger . ROOT_LOGGER . isTraceEnabled ( ) ) { EjbLogger . ROOT_LOGGER . trace ( ( ( ( ( ( "Trying<seq2seq4repair_space>to<seq2seq4repair_space>acquire<seq2seq4repair_space>lock:<seq2seq4repair_space>" + ( lock ) ) + "<seq2seq4repair_space>for<seq2seq4repair_space>entity<seq2seq4repair_space>bean<seq2seq4repair_space>" ) + instance ) + "<seq2seq4repair_space>during<seq2seq4repair_space>invocation:<seq2seq4repair_space>" ) + context ) ) ; } final Object lockOwner = getLockOwner ( transactionSynchronizationRegistry ) ; lock . pushOwner ( lockOwner ) ; try { lock . lock ( ) ; boolean syncRegistered = false ; synchronized ( lock ) { if ( EjbLogger . ROOT_LOGGER . isTraceEnabled ( ) ) { EjbLogger . ROOT_LOGGER . trace ( ( ( ( ( ( "Acquired<seq2seq4repair_space>lock:<seq2seq4repair_space>" + ( lock ) ) + "<seq2seq4repair_space>for<seq2seq4repair_space>entity<seq2seq4repair_space>bean<seq2seq4repair_space>instance:<seq2seq4repair_space>" ) + instance ) + "<seq2seq4repair_space>during<seq2seq4repair_space>invocation:<seq2seq4repair_space>" ) + context ) ) ; } if ( ( context . getPrivateData ( InternalInvocationMarker . class ) ) == null ) { if ( ( instance . isRemoved ( ) ) || ( instance . isDiscarded ( ) ) ) { final Object primaryKey = context . getPrivateData ( PRIMARY_KEY_CONTEXT_KEY ) ; component . getCache ( ) . release ( instance , true ) ; lock . unlock ( ) ; <START_BUG> throw EjbMessages . MESSAGES . instaceWasRemoved ( component . getComponentName ( ) , primaryKey ) ; <END_BUG> } } Object currentTransactionKey = null ; try { currentTransactionKey = transactionSynchronizationRegistry . getTransactionKey ( ) ; if ( ! ( instance . isSynchronizeRegistered ( ) ) ) { if ( currentTransactionKey != null ) { final Synchronization entitySynchronization = new EntityBeanSynchronizationInterceptor . EntityBeanSynchronization ( instance , lockOwner ) ; transactionSynchronizationRegistry . registerInterposedSynchronization ( entitySynchronization ) ; syncRegistered = true ; if ( EjbLogger . ROOT_LOGGER . isTraceEnabled ( ) ) { EjbLogger . ROOT_LOGGER . trace ( ( ( ( ( ( "Registered<seq2seq4repair_space>tx<seq2seq4repair_space>synchronization:<seq2seq4repair_space>" + entitySynchronization ) + "<seq2seq4repair_space>for<seq2seq4repair_space>tx:<seq2seq4repair_space>" ) + currentTransactionKey ) + "<seq2seq4repair_space>associated<seq2seq4repair_space>with<seq2seq4repair_space>stateful<seq2seq4repair_space>component<seq2seq4repair_space>instance:<seq2seq4repair_space>" ) + instance ) ) ; } } instance . setSynchronizationRegistered ( true ) ; } return context . proceed ( ) ; } finally { if ( currentTransactionKey == null ) { instance . store ( ) ; releaseInstance ( instance , true ) ; } else if ( ! syncRegistered ) { component . getCache ( ) . release ( instance , true ) ; lock . unlock ( ) ; } } } } finally { lock . popOwner ( ) ; } } private void releaseInstance ( final EntityBeanComponentInstance instance , final boolean success ) { } private void releaseLock ( ) { } private class EntityBeanSynchronization implements Synchronization { private final EntityBeanComponentInstance componentInstance ; private final Object lockOwner ; EntityBeanSynchronization ( EntityBeanComponentInstance componentInstance , final Object lockOwner ) { } @ Override public void beforeCompletion ( ) { } @ Override public void afterCompletion ( int status ) { } private Error handleThrowableInTxSync ( final EntityBeanComponentInstance instance , final Throwable t ) { } } public static final InterceptorFactory FACTORY = new ComponentInstanceInterceptorFactory ( ) { @ Override protected Interceptor create ( final Component component , final InterceptorFactoryContext context ) { } } ; private Object getLockOwner ( final TransactionSynchronizationRegistry transactionSynchronizationRegistry ) { } }

Fix:
throw EjbMessages . MESSAGES . instanceWasRemoved ( component . getComponentName ( ) , primaryKey ) ;