[jboss-jira] [JBoss JIRA] (WFLY-11956) @PostConstruct on @ApplicationScoped bean called too late in case @Valid is annotated on a business method

Ronald Sigal (Jira) issues at jboss.org
Fri Apr 26 12:05:00 EDT 2019


    [ https://issues.jboss.org/browse/WFLY-11956?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13727201#comment-13727201 ] 

Ronald Sigal commented on WFLY-11956:
-------------------------------------

Thanks for clarifying, [~guillaume.smet]. At least I defensively claimed ignorance. ;-)

re: "Bean Validation really supposes that your objects are following the Java Beans specification."

I think that's one underlying point here. It's fair to assume that getters really are getters, in the Java Beans sense. [~christian.zambrano], sorry, but I think we may not have a happy ending here. 

As for the issue with getters being executed twice, I note that Section 7.1 "Accessor methods" of the Javabeans spec (https://download.oracle.com/otn-pub/jcp/7224-javabeans-1.01-fr-spec-oth-JSpec/beans.101.pdf) says, "So properties need not just be simple data fields, they can actually be computed values. Updates
may have various programmatic side effects." I.e., getters aren't required to be idempotent, so calling them twice seems like a problem.

re: "Calling the PostConstruct before Phase 2 would still be in compliance with the spec and would better fit the sequence of events that are expected from CDI which is for the PostConstruct to be called after injections."

[~christian.zambrano], yes, I agree. The JAX-RS spec is silent on the question of postConstruct(), so ignoring it can't be considered a bug, but I agree that validating *after* calling the @PostConstruct method is more in line with the spirit of the algorithm. I've created RESTEASY-2227 "Validate fields/properties after calling @PostConstruct annotated method, if one exists" to get that done.

> @PostConstruct on @ApplicationScoped bean called too late in case @Valid is annotated on a business method
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: WFLY-11956
>                 URL: https://issues.jboss.org/browse/WFLY-11956
>             Project: WildFly
>          Issue Type: Bug
>          Components: Bean Validation, REST
>    Affects Versions: 16.0.0.Final
>            Reporter: Joerg Baesner
>            Assignee: Ronald Sigal
>            Priority: Major
>         Attachments: logging.txt, playground.zip
>
>
> Having a bean class with {{@ApplicationScoped}}, which has a {{@PostConstruct}} and is implementing  the following _Interface_:
> {code}
> @Path("/validated")
> public interface ValidatedJaxRsInterface {
>     
>     @GET
>     @Valid
>     @Produces(MediaType.APPLICATION_JSON)
>     GreetingModel getHelloGreeting();
> }
> {code}
> will result in calling the {{getHelloGreeting}} method of the implementation class twice *_before_* the {{@PostConstruct}} is getting executed.
> This can be reproduced with the attached reproducer application...



--
This message was sent by Atlassian Jira
(v7.12.1#712002)


More information about the jboss-jira mailing list