Buggy code:
public class ModuleContextProcessor implements DeploymentUnitProcessor { public void deploy ( DeploymentPhaseContext phaseContext ) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext . getDeploymentUnit ( ) ; if ( DeploymentTypeMarker . isType ( EAR , deploymentUnit ) ) { return ; } EEModuleDescription moduleDescription = deploymentUnit . getAttachment ( EE_MODULE_DESCRIPTION ) ; final ServiceTarget serviceTarget = phaseContext . getServiceTarget ( ) ; final ServiceName appContextServiceName = ContextNames . contextServiceNameOfApplication ( moduleDescription . getApplicationName ( ) ) ; final ServiceName moduleContextServiceName = ContextNames . contextServiceNameOfModule ( moduleDescription . getApplicationName ( ) , moduleDescription . getModuleName ( ) ) ; final NamingStoreService contextService = new NamingStoreService ( ) ; serviceTarget . addService ( moduleContextServiceName , contextService ) . install ( ) ; final BinderService moduleNameBinder = new BinderService ( "ModuleName" ) ; final ServiceName moduleNameServiceName = moduleContextServiceName . append ( "ModuleName" ) ; serviceTarget . addService ( moduleNameServiceName , moduleNameBinder ) . addInjection ( moduleNameBinder . getManagedObjectInjector ( ) , new org . jboss . as . naming . ValueManagedReferenceFactory ( Values . immediateValue ( moduleDescription . getModuleName ( ) ) ) ) . addDependency ( moduleContextServiceName , ServiceBasedNamingStore . class , moduleNameBinder . getNamingStoreInjector ( ) ) . install ( ) ; deploymentUnit . addToAttachmentList ( JNDI_DEPENDENCIES , moduleNameServiceName ) ; deploymentUnit . putAttachment ( Attachments . MODULE_CONTEXT_CONFIG , moduleContextServiceName ) ; final InjectedEENamespaceContextSelector selector = new InjectedEENamespaceContextSelector ( ) ; phaseContext . addDependency ( appContextServiceName , NamingStore . class , selector . getAppContextInjector ( ) ) ; phaseContext . addDependency ( moduleContextServiceName , NamingStore . class , selector . getModuleContextInjector ( ) ) ; phaseContext . addDependency ( moduleContextServiceName , NamingStore . class , selector . getCompContextInjector ( ) ) ; phaseContext . addDependency ( JBOSS_CONTEXT_SERVICE_NAME , NamingStore . class , selector . getJbossContextInjector ( ) ) ; phaseContext . addDependency ( EXPORTED_CONTEXT_SERVICE_NAME , NamingStore . class , selector . getExportedContextInjector ( ) ) ; phaseContext . addDependency ( GLOBAL_CONTEXT_SERVICE_NAME , NamingStore . class , selector . getGlobalContextInjector ( ) ) ; moduleDescription . setNamespaceContextSelector ( selector ) ; final Set < ServiceName > serviceNames = new HashSet < ServiceName > ( ) ; serviceNames . add ( appContextServiceName ) ; serviceNames . add ( moduleContextServiceName ) ; serviceNames . add ( JBOSS_CONTEXT_SERVICE_NAME ) ; serviceNames . add ( GLOBAL_CONTEXT_SERVICE_NAME ) ; <START_BUG> final JavaNamespaceSetup setupAction = new JavaNamespaceSetup ( selector , serviceTarget ) ; <END_BUG> deploymentUnit . addToAttachmentList ( org . jboss . as . server . deployment . Attachments . SETUP_ACTIONS , setupAction ) ; deploymentUnit . addToAttachmentList ( WEB_SETUP_ACTIONS , setupAction ) ; } public void undeploy ( DeploymentUnit context ) { } }

Fix:
final JavaNamespaceSetup setupAction = new JavaNamespaceSetup ( selector , deploymentUnit . getServiceName ( ) ) ;