Uploaded image for project: 'CDI Specification Issues'
  1. CDI Specification Issues
  2. CDI-594

Instance#destroy should be linked to Instance instance which has been used for the creation

    XMLWordPrintable

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

          Activity

            People

              Unassigned Unassigned
              rmannibucau@gmail.com Romain Manni-Bucau
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: