[weld-issues] [JBoss JIRA] Commented: (CDITCK-140) TCK uses cyclic @PostConstruct calls which is forbidden by JSR-250

Mark Struberg (JIRA) jira-events at lists.jboss.org
Mon Apr 12 13:32:37 EDT 2010


    [ https://jira.jboss.org/jira/browse/CDITCK-140?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12525192#action_12525192 ] 

Mark Struberg commented on CDITCK-140:
--------------------------------------

@PostConstruct Pig#postConstruct() accesses a member of Food and 
@PostConstruct Food#postConstruct()  accesses a member of Pig

So you can turn it as you like, one of those calls is to an unfinished instance.

And now to the problem this causes in OWB: 

The contextual instance of Pig cannot get stored in the Context unless we suceeded running Pig#postConstruct(). So even if we inject a Proxy for Food, this won't help us fixing a cyclic creation problem because you call a method on Food from WITHIN the Pig construction (all inside Creational<T>#create(CreationalContext)

So sure, we would be able to pass the CreationalContext for the first creation and cleaning it up later, but the question is if we really need to do all this stuff? Because obviously this introduces much bigger problem spots than it solves.

> TCK uses cyclic @PostConstruct calls which is forbidden by JSR-250
> ------------------------------------------------------------------
>
>                 Key: CDITCK-140
>                 URL: https://jira.jboss.org/jira/browse/CDITCK-140
>             Project: CDI TCK
>          Issue Type: Bug
>      Security Level: Public(Everyone can see) 
>          Components: Tests
>            Reporter: Mark Struberg
>            Assignee: Pete Muir
>             Fix For: 1.0.2.CR1
>
>
> from JSR-250-1.1.MREL section 2.5:
> "The PostConstruct annotation is used on a method that needs to be executed after
> dependency injection is done to perform any initialization. This method MUST be
> invoked before the class is put into service."
> Which I read as "may only get used by others after the @PostConstruct annotated method did run".
> This is backed by the following example
> public BeanA {
>   private @Inject BeanB b;
>   private int x = 0;
>   public int getX() { return x; }
>   @PostConstruct void init() { x = b.getX()+7; }
> }
>   
> public BeanB {
>   private @Inject BeanA a;
>   private int x = 0;
>   public int getX() { return x; }
>   @PostConstruct void init() { x = a.getX()+9; }
> }
> which value do a.x and b.x get finally? This would simply be non-deterministic - and therefore forbidden by the JSR-250 spec.
> Such kind of circular @PostConstruct method calls happen e.g. in CircularDependencyTest Pig -> Food -> Pig

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the weld-issues mailing list