Buggy code:
public class SingletonService < T extends Serializable > implements ServiceProviderRegistry . Listener , Singleton , SingletonRpcHandler < T > , Service < T > { public static final String DEFAULT_CONTAINER = "cluster" ; private final InjectedValue < ServiceProviderRegistry > registryRef = new InjectedValue < ServiceProviderRegistry > ( ) ; private final InjectedValue < GroupRpcDispatcher > dispatcherRef = new InjectedValue < GroupRpcDispatcher > ( ) ; private final Service < T > service ; private final ServiceName serviceName ; private final ServiceName singletonServiceName ; private final AtomicBoolean master = new AtomicBoolean ( false ) ; volatile ServiceProviderRegistry registry ; volatile GroupRpcDispatcher dispatcher ; volatile boolean started = false ; private volatile SingletonElectionPolicy electionPolicy ; private volatile SingletonRpcHandler < T > handler ; private volatile ServiceRegistry container ; private volatile boolean restartOnMerge = true ; public SingletonService ( Service < T > service , ServiceName serviceName ) { } public ServiceBuilder < T > build ( ServiceContainer target ) { } public ServiceBuilder < T > build ( ServiceContainer target , String container ) { ServiceName registryName = ServiceProviderRegistryService . getServiceName ( container ) ; synchronized ( target ) { if ( ( target . getService ( registryName ) ) == null ) { new ServiceProviderRegistryService ( ) . build ( target , container ) . setInitialMode ( ON_DEMAND ) . install ( ) ; } } target . addService ( this . serviceName , this . service ) . setInitialMode ( NEVER ) . install ( ) ; target . addService ( this . singletonServiceName . append ( "singleton" ) , new org . jboss . msc . service . ValueService < Singleton > ( new org . jboss . msc . value . ImmediateValue < Singleton > ( this ) ) ) . addDependency ( this . singletonServiceName ) . setInitialMode ( PASSIVE ) . install ( ) ; <START_BUG> return target . addService ( this . singletonServiceName , new org . jboss . as . clustering . msc . AsynchronousService < T > ( this ) ) . addDependency ( ServiceProviderRegistryService . getServiceName ( container ) , ServiceProviderRegistry . class , this . registryRef ) . addDependency ( JBOSS . append ( SingletonService . DEFAULT_CONTAINER , container ) , GroupRpcDispatcher . class , this . dispatcherRef ) ; <END_BUG> } @ Override public void start ( final StartContext context ) { } @ Override public void stop ( StopContext context ) { } @ Override public boolean isMaster ( ) { } public void setElectionPolicy ( SingletonElectionPolicy electionPolicy ) { } public void setRestartOnMerge ( boolean restart ) { } @ Override public void serviceProvidersChanged ( Set < ClusterNode > nodes , boolean merge ) { } private boolean elected ( Set < ClusterNode > candidates ) { } private ClusterNode election ( Set < ClusterNode > candidates ) { } private void startNewMaster ( ) { } @ Override public T getValue ( ) { } @ Override public AtomicReference < T > getValueRef ( ) { } @ Override public void stopOldMaster ( ) { } private class RpcHandler implements ResponseFilter , SingletonRpcHandler < T > { private final GroupRpcDispatcher dispatcher ; private String name ; RpcHandler ( GroupRpcDispatcher dispatcher , String name ) { } @ Override public void stopOldMaster ( ) { } @ Override public AtomicReference < T > getValueRef ( ) { } @ Override public boolean isAcceptable ( Object response , ClusterNode sender ) { } @ Override public boolean needMoreResponses ( ) { } } }

Fix:
return AsynchronousService . addService ( target , this . singletonServiceName , this ) . addDependency ( ServiceProviderRegistryService . getServiceName ( container ) , ServiceProviderRegistry . class , this . registryRef ) . addDependency ( JBOSS . append ( SingletonService . DEFAULT_CONTAINER , container ) , GroupRpcDispatcher . class , this . dispatcherRef ) ;