PicoContainer
  1. PicoContainer
  2. PICO-143

resolution of components present in ancestor containers is limited to immediate parent only [patch]

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.0-beta-5
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      3

      Description

      this works:

      MutablePicoContainer parent = new DefaultPicoContainer();
      parent.registerComponentImplementation(Touchable.class, SimpleTouchable.class);

      MutablePicoContainer child = new DefaultPicoContainer(parent);
      child.registerComponentImplementation(DependsOnTouchable.class, DependsOnTouchable.class, new Parameter[]

      { new ComponentParameter((Object)Touchable.class) });
      assertNotNull(child.getComponentInstance(DependsOnTouchable.class));
      this does not work:

      MutablePicoContainer grandParent = new DefaultPicoContainer();

      grandParent.registerComponentImplementation(Touchable.class, SimpleTouchable.class);

      MutablePicoContainer parent = new DefaultPicoContainer(grandParent);

      MutablePicoContainer child = new DefaultPicoContainer(parent);
      child.registerComponentImplementation(DependsOnTouchable.class, DependsOnTouchable.class, new Parameter[] { new ComponentParameter((Object)Touchable.class) }

      );
      assertNotNull(child.getComponentInstance(DependsOnTouchable.class));
      ---------------------------------------------------------------------

      a testcase and two fixes are provided:

      1) a straightforward one, that calls parent.getComponentAdapter() recursively, if componentKeyToAdapterCache.get yields null

      2) a conservative one, that creates correct map of keys -> component adapters from entire container hierarchy. It's rather baroque and performance ineffective IMO, but maybe it was implemented this way for a reason?

      All testcases pass with either of these fixes.

      1. conatinerHierarchyConservativeFix.diff
        6 kB
        Rafal Krzewski
      2. conatinerHierarchyStraightforwardFix.diff
        2 kB
        Rafal Krzewski
      3. conatinerHierarchyTestcase.diff
        4 kB
        Rafal Krzewski

        Activity

        Hide
        Rafal Krzewski added a comment -

        the failing testcase

        Show
        Rafal Krzewski added a comment - the failing testcase
        Rafal Krzewski made changes -
        Field Original Value New Value
        Attachment conatinerHierarchyTestcase.diff [ 11461 ]
        Hide
        Rafal Krzewski added a comment -

        a straightforward fix for the issue

        Show
        Rafal Krzewski added a comment - a straightforward fix for the issue
        Rafal Krzewski made changes -
        Hide
        Rafal Krzewski added a comment -

        a conservative fix for the issue (an alternative to straightforward fix)

        Show
        Rafal Krzewski added a comment - a conservative fix for the issue (an alternative to straightforward fix)
        Rafal Krzewski made changes -
        Hide
        Aslak Hellesøy added a comment -

        I applied the straightforward fix. The current implementation was - as you pointed out - rather baroque

        Thanks!

        Show
        Aslak Hellesøy added a comment - I applied the straightforward fix. The current implementation was - as you pointed out - rather baroque Thanks!
        Aslak Hellesøy made changes -
        Assignee Aslak Hellesoy [ rinkrank ]
        Resolution Fixed [ 1 ]
        Status Open [ 1 ] Closed [ 6 ]
        Fix Version/s 1.0-beta-5 [ 10145 ]

          People

          • Assignee:
            Aslak Hellesøy
            Reporter:
            Rafal Krzewski
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: