Buggy code:
public class OSGiSubsystemSupport { private static final Logger log = Logger . getLogger ( OSGiSubsystemSupport . class ) ; public static final byte [ ] BLANK_SHA1 = new byte [ 20 ] ; private static final AtomicInteger archiveCount = new AtomicInteger ( ) ; private final ServiceContainer serviceContainer ; private OSGiSubsystemState subsystemState ; private DeploymentChain deploymentChain ; private Selector selector ; public OSGiSubsystemSupport ( ) throws Exception { } public OSGiSubsystemSupport ( final OSGiSubsystemState subsystemState ) throws Exception { } public ServiceContainer getServiceContainer ( ) { } public ModuleLoader getClassifyingModuleLoader ( ) { } public OSGiSubsystemSupport . TestModuleLoader getTestModuleLoader ( ) { } public DeploymentChain getDeploymentChain ( ) { } public String getUniqueName ( String prefix ) { } public void assertServiceUp ( ServiceName serviceName ) { } public void assertServiceDown ( ServiceName serviceName ) { } public void shutdown ( ) { } public void removeDeploymentChain ( ) { } public void setupServices ( final BatchBuilder batchBuilder ) throws Exception { } public void setupEnvironmentServices ( final BatchBuilder batchBuilder ) { } public void setupModuleLoaderServices ( final BatchBuilder batchBuilder ) { } public void setupDeploymentServices ( final BatchBuilder batchBuilder ) { } public void setupFrameworkServices ( final BatchBuilder batchBuilder ) { batchBuilder . addService ( SERVICE_NAME , new MBeanServerService ( ) ) ; OSGiSubsystemSupport . TestBundleManagerService . addService ( batchBuilder ) ; <START_BUG> FrameworkService . addService ( batchBuilder ) ; <END_BUG> PackageAdminService . addService ( batchBuilder ) ; } private Selector getDeploymentChainSelector ( ) { } public BundleManager getBundleManager ( ) { } public BundleContext getSystemContext ( ) { } public Configuration getSubsystemConfig ( ) { } public void assertLoadClass ( ModuleIdentifier identifier , String className ) throws Exception { } public void assertLoadClass ( ModuleIdentifier identifier , String className , ModuleIdentifier exporterId ) throws Exception { } public void assertLoadClassFails ( ModuleIdentifier identifier , String className ) throws Exception { } public Class < ? > loadClass ( ModuleIdentifier identifier , String className ) throws Exception { } public Module loadModule ( ModuleIdentifier identifier ) throws ModuleLoadException { } public Bundle executeDeploy ( final JavaArchive archive ) throws Exception { } public void executeUndeploy ( final JavaArchive archive ) throws Exception { } List < ServiceName > runWithLatchedBatch ( final OSGiSubsystemSupport . BatchedWork work ) throws Exception { } public interface BatchedWork { void execute ( final BatchBuilder batchBuilder ) throws Exception { } } private static class TestServiceListener extends AbstractServiceListener < Object > { final List < ServiceName > registeredServices = new ArrayList < ServiceName > ( ) ; final List < ServiceName > startedServices = new ArrayList < ServiceName > ( ) ; final List < ServiceName > failedServices = new ArrayList < ServiceName > ( ) ; final Map < Mode , List < ServiceName > > initialModes ; private final AtomicInteger count = new AtomicInteger ( 1 ) ; private final Runnable finishTask ; public TestServiceListener ( Runnable finishTask , Map < Mode , List < ServiceName > > initialModes ) { } public void listenerAdded ( final ServiceController < ? extends Object > controller ) { } public void serviceStarted ( final ServiceController < ? extends Object > controller ) { } public void serviceFailed ( ServiceController < ? extends Object > controller , StartException reason ) { } @ Override public void serviceRemoved ( ServiceController < ? extends Object > controller ) { } public void finishBatch ( ) { } private void batchComplete ( ) { } } public static class TestModuleLoader extends ModuleLoader implements Service < OSGiSubsystemSupport . TestModuleLoader > { public static final ServiceName SERVICE_NAME = JBOSS . append ( "module" , "loader" , "support" ) ; private String prefix ; private Map < ModuleIdentifier , ModuleSpec > modules = new HashMap < ModuleIdentifier , ModuleSpec > ( ) ; private Injector < ClassifyingModuleLoaderService > injector ; TestModuleLoader ( String prefix ) { } public void addModuleSpec ( ModuleSpec moduleSpec ) { } @ Override protected ModuleSpec findModule ( ModuleIdentifier identifier ) throws ModuleLoadException { } public static OSGiSubsystemSupport . TestModuleLoader getServiceValue ( ServiceContainer container ) { } public synchronized void start ( StartContext context ) throws StartException { } public synchronized void stop ( StopContext context ) { } public synchronized OSGiSubsystemSupport . TestModuleLoader getValue ( ) throws IllegalStateException { } @ Override public String toString ( ) { } } static class TestBundleManagerService implements Service < BundleManager > { public static final ServiceName SERVICE_NAME = BundleManagerService . SERVICE_NAME ; private static final Logger log = Logger . getLogger ( "org.jboss.as.osgi" ) ; private InjectedValue < Configuration > injectedConfig = new InjectedValue < Configuration > ( ) ; private InjectedValue < ClassifyingModuleLoaderService > injectedModuleLoader = new InjectedValue < ClassifyingModuleLoaderService > ( ) ; private Injector < ClassifyingModuleLoaderService > moduleLoaderInjector ; private BundleManager bundleManager ; public static void addService ( final BatchBuilder batchBuilder ) { } public static BundleManager getServiceValue ( ServiceContainer container ) { } public synchronized void start ( StartContext context ) throws StartException { } public synchronized void stop ( StopContext context ) { } @ Override public BundleManager getValue ( ) throws IllegalStateException { } } static class TestServerDeploymentRepository implements ServerDeploymentRepository , Service < ServerDeploymentRepository > { private Map < String , JavaArchive > repository = new HashMap < String , JavaArchive > ( ) ; public static OSGiSubsystemSupport . TestServerDeploymentRepository getServiceValue ( ServiceContainer container ) { } public void registerDeploymentArchive ( String name , JavaArchive archive ) { } @ Override public void start ( StartContext context ) throws StartException { } @ Override public void stop ( StopContext context ) { } @ Override public ServerDeploymentRepository getValue ( ) throws IllegalStateException { } @ Override public byte [ ] addDeploymentContent ( String name , String runtimeName , InputStream stream ) throws IOException { } @ Override public Closeable mountDeploymentContent ( String name , String runtimeName , byte [ ] deploymentHash , VirtualFile mountPoint ) throws IOException { } } }

Fix:
FrameworkService . addService ( batchBuilder , null ) ;