[cdi-dev] cyclic references

Mark Struberg struberg at yahoo.de
Sat Nov 24 11:58:28 EST 2012


Hi Folks!

I know we already discussed that cyclic references in @PostConstruct and @Inject methods are not allowed (btw, did we also nail this down in the spec properly? This is implicitly defined in commons-annotations).

But what about @PreDestroy? As the destroy order is not defined for normalscoped beans it could happen that a bean already got wiped and destroyed while another one likes to access it. So it's not only a problem of cycles, but might also happen without.

sample:

@RequestScoped

public class BeanA {
  @Inject BeanB b;

  @PreDestroy
  public void destroyMe() {
    b.dosomething();
  }
}

and 


@RequestScoped

public class BeanB {
  public void dosomething() {..}

  @PreDestroy
  public void dropDatabaseConnection() {...}

}

Now lets imagine that BeanB got destroyed earlier than BeanA ....


It's atm purely random. Imo this is ok, but should we point users to this behaviour?

LieGrue,
strub




More information about the cdi-dev mailing list