Re: [picocontainer-dev] Bug in DefaultPico?
Paul Hammant <[email protected]>
| Newsgroups | gmane.comp.java.picocontainer.devel |
|---|---|
| Message-ID | <[email protected]> |
Mike,
You're quite right - its lame as is.
What do you think it should be changed to ? One using plain refs
rather than integers ?
- Paul
On Dec 19, 2007, at 2:18 AM, Michael Rimov wrote:
> Hi guys,
>
> I wanted verify that this was actually a problem before I jira'd it.
>
> DefaultPicoContainer has two collections related to storing
> Lifecycle state:
>
> /** List collecting the CAs which have been successfully started
> */
> private final List<Integer> startedComponentAdapters = new
> ArrayList<Integer>();
>
> /**
> * Keeps track of child containers started status.
> */
> private final Set<Integer> childrenStarted = new
> HashSet<Integer>();
>
> These collections are populated like so:
>
> In Start:
> childrenStarted.add(child.hashCode());
>
> In Start Adapters:
>
> adapters = getOrderedComponentAdapters();
> // clear list of started CAs
> startedComponentAdapters.clear();
> // clone the adapters
> List<ComponentAdapter<?>> adaptersClone = new
> ArrayList<ComponentAdapter<?>>(adapters);
> for (final ComponentAdapter<?> adapter : adaptersClone) {
> if (adapter instanceof Behavior) {
> Behavior<?> manager = (Behavior<?>)adapter;
> manager.start(DefaultPicoContainer.this);
>
> startedComponentAdapters.add(adaptersClone.indexOf(adapter));
> }
> }
>
> Now, I have two problems:
>
> 1 – Since hashcodes are not guaranteed unique, it seems that storing
> a series of integers representing the hashcodes as a substitution
> for identity is going to cause spurious bugs.
>
> 2 – In start adapters, storing the index seems like unnecessary as
> well as awfully dependent on the immutability of the adapters.
>
> Overall it seems that relying on collections of integers in this
> fashion is only asking for trouble, and since the collections are
> only storing references, I don’t even see that it has a significant
> savings in memory.
>
> Can someone set me straight on this?
>
> Thanks,
>
> -Mike
>
>
>
>