Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-7687

Some Adapters don't work during service deactivation

    XMLWordPrintableJSON

Details

    • Patch

    Description

      If we have an AdapterFactory and a Service registered by the following code:

       

      // code placeholder
      SlingContext context = new SlingContext();
      context.registerInjectActivateService(new TestAdapterFactory());
      context.registerInjectActivateService(new TestService());

      it turns out that adapting a Resource to another Class (defined by the TestAdapterFactory) returns null when done in the deactivate method of the TestService, i.e.

       

      resource.adaptTo(TestClass.class) // returns null in the deactivate method.
      resource.adaptTo(TestClass.class) // works correctly in any other method.

       

      Reason:

      It looks like the registered adapters are cleaned up before registered services are deactivated in the tearDown method of SlingContextImpl. 

       

      // SlingContextImpl
      void tearDown() {
          ...
          MockSling.clearAdapterManagerBundleContext();
          ...
          super.tearDown(); // calls the deactivate of the registered services.
      }

       

       

      Cleaning up the registered adapters after deactivating the services seems to solve the issue. 

      // SlingContextImpl
      void tearDown() {
          ...
          super.tearDown();
          MockSling.clearAdapterManagerBundleContext();
      }
      

      but I'm not sure about any other potential impacts of this change (attached patch). 

       

       

      Attachments

        1. patch.txt
          0.9 kB
          Arneh Jain

        Activity

          People

            sseifert Stefan Seifert
            arnehjain Arneh Jain
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: