Re: [picocontainer-dev] ComponentMonitorStrategy Interface Problem + Pico Scripting

Mauro Talevi <[email protected]> Wed, 18 Jun 2008 08:30:58 +0100
Newsgroups gmane.comp.java.picocontainer.devel
Message-ID <[email protected]>
Michael Rimov wrote:
> Hi all.  I hit a problem with the new DefaultClassLoadingPicoContainer.  The
> culprit code is invoked when parent.createChildContainer() is called:
> 
>     protected DefaultClassLoadingPicoContainer createChildContainer() {
>         MutablePicoContainer child = getDelegate().makeChildContainer();
>         DefaultClassLoadingPicoContainer container = new
> DefaultClassLoadingPicoContainer(getComponentClassLoader(), child);
>         container.changeMonitor(currentMonitor());
>         return container;
>     }
> 
>     public void changeMonitor(ComponentMonitor monitor) {
>         ((ComponentMonitorStrategy) getDelegate()).changeMonitor(monitor);
> 		^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>     }
> 
> 
> If the delegate happens to be a DefaultClassLoadingPicoContainer, then the
> result is a class cast exception, which happens a little more often than not
> because there's only a few containers that implement ComponentMonitorStrategy,
> and AbstractDelegatingPicoContainer is not one of them.
> 
> So, do we have MutablePicoContainer implement ComponentMonitorStrategy, or do we
> just more defensively program changeMonitor()?  Or is there another option?
> 

IMO the second option:  we need to check the instance of the delegate 
before casting to component monitor stratege.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email