Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Critical
-
Resolution: Unresolved
-
Affects Version/s: 1.0.0
-
Fix Version/s: None
-
Component/s: Container
-
Labels:None
-
Environment:Linux, Gentoo 2.6.22 kernel, amd64 - does not matter
-
Testcase included:yes
-
Number of attachments :
Description
Symptom:
"A" - is singleton object (singe instance component)
Code:
PlexusContainer container=new DefaultPlexusContainer();
container.lookup("A").
container.createChildContainer("A",Collections.EMPTY_LIST,Collections.EMPTY_MAP, Collections.EMPTY_LIST).lookup("A").
The components "A" is instanced twice.
Unit test for plexus container is attached to the bug.
=================================================================
Explanation:
createChildContainer method calls initializeConfiguration that uses PlexusXmlComponentDiscoverer to
merge the container configuration. The method parses META-INF/plexus/plexus.xml another time.
Using this configuration ComponentRepository for child-container is instanced. So the ComponentRepository starts with
preconfigured map (containing configuration for component "A").
Then child-container.lookups finds the component in child's componentRepository - so don't ask Parent's repository for component.
Changing line 1136 of Default plexus Container from
if (( !containerContext.contains( PlexusConstants.IGNORE_CONTAINER_CONFIGURATION )
to
if ((parentContainer==null)&&( !containerContext.contains( PlexusConstants.IGNORE_CONTAINER_CONFIGURATION )
correct's the problem.
I don't know (and there is no documentation), what the correct plexus's behavior should be. How should work child container with configuration.
Unit case for plexus-container-default (attached).
The test is provided for alpha-32-SNAPSHOT version.