Details
-
Clarification
-
Resolution: Obsolete
-
Major
-
None
-
1.2.Final
-
None
-
None
Description
We suppose we have an injection of type Instance<Greeting>.
// 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);
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:
Greeting anotherBean = instance.select(new AnnotationLiteral<Default>() {}).get();
assertThat(anotherBean, instanceOf(SimpleGreeting.class));
instance.destroy(anotherBean);
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.
Attachments
Issue Links
- duplicates
-
CDI-519 Instance.destroy() cannot be used for dependent bean instances not created by the same Instance object
- Resolved