Community
Participate
Working Groups
Created attachment 274110 [details] Attachment contains the sample project I have created a part with 3 methods that are annotated with @PostConstruct annotation According to the JAVA API specification (https://docs.oracle.com/javaee/7/api/javax/annotation/PostConstruct.html), A method annotated with @PostConstruct is called after a class is initialized with its constructor and after all fields have been injected. Only one method can be annotated with this annotation. I have referred But in my sample part class code I have annotated 3 different methods with @PostConstruct annotation. And it dosen't give neither warning nor error. When I try to execute the application it runs without any exception/error and displays UI with all 3 @PostConstruct annotated method creation. Even the order of the method execution is not stable i.e., sometimes second method annotated with postConstruct gets executes and few times first method annotated with postConstruct gets executes and UI provides different output according to this execution. I was expecting a warning/error for this sort of situation. Please let me know am if I misunderstood something different here. Steps To Reproduce: Create a basic eclipse 4 RCP application with a sample part. In the sample part class add two more methods and annotate with @PostConstruct like below and run the product. public class SamplePart { // postConstruct one @PostConstruct public void createComposite(Composite parentOne) { parentOne.setLayout(new GridLayout(1, false)); Text txtInputOne = new Text(parentOne, SWT.BORDER); txtInputOne.setMessage("postConstruct one"); } // postConstruct Two @PostConstruct public void createCompositeTwo(Composite parentTwo) { parentTwo.setLayout(new GridLayout(1, false)); Text txtInputTwo = new Text(parentTwo, SWT.BORDER); txtInputTwo.setMessage("postConstruct two"); } // postConstruct Three @PostConstruct public void createCompositeThree(Composite parentThree) { parentThree.setLayout(new GridLayout(1, false)); Text txtInputThree = new Text(parentThree, SWT.BORDER); txtInputThree.setMessage("postConstruct three"); } } More information: I have attached the code snippet that demonstrates (what is in my opinion) the problem. Environment I have used: Eclipse Version: Neon.2 Release (4.6.2) Java : "1.8.0_111" Eclispe e4 tools version installed: Eclipse e4 Tools 4.5.100.v20160503-0947
On quick look, the behavior is same as Javac. Moving to JDT Core for further discussion.
Given that the javadoc explicitly disallows multiple methods with this annotation, it seems fair to let the compiler raise a configurable problem. Should we worry about the transition from https://docs.oracle.com/javase/9/docs/api/java.xml.ws.annotation-summary.html to https://github.com/eclipse-ee4j/common-annotations-api ?