PicoContainer
  1. PicoContainer
  2. PICO-384

ClassCastException obtaining component from parent container when using CompositePicoContainer.

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major 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 :
      1

      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);

        People

        • Assignee:
          Paul Hammant
          Reporter:
          Chris Simmons
        • Votes:
          0 Vote for this issue
          Watchers:
          0 Start watching this issue

          Dates

          • Created:
            Updated:
            Resolved: