Buggy code:
public class PersistenceContextBindingSourceDescription extends BindingSourceDescription { private final PersistenceContextType type ; private final PersistenceContextBindingSourceDescription . PersistenceContextJndiInjectable injectable ; private final ServiceName puServiceName ; public PersistenceContextBindingSourceDescription ( final PersistenceContextType type , final Map properties , final ServiceName puServiceName , final DeploymentUnit deploymentUnit , final String scopedPuName , final String injectionTypeName ) { } @ Override public void getResourceValue ( BindingDescription referenceDescription , ServiceBuilder < ? > serviceBuilder , DeploymentPhaseContext phaseContext , Injector < ManagedReferenceFactory > injector ) { } private static final class PersistenceContextJndiInjectable implements ManagedReferenceFactory { private final ServiceName puServiceName ; private final DeploymentUnit deploymentUnit ; private final PersistenceContextType type ; private final Map properties ; private final String unitName ; private final String injectionTypeName ; private static final String ENTITY_MANAGER_CLASS = "javax.persistence.EntityManager" ; private static final Logger log = Logger . getLogger ( "org.jboss.jpa" ) ; public PersistenceContextJndiInjectable ( final ServiceName puServiceName , final DeploymentUnit deploymentUnit , final PersistenceContextType type , final Map properties , final String unitName , final String injectionTypeName ) { } @ Override public ManagedReference getReference ( ) { PersistenceUnitService service = ( ( PersistenceUnitService ) ( deploymentUnit . getServiceRegistry ( ) . getRequiredService ( puServiceName ) . getValue ( ) ) ) ; EntityManagerFactory emf = service . getEntityManagerFactory ( ) ; EntityManager entityManager ; if ( type . equals ( TRANSACTION ) ) { entityManager = new org . jboss . as . jpa . container . TransactionScopedEntityManager ( unitName , properties , emf ) ; if ( PersistenceContextBindingSourceDescription . PersistenceContextJndiInjectable . log . isDebugEnabled ( ) ) PersistenceContextBindingSourceDescription . PersistenceContextJndiInjectable . log . debug ( ( "created<seq2seq4repair_space>new<seq2seq4repair_space>TransactionScopedEntityManager<seq2seq4repair_space>for<seq2seq4repair_space>unit<seq2seq4repair_space>name=" + ( unitName ) ) ) ; } else { EntityManager entityManager1 = SFSBCallStack . findPersistenceContext ( unitName ) ; if ( entityManager1 == null ) { entityManager1 = emf . createEntityManager ( properties ) ; entityManager = new org . jboss . as . jpa . container . ExtendedEntityManager ( unitName , entityManager1 ) ; if ( PersistenceContextBindingSourceDescription . PersistenceContextJndiInjectable . log . isDebugEnabled ( ) ) PersistenceContextBindingSourceDescription . PersistenceContextJndiInjectable . log . debug ( ( "created<seq2seq4repair_space>new<seq2seq4repair_space>ExtendedEntityManager<seq2seq4repair_space>for<seq2seq4repair_space>unit<seq2seq4repair_space>name=" + ( unitName ) ) ) ; } else { entityManager = entityManager1 ; if ( PersistenceContextBindingSourceDescription . PersistenceContextJndiInjectable . log . isDebugEnabled ( ) ) PersistenceContextBindingSourceDescription . PersistenceContextJndiInjectable . log . debug ( ( "inherited<seq2seq4repair_space>existing<seq2seq4repair_space>ExtendedEntityManager<seq2seq4repair_space>from<seq2seq4repair_space>SFSB<seq2seq4repair_space>invocation<seq2seq4repair_space>stack,<seq2seq4repair_space>unit<seq2seq4repair_space>name=" + ( unitName ) ) ) ; } SFSBXPCMap . RegisterPersistenceContext ( entityManager ) ; } if ( ! ( PersistenceContextBindingSourceDescription . PersistenceContextJndiInjectable . ENTITY_MANAGER_CLASS . equals ( injectionTypeName ) ) ) { Class extensionClass ; try { extensionClass = this . getClass ( ) . getClassLoader ( ) . loadClass ( injectionTypeName ) ; } catch ( ClassNotFoundException e ) { throw new RuntimeException ( ( ( "couldn't<seq2seq4repair_space>load<seq2seq4repair_space>" + ( injectionTypeName ) ) + "<seq2seq4repair_space>from<seq2seq4repair_space>JPA<seq2seq4repair_space>modules<seq2seq4repair_space>classloader" ) , e ) ; } Object targetValueToInject = entityManager . unwrap ( extensionClass ) ; <START_BUG> new ValueManagedReference ( new org . jboss . msc . value . ImmediateValue < Object > ( targetValueToInject ) ) ; <END_BUG> } return new ValueManagedReference ( new org . jboss . msc . value . ImmediateValue < Object > ( entityManager ) ) ; } } }

Fix:
return new ValueManagedReference ( new org . jboss . msc . value . ImmediateValue < Object > ( targetValueToInject ) ) ;