Uploaded image for project: 'XWiki Commons'
  1. XWiki Commons
  2. XCOMMONS-3947

Looking up a component while it's being unregistered can fail with a NullPointerException

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Major
    • None
    • 15.4-rc-1
    • Component
    • None
    • Unknown

    Description

      When a singleton component registered with an instance but without implementation class (typically a wiki macro, registered through registerComponent(descriptor, instance)) is unregistered while another thread is looking it up, the lookup fails with a NullPointerException instead of a meaningful error, and the real cause is lost.

      Steps to reproduce

      This is a race, so it is not reproducible on demand. It was observed on CI during Upgrade84FileStoreTest (stable-18.4.x, Environment Tests build #197): the Solr indexer extracted the links of XWiki.Notifications.Code.Legacy.ActivityMacro (which looks up the activity macro through DefaultMacroRefactoring) while the upgrade was re-registering that wiki macro.

      1. Thread A gets the ComponentEntry of the wiki macro from EmbeddableComponentManager.
      2. Thread B unregisters the component: removeComponent() -> releaseInstance() sets componentEntry.instance to null.
      3. Thread A calls getComponentInstance(componentEntry).

      Expected results

      The lookup fails with a ComponentLookupException explaining that the component is not (or no longer) available, or it is simply treated as not found.

      Actual results

      • getComponentInstance() finds a singleton entry without instance and calls createInstance(descriptor), which runs descriptor.getImplementation().newInstance() on a null implementation and throws a NullPointerException.
      • The catch block of getInstance(ComponentEntry) builds its ComponentLookupException message with componentEntry.descriptor.getImplementation().getName(), which throws a second NullPointerException that replaces the original error.
      org.xwiki.search.solr.internal.api.SolrIndexerException: Failed to get input Solr document for entity 'xwiki:XWiki.Notifications.Code.Legacy.ActivityMacro'
      	at org.xwiki.search.solr.internal.metadata.AbstractSolrMetadataExtractor.getSolrDocument(AbstractSolrMetadataExtractor.java:174)
      	...
      Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.Class.getName()" because the return value of "org.xwiki.component.descriptor.ComponentDescriptor.getImplementation()" is null
      	at org.xwiki.component.embed.EmbeddableComponentManager.getInstance(EmbeddableComponentManager.java:342)
      	at org.xwiki.component.embed.EmbeddableComponentManager.getInstance(EmbeddableComponentManager.java:326)
      	at org.xwiki.component.internal.multi.DelegateComponentManager.getInstance(DelegateComponentManager.java:83)
      	at org.xwiki.rendering.internal.macro.DefaultMacroManager.getMacro(DefaultMacroManager.java:131)
      	at org.xwiki.refactoring.internal.DefaultMacroRefactoring.getMacro(DefaultMacroRefactoring.java:107)
      	at org.xwiki.refactoring.internal.DefaultMacroRefactoring.parseMacro(DefaultMacroRefactoring.java:140)
      	at org.xwiki.refactoring.internal.DefaultMacroRefactoring.extractReferences(DefaultMacroRefactoring.java:216)
      	at org.xwiki.rendering.internal.parser.LinkParser.extractReferences(LinkParser.java:117)
      	at org.xwiki.rendering.internal.parser.LinkParser.getUniqueLinkedEntityReferences(LinkParser.java:142)
      	at com.xpn.xwiki.doc.XWikiDocument.getUniqueLinkedEntities(XWikiDocument.java:6081)
      	at org.xwiki.search.solr.internal.metadata.DocumentSolrMetadataExtractor.setLinks(DocumentSolrMetadataExtractor.java:187)
      

      The same error was also logged as a warning by the links indexing task (DefaultTasksManager). The consequence is that the page is not indexed (Solr, links) and the log shows an error that does not say what happened.

      The code is the same on master (the getImplementation().getName() in the error message, createInstance() on a released entry). XCOMMONS-3848 fixed a similar race for getInstanceMap() with components of the parent component manager, but not this one.

      Attachments

        Issue Links

          Activity

            People

              surli Simon Urli
              surli Simon Urli
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated: