Details
-
Type: Bug
-
Status: Resolved
-
Priority: Major
-
Resolution: Fixed
-
Affects Version/s: 2.13.5
-
Fix Version/s: None
-
Component/s: PicoContainer (Java)
-
Labels:None
-
Testcase included:yes
-
Patch Submitted:Yes
-
Number of attachments :
Description
I encountered a ClassCastException when using a composite container. I think I've tracked down the problem to this method:-
org.picocontainer.DefaultPicoContainer.getInstance(ComponentAdapter<?>, Class)
In this case isLocal is false and parent != null. Its passing in the key from the component adapter rather than using the componentKey. In this case these are different. componentKey is Impl2 but the componentAdapter's key is AnInterface. Subsequently the composite pico returns Impl1 and it attempts to cast it to anImpl2.
I'd guess that changing it to do this would fix this problem but perhaps it would cause other problems?
return getParent().getComponent(componentKey);
On closer inspection the last line should be
assertEquals(Impl1.class, child.getComponent(AnInterface.class).getClass());
I didn't notice it was wrong due to the class cast execption.