Buggy code:
public final class BundleLifecycleIntegration extends BundleLifecyclePlugin { private static Map < String , Deployment > deploymentMap = new HashMap < String , Deployment > ( ) ; private final InjectedValue < ModelController > injectedController = new InjectedValue < ModelController > ( ) ; private final InjectedValue < BundleManager > injectedBundleManager = new InjectedValue < BundleManager > ( ) ; private final InjectedValue < XEnvironment > injectedEnvironment = new InjectedValue < XEnvironment > ( ) ; private final InjectedValue < XResolver > injectedResolver = new InjectedValue < XResolver > ( ) ; private ServerDeploymentManager deploymentManager ; @ Override protected void addServiceDependencies ( ServiceBuilder < BundleLifecycle > builder ) { } @ Override public void start ( StartContext startContext ) throws StartException { } @ Override protected BundleLifecycle createServiceValue ( StartContext startContext ) throws StartException { } public static Deployment getDeployment ( String runtimeName ) { } private void putDeployment ( String runtimeName , final Deployment dep ) { } public static Deployment removeDeployment ( String runtimeName ) { } class BundleLifecycleImpl implements BundleLifecycle { private final BundleLifecycle defaultService ; public BundleLifecycleImpl ( BundleLifecycle defaultService ) { } @ Override public void install ( BundleContext context , Deployment dep ) throws BundleException { } @ Override @ SuppressWarnings ( { "unchecked" , "rawtypes" } ) public void resolve ( XBundle bundle ) throws ResolutionException { } @ Override public void start ( XBundle bundle , int options ) throws BundleException { } @ Override public void stop ( XBundle bundle , int options ) throws BundleException { } @ Override public void update ( XBundle bundle , InputStream input ) throws BundleException { } @ Override public void uninstall ( XBundle bundle , int options ) throws BundleException { } private void activateDeferredPhase ( XBundle bundle , int options , DeploymentUnit depUnit , ServiceController < Phase > phaseService , ServiceController < DeploymentUnit > parentDeploymentService ) throws BundleException { BundleManager bundleManager = injectedBundleManager . getValue ( ) ; FrameworkStartLevel frameworkStartLevel = bundleManager . getSystemBundle ( ) . adapt ( FrameworkStartLevel . class ) ; BundleStartLevel bundleStartLevel = bundle . adapt ( BundleStartLevel . class ) ; int startlevel = bundleStartLevel . getStartLevel ( ) ; if ( startlevel > ( frameworkStartLevel . getStartLevel ( ) ) ) { OSGiLogger . LOGGER . debugf ( "Start<seq2seq4repair_space>level<seq2seq4repair_space>[%d]<seq2seq4repair_space>not<seq2seq4repair_space>valid<seq2seq4repair_space>for:<seq2seq4repair_space>%s" , startlevel , bundle ) ; return ; } OSGiLogger . LOGGER . infoActivateDeferredModulePhase ( bundle ) ; if ( ! ( bundle . isResolved ( ) ) ) { XEnvironment env = injectedEnvironment . getValue ( ) ; XResolver resolver = injectedResolver . getValue ( ) ; XResolveContext context = resolver . createResolveContext ( env , Collections . singleton ( bundle . getBundleRevision ( ) ) , null ) ; try { resolver . resolveAndApply ( context ) ; } catch ( ResolutionException ex ) { throw new BundleException ( MESSAGES . cannotResolveBundle ( bundle ) , BundleException . RESOLVE_ERROR , ex ) ; } } depUnit . getAttachment ( DEFERRED_ACTIVATION_COUNT ) . incrementAndGet ( ) ; StabilityMonitor monitor = new StabilityMonitor ( ) ; monitor . addController ( parentDeploymentService ) ; monitor . addController ( phaseService ) ; Set < ServiceController < ? > > failed = new HashSet < ServiceController < ? > > ( ) ; Set < ServiceController < ? > > problems = new HashSet < ServiceController < ? > > ( ) ; try { phaseService . setMode ( ACTIVE ) ; monitor . awaitStability ( failed , problems ) ; } catch ( final InterruptedException ex ) { } finally { <START_BUG> monitor . removeController ( phaseService ) ; <END_BUG> } if ( ( ( failed . size ( ) ) > 0 ) || ( ( problems . size ( ) ) > 0 ) ) { List < ServiceController < ? > > combined = new ArrayList < ServiceController < ? > > ( ) ; combined . addAll ( failed ) ; combined . addAll ( problems ) ; StartException startex = null ; for ( ServiceController < ? > aux : combined ) { if ( ( aux . getStartException ( ) ) != null ) { startex = aux . getStartException ( ) ; break ; } } BundleException failure ; if ( ( startex != null ) && ( ( startex . getCause ( ) ) instanceof BundleException ) ) { failure = ( ( BundleException ) ( startex . getCause ( ) ) ) ; } else { failure = OSGiMessages . MESSAGES . cannotActivateDeferredModulePhase ( startex , bundle ) ; } OSGiLogger . LOGGER . warnDeactivateDeferredModulePhase ( bundle ) ; phaseService . setMode ( NEVER ) ; try { FutureServiceValue < Phase > future = new FutureServiceValue < Phase > ( phaseService , State . DOWN ) ; future . get ( 30 , TimeUnit . SECONDS ) ; } catch ( ExecutionException ex ) { OSGiLogger . LOGGER . errorf ( failure , failure . getMessage ( ) ) ; throw OSGiMessages . MESSAGES . cannotDeactivateDeferredModulePhase ( ex , bundle ) ; } catch ( TimeoutException ex ) { OSGiLogger . LOGGER . errorf ( failure , failure . getMessage ( ) ) ; throw OSGiMessages . MESSAGES . cannotDeactivateDeferredModulePhase ( ex , bundle ) ; } throw failure ; } } private String getRuntimeName ( Deployment dep ) { } @ SuppressWarnings ( "unchecked" ) private ServiceController < Phase > getDeferredPhaseService ( DeploymentUnit depUnit ) { } } }

Fix:
monitor . clear ( ) ;