[cdi-dev] [JBoss JIRA] (CDI-594) Instance#destroy should be linked to Instance instance which has been used for the creation

Martin Kouba (JIRA) issues at jboss.org
Wed May 11 05:37:00 EDT 2016


    [ https://issues.jboss.org/browse/CDI-594?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13203657#comment-13203657 ] 

Martin Kouba commented on CDI-594:
----------------------------------

I can see the difference now. Right now, all the child {{Instance}} instances obtained through {{Instance.select()}} share the {{CreationalContext}} of the root (in most cases an injected {{Instance}}). That's why it would probably work. 

The requirement to be symmetric seems reasonable but I don't get the requirement for untracked instances. For your use case it might be useful but it may break other applications where e.g. {{@PreDestroy}} callback is needed. By the way, in Weld there is an optimization where certain dependent instances are not tracked (e.g. a bean with no transitive dependency with @PreDestroy/disposal method).

In any case, CDI-519 clarifies that a bean instance to destroy must be obtained from the same {{Instance}} object.

> Instance#destroy should be linked to Instance instance which has been used for the creation
> -------------------------------------------------------------------------------------------
>
>                 Key: CDI-594
>                 URL: https://issues.jboss.org/browse/CDI-594
>             Project: CDI Specification Issues
>          Issue Type: Clarification
>    Affects Versions: 1.2.Final
>            Reporter: Romain Manni-Bucau
>
> We suppose we have an injection of type Instance<Greeting>.
> {code}
> // adapted from javaee7-samples repo
> 		Instance<Greeting> select = instance.select(new AnnotationLiteral<Default>() {});
> 		Greeting anotherBean = select.get();
> 		assertThat(anotherBean, instanceOf(SimpleGreeting.class));
> 		select.destroy(anotherBean);
> {code}
> This version of code is working well and not ambiguous but the original one (next snippet) is currently ambiguous and I think it shouldn't even work:
> {code}
> 		Greeting anotherBean = instance.select(new AnnotationLiteral<Default>() {}).get();
> 		assertThat(anotherBean, instanceOf(SimpleGreeting.class));
> 		instance.destroy(anotherBean);
> {code}
> The difference is this time the destroy is called on an instance which can be different from the producing instance. For symmetry I think it should be explicitly mentionned the root instance doesn't have to support it and that the destruction should happen with the creation instance Instance. The rational behind that is to be symmetric and to allow to have untracked instances and not hold memory in a useless manner and not require ref counting which would be the alternative specification solution I think and can create issue if the code relies on Instance in a less atomic manner.



--
This message was sent by Atlassian JIRA
(v6.4.11#64026)


More information about the cdi-dev mailing list