Details
-
Bug
-
Resolution: Unresolved
-
Major
-
None
-
15.4-rc-1
-
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.
- Thread A gets the ComponentEntry of the wiki macro from EmbeddableComponentManager.
- Thread B unregisters the component: removeComponent() -> releaseInstance() sets componentEntry.instance to null.
- 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
- relates to
-
XCOMMONS-3848 Looking up all the components of a role fails when a component of the parent component manager is unregistered at the same time
-
- Closed
-