Uploaded image for project: 'Weld'
  1. Weld
  2. WELD-1010

@PreDestroy method invoked twice

    Details

    • Steps to Reproduce:
      Hide

      for(Bean b: bm.getBeans(TestBean.class))

      { CreationalContext ctx = bm.createCreationalContext(null); TestBean testBean = (TestBean)bm.getReference(b, b.getBeanClass(), ctx); b.destroy(testBean, ctx); }

      TestBean is simple POJO with @PreDestroy method

      Show
      for(Bean b: bm.getBeans(TestBean.class)) { CreationalContext ctx = bm.createCreationalContext(null); TestBean testBean = (TestBean)bm.getReference(b, b.getBeanClass(), ctx); b.destroy(testBean, ctx); } TestBean is simple POJO with @PreDestroy method

      Description

      @PreDestroy method on @Dependend scope is invoked twice when we use Bean.destroy() method.

      Problem occurs in destroy() method:

      getInjectionTarget().preDestroy(instance);
      creationalContext.release();

        Gliffy Diagrams

          Activity

          Hide
          alesj Ales Justin added a comment -

          The initial issue I see is that CreationalContextImpl passes dependentInstances as a ref to its child – from getCreationalContext.
          This ref gets then later filled from addDependentInstance invocation on new creational context instance.

          @Pete: the question is (and imo it looks like it is), is this intentional – passing the ref instead of deep copy?

          Show
          alesj Ales Justin added a comment - The initial issue I see is that CreationalContextImpl passes dependentInstances as a ref to its child – from getCreationalContext. This ref gets then later filled from addDependentInstance invocation on new creational context instance. @Pete: the question is (and imo it looks like it is), is this intentional – passing the ref instead of deep copy?
          Show
          alesj Ales Justin added a comment - https://github.com/alesj/core/commit/31b07b2fe9aecf6ae043015c830b0e9652c07594
          Hide
          alesj Ales Justin added a comment -

          Current fix uses impl detail to workaround the issue.

          Show
          alesj Ales Justin added a comment - Current fix uses impl detail to workaround the issue.

            People

            • Assignee:
              alesj Ales Justin
              Reporter:
              wojtek9 wojtek k
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development