@Override
  public void clear(Portlet portlet, boolean resetRemotePortletBag) {
    String rootPortletId = portlet.getRootPortletId();

    Map<String, InvokerPortlet> portletInstances = _pool.remove(rootPortletId);

    if (portletInstances != null) {
      InvokerPortlet rootInvokerPortletInstance = portletInstances.remove(rootPortletId);

      if (rootInvokerPortletInstance != null) {
        rootInvokerPortletInstance.destroy();
      }

      portletInstances.clear();
    }

    PortletApp portletApp = portlet.getPortletApp();

    if (resetRemotePortletBag && portletApp.isWARFile()) {
      PortletBag portletBag = PortletBagPool.remove(rootPortletId);

      if (portletBag != null) {
        portletBag.destroy();
      }
    }
  }
 @Test
 public void test7() throws Exception {
   try {
     PortletBagPool.remove("1_WAR_flashportlet");
   } catch (SecurityException se) {
     Assert.fail();
   }
 }
  @Test
  public void test8() throws Exception {
    try {
      PortletBagPool.remove("fail");

      Assert.fail();
    } catch (SecurityException se) {
    }
  }
  @Override
  public void removedService(
      ServiceReference<Portlet> serviceReference, com.liferay.portal.model.Portlet portletModel) {

    portletModel.unsetReady();

    ServiceRegistrations serviceRegistrations =
        _serviceRegistrations.get(serviceReference.getBundle());

    if (serviceRegistrations == null) {
      return;
    }

    BundlePortletApp bundlePortletApp = serviceRegistrations.getBundlePortletApp();

    bundlePortletApp.removePortlet(portletModel);

    serviceRegistrations.removeServiceReference(serviceReference);

    BundleContext bundleContext = _componentContext.getBundleContext();

    bundleContext.ungetService(serviceReference);

    _portletInstanceFactory.destroy(portletModel);

    List<Company> companies = _companyLocalService.getCompanies();

    for (Company company : companies) {
      PortletCategory portletCategory =
          (PortletCategory) WebAppPool.get(company.getCompanyId(), WebKeys.PORTLET_CATEGORY);

      portletCategory.separate(portletModel.getRootPortletId());
    }

    PortletBag portletBag = PortletBagPool.remove(portletModel.getRootPortletId());

    if (portletBag != null) {
      portletBag.destroy();
    }
  }