Bug 427752 - Method parameter annotations missing when a type is re-compiled after an annotation processing round
Summary: Method parameter annotations missing when a type is re-compiled after an anno...
Status: CLOSED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: APT (show other bugs)
Version: 4.6   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Generic inbox for the JDT-APT component CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2014-02-09 07:07 EST by Stefan Ocke CLA
Modified: 2019-06-22 08:48 EDT (History)
2 users (show)

See Also:


Attachments
Processor and example project to reproduce the bug (39.73 KB, application/octet-stream)
2014-02-09 07:14 EST, Stefan Ocke CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Ocke CLA 2014-02-09 07:07:17 EST
- I have a class "ClassWithParamAnnotations" with methods with parameters with annotations. 
- This class is not related to any generated class and it also does not trigger code generation.
- In my annotation processor, I lookup this class by Elements.getTypeElement.
- In first round of processing, that type element correctly contains the parameter annotations on its methods.
- In subsequent rounds of processing, those annotations are missing. (Other annotations like method and class level annotations ares still there).
- This happens only, if I have some other class that refers to a type to be generated by the annotation processor.


I did some debugging and found the following:
- In first round, the parameter annotations are resolved correctly by AnnotationDiscoveryVisitor.
- As I understand, this visitor is only called for root elements of the round.
- After first round, all types are re-compiled, including the "ClassWithParamAnnotations". This is done, since Eclipse discovered that there has been a reference to a missing type that now has been generated (see Compiler.compile() amd there:  catch (SourceTypeCollisionException e))
- Due to re-compilation, a new SourceTypeBinding is created for "ClassWithParamAnnotations". However, the AnnotationDiscoveryVisitor is not applied here, since it is not a root element for second round.
- There seems to be no other place, where the parameter anntoations get resolved: Debbuging into LocalVariableBinding.getAnnotations() for this case shows, that Binding.NO_ANNOTATIONS is returned, since DeclaringScope is null for the LocalVariableBinding. 
- Thus, the parameter annotations never get resolved.
Comment 1 Stefan Ocke CLA 2014-02-09 07:14:36 EST
Created attachment 239767 [details]
Processor and example project to reproduce the bug

Steps to reproduce:

1.) unzip attachement
2.) for project eclipse-bug-processor, call "mvn install" to create the processor
3.) import project "eclipse-bug-test" as maven project into eclipse
4.) Either install the m2e-apt connector as suggested. (if not done before) Make sure, the m2e-option "Automatically configure JDT APT is selected"
5.) Open the Error Log. You should see messages for 3 rounds of annotation processing there.

In first round, you see:
aMethod [@test.SomeAnnotation], Parameters: aParam [@test.SomeAnnotation],

In 2nd and 3rd round, you see the bug:
aMethod [@test.SomeAnnotation], Parameters: aParam [],
Comment 2 Srikanth Sankaran CLA 2014-02-26 20:13:50 EST
Jay, please triage. TIA.
Comment 3 Jay Arthanareeswaran CLA 2014-02-26 22:17:30 EST
At the moment we are overloaded with Java 8 work and unlikely to be able to look at this during Luna timeframe. However, if someone can come up with a patch, I can review and release.
Comment 4 Stefan Ocke CLA 2017-05-20 09:32:42 EDT
Hello,

any news here? 
If I could, I would help more, but this is just "to deep" in apt for me...

Best Regards,
Stefan.
Comment 5 Eclipse Genie CLA 2019-06-22 01:18:27 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 6 Stefan Ocke CLA 2019-06-22 08:48:02 EDT
Dear Eclipse Genie, this bug is still relevant.