Buggy code:
break ; } } if ( ! skip ) { injectionContainer . addInstantiator ( entry . getKey ( ) , entry . getValue ( ) ) ; } } } final Loader loader = new WebCtxLoader ( classLoader ) ; webContext . setLoader ( loader ) ; List < ValveMetaData > valves = metaData . getValves ( ) ; if ( valves == null ) { metaData . setValves ( ( valves = new ArrayList < ValveMetaData > ( ) ) ) ; } for ( ValveMetaData valve : valves ) { Valve valveInstance = ( ( Valve ) ( getInstance ( module , valve . getModule ( ) , valve . getValveClass ( ) , valve . getParams ( ) ) ) ) ; webContext . getPipeline ( ) . addValve ( valveInstance ) ; } List < ContainerListenerMetaData > listeners = metaData . getContainerListeners ( ) ; if ( listeners != null ) { for ( ContainerListenerMetaData listener : listeners ) { switch ( listener . getListenerType ( ) ) { case CONTAINER : ContainerListener containerListener = ( ( ContainerListener ) ( getInstance ( module , listener . getModule ( ) , listener . getListenerClass ( ) , listener . getParams ( ) ) ) ) ; webContext . addContainerListener ( containerListener ) ; break ; case LIFECYCLE : LifecycleListener lifecycleListener = ( ( LifecycleListener ) ( getInstance ( module , listener . getModule ( ) , listener . getListenerClass ( ) , listener . getParams ( ) ) ) ) ; if ( webContext instanceof Lifecycle ) { ( ( Lifecycle ) ( webContext ) ) . addLifecycleListener ( lifecycleListener ) ; } break ; case SERVLET_INSTANCE : webContext . addInstanceListener ( listener . getListenerClass ( ) ) ; break ; case SERVLET_CONTAINER : webContext . addWrapperListener ( listener . getListenerClass ( ) ) ; break ; case SERVLET_LIFECYCLE : webContext . addWrapperLifecycle ( listener . getListenerClass ( ) ) ; break ; } } } switch ( metaData . getSessionCookies ( ) ) { case JBossWebMetaData . SESSION_COOKIES_ENABLED : webContext . setCookies ( true ) ; break ; case JBossWebMetaData . SESSION_COOKIES_DISABLED : webContext . setCookies ( false ) ; break ; } String metaDataSecurityDomain = metaData . getSecurityDomain ( ) ; if ( metaDataSecurityDomain == null ) { metaDataSecurityDomain = getJBossAppSecurityDomain ( deploymentUnit ) ; } if ( metaDataSecurityDomain != null ) { metaDataSecurityDomain = metaDataSecurityDomain . trim ( ) ; } String securityDomain = ( metaDataSecurityDomain == null ) ? SecurityConstants . DEFAULT_APPLICATION_POLICY : SecurityUtil . unprefixSecurityDomain ( metaDataSecurityDomain ) ; final List < ServletContextAttribute > attributes = deploymentUnit . getAttachment ( ATTACHMENT_KEY ) ; try { final ServiceName webappServiceName = WebSubsystemServices . deploymentServiceName ( hostName , pathName ) ; final ServiceName realmServiceName = webappServiceName . append ( "realm" ) ; deploymentUnit . addToAttachmentList ( DEPLOYMENT_COMPLETE_SERVICES , webappServiceName ) ; deploymentUnit . addToAttachmentList ( DEPLOYMENT_COMPLETE_SERVICES , realmServiceName ) ; final JBossWebRealmService realmService = new JBossWebRealmService ( deploymentUnit ) ; ServiceBuilder < Realm > realmBuilder = serviceTarget . addService ( realmServiceName , realmService ) ; realmBuilder . addDependency ( REQUIRED , SERVICE_NAME . append ( securityDomain ) , SecurityDomainContext . class , realmService . getSecurityDomainContextInjector ( ) ) . setInitialMode ( ACTIVE ) . install ( ) ; final WebDeploymentService webappService = new WebDeploymentService ( webContext , injectionContainer , setupActions , attributes ) ; <START_BUG> ServiceBuilder < StandardContext > webappBuilder = serviceTarget . addService ( webappServiceName , webappService ) . addDependency ( JBOSS_WEB_HOST . append ( hostName ) , VirtualHost . class , new WebContextInjector ( webContext ) ) . addDependencies ( injectionContainer . getServiceNames ( ) ) . addDependency ( realmServiceName , Realm . class , webappService . getRealm ( ) ) . addDependencies ( deploymentUnit . getAttachmentList ( WEB_DEPENDENCIES ) ) . addDependency ( JndiNamingDependencyProcessor . serviceName ( deploymentUnit ) ) ; <END_BUG> for ( final SetupAction action : setupActions ) { webappBuilder . addDependencies ( action . dependencies ( ) ) ; } if ( ( metaData . getDistributable ( ) ) != null ) { DistributedCacheManagerFactoryService factoryService = new DistributedCacheManagerFactoryService ( ) ; DistributedCacheManagerFactory factory = factoryService . getValue ( ) ; if ( factory != null ) { ServiceName factoryServiceName = webappServiceName . append ( "session" ) ; webappBuilder . addDependency ( OPTIONAL , factoryServiceName , DistributedCacheManagerFactory . class , config . getDistributedCacheManagerFactoryInjector ( ) ) ; ServiceBuilder < DistributedCacheManagerFactory > factoryBuilder = serviceTarget . addService ( factoryServiceName , factoryService ) ; boolean enabled = factory . addDeploymentDependencies ( webappServiceName , deploymentUnit . getServiceRegistry ( ) , serviceTarget , factoryBuilder , metaData ) ; factoryBuilder . setInitialMode ( ( enabled ? Mode . ON_DEMAND : Mode . NEVER ) ) . install ( ) ; } } if ( deploymentUnit . hasAttachment ( OSGI_MANIFEST ) ) { webappBuilder . setInitialMode ( NEVER ) ; ContextActivator activator = new ContextActivator ( webappBuilder . install ( ) ) ; deploymentUnit . putAttachment ( ContextActivator . ATTACHMENT_KEY , activator ) ; } else { webappBuilder . setInitialMode ( ACTIVE ) ; webappBuilder . install ( ) ; } AbstractSecurityDeployer < WarMetaData > deployer = new WarSecurityDeployer ( ) ; JaccService < WarMetaData > jaccService = deployer . deploy ( deploymentUnit ) ; if ( jaccService != null ) { ( ( WarJaccService ) ( jaccService ) ) . setContext ( webContext ) ; final ServiceName jaccServiceName = deploymentUnit . getServiceName ( ) . append ( JaccService . SERVICE_NAME ) ; ServiceBuilder < ? > jaccBuilder = serviceTarget . addService ( jaccServiceName , jaccService ) ; if ( ( deploymentUnit . getParent ( ) ) != null ) { final DeploymentUnit parentDU = deploymentUnit . getParent ( ) ; jaccBuilder . addDependency ( parentDU . getServiceName ( ) . append ( JaccService . SERVICE_NAME ) , PolicyConfiguration . class , jaccService . getParentPolicyInjector ( ) ) ; }

Fix:
ServiceBuilder < StandardContext > webappBuilder = serviceTarget . addService ( webappServiceName , webappService ) . addDependency ( JBOSS_WEB_HOST . append ( hostName ) , VirtualHost . class , new WebContextInjector ( webContext ) ) . addDependencies ( injectionContainer . getServiceNames ( ) ) . addDependency ( realmServiceName , Realm . class , webappService . getRealm ( ) ) . addDependencies ( deploymentUnit . getAttachmentList ( WEB_DEPENDENCIES ) ) . addDependency ( JndiNamingDependencyProcessor . serviceName ( deploymentUnit . getServiceName ( ) ) ) ;