Uploaded image for project: 'Jira Data Center'
  1. Jira Data Center
  2. JRASERVER-27345

JIRA Mail Plugin: DefaultModuleHandlerFactory.getHandler is unreliable

    XMLWordPrintable

Details

    Description

      The above mentioned method tries to load message handler instance for class name. As part of this it attempts to find a module that the handler belongs to in the following way

      final Plugin pluginForClass = ((PluginsClassLoader) ComponentAccessor.getPluginAccessor().getClassLoader()).getPluginForClass(clazz);
      			if (pluginForClass == null) {
      				log.error("Handler '" + clazz + "' cannot be instantiated because the plugin which provides it cannot be find.");
      				return null;
      			}
      
      			final Object handler = componentClassManager.newInstance(clazz);
      
      			boolean isMatchingModuleEnabled = Iterables.any(Iterables.filter(pluginForClass.getModuleDescriptors(), MessageHandlerModuleDescriptor.class), new Predicate<MessageHandlerModuleDescriptor>()
      			{
      				@Override
      				public boolean apply(@Nullable MessageHandlerModuleDescriptor input)
      				{
      					return input != null && ComponentAccessor.getPluginAccessor().isPluginModuleEnabled(input.getCompleteKey())
      							&& (handler.getClass().equals(input.getMessageHandler()));
      				}
      			});
      			// https://jira.atlassian.com/browse/JRA-27266 temporarily disable this test on studio
      			if (!isStudio() && !isMatchingModuleEnabled) {
      					log.error("Handler '" + clazz + "' cannot be instantiated because its corresponding module is disabled");
      					return null;
      			}
      

      This is unreliable, as PluginsClassLoader.getPluginForClass will return the first plugin that was able to load the class. This does not have to be the plugin that actually contains a corresponding module - in such case the above logic will falsely assume that the handler's corresponding module is disabled. A more robust approach to check whether there is any module defining such a message handler would be to query for all enabled message handler module descriptors and check if any of them defines the class:

      boolean hasCorrespondingEnabledModuleDescriptor = Iterables.any(pluginAccessor.getEnabledModuleDescriptorsByClass(MessageHandlerModuleDescriptor.class), new Predicate<MessageHandlerModuleDescriptor>
      {
      // in apply() check input not null and input.getMessageHandler() equals to handlerClass
      }
      

      Work around
      If users are experiencing the following error in the logs:

      [atlassian.mail.incoming.DefaultMessageHandlerFactory] Handler 'com.atlassian.jira.plugins.mail.handlers.CreateIssueHandler'cannot be instatiated because its corresponding module is disabled
      

      And they are having problems with their mail plugin/handler then please follow these steps:

      • Turn on plugin safe mode
      • Disable the System mail plugin, and then reinable it
      • Go to create/test the handlers, this should work
      • Then turned off safe mode, and it still continued to work.

      Attachments

        Activity

          People

            rsmart metapoint
            dkordonski Dariusz Kordonski (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: