Uploaded image for project: 'Felix'
  1. Felix
  2. FELIX-3220

Multiple ClassCastException(s) when invoking OSGi Service-Hooks (EventHook, FindHook)

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • framework-4.0.1
    • framework-4.0.2
    • Framework
    • None
    • Enable OSGi Security, using Felix security bundle version 2.0.0

    Description

      Scenario:

      • Register a EventHook in the OSGi service registry as described in the OSGi core specification 4.2.
      • Run felix with a SecurityManager
      • The framework is not calling the EventHook during framework service (register, modify, and unregister service) operations.

      Expected Behavior

      • The framework code calls the EventHook during framework service (register, modify, and unregister service) operations.

      Current Behavior:

      • A ClassCastException occurs in the framework code org.apache.felix.framework.util.SecureAction:1628
      • Logged on "WARNING" Level

      Probably Caused By:
      The ClassCastException is caused by calling the wrong setter-method within the org.apache.felix.framework.util.SecureAction:1135 class.
      The ServiceEvent will never be set which causes that in line 1628 when invoking the EventHook the ServiceEvent argument is missing and parameters for the EventHook will be casted wrong.

      Method: org.apache.felix.framework.util.SecureAction # invokeServiceEventHook

      public void invokeServiceEventHook(
              org.osgi.framework.hooks.service.EventHook eh,
              ServiceEvent event, Collection<BundleContext> contexts)
              throws Exception
          { ....
            actions.set(Actions.INVOKE_SERVICE_EVENT_HOOK, eh, contexts);
           ....
          }
      

      Method: org.apache.felix.framework.util.SecureAction.Actions # run
      has wrong arguments:
      arg1 = EventHook
      arg2 = Collection<BundleContext>
      arg3 = null

      case INVOKE_SERVICE_EVENT_HOOK:
                          ((org.osgi.framework.hooks.service.EventHook) arg1).event(
                              (ServiceEvent) arg2, (Collection<BundleContext>) arg3);
                          return null;
      

      Solution:
      Changing the method of setting the arguments for the Action class. Set also the ServiceEvent!

      public void invokeServiceEventHook(
              org.osgi.framework.hooks.service.EventHook eh,
              ServiceEvent event, Collection<BundleContext> contexts)
              throws Exception
          { ....
            actions.set(Actions.INVOKE_SERVICE_EVENT_HOOK, eh, event, contexts);
           ....
          }
      

      Additional:

      1. Meanwhile investigating code I found that also invoking the ServiceEventListenerHook has probably the same behavior! When calling the setter-method for setting the arguments for the Action class there is missing the ServiceEvent.
      1. Invoking FindHook using wrong action constant which causes a ClassCastException!
        Actions.INVOKE_SERVICE_EVENT_HOOK need to be changed to Actions.INVOKE_SERVICE_FIND_HOOK
        public void invokeServiceFindHook(
                org.osgi.framework.hooks.service.FindHook fh,
                BundleContext context, String name, String filter,
                boolean allServices, Collection<ServiceReference<?>> references)
                throws Exception
            {....
               actions.set(
                        Actions.INVOKE_SERVICE_EVENT_HOOK, fh, context, name, filter,
                        (allServices) ? Boolean.TRUE : Boolean.FALSE, references);
             ....}
        

      Attachments

        Activity

          People

            karlpauls Karl Pauls
            michael.hirsch Michael Hirsch
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: