Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 566803

Summary: field.getAnnotatedType().getAnnotations() broken in the latest ECJ version
Product: [Eclipse Project] JDT Reporter: Andres Luuk <mysticel>
Component: CoreAssignee: Srikanth Sankaran <srikanth.sankaran>
Status: CLOSED MOVED QA Contact: Jay Arthanareeswaran <jarthana>
Severity: normal    
Priority: P3 CC: jarthana, srikanth.sankaran
Version: 4.17   
Target Milestone: ---   
Hardware: PC   
OS: Windows 10   
See Also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=552082
Whiteboard:
Attachments:
Description Flags
Repro case, run new Test().test(); to reproduce. none

Description Andres Luuk CLA 2020-09-09 02:00:56 EDT
Created attachment 284087 [details]
Repro case, run new Test().test(); to reproduce.

I upgraded my org.eclipse.jdt:ecj from 3.19.0 to the latest version of 3.22.0.
And now field.getAnnotatedType().getAnnotations() behaves differently from the default jdk.
If I compile the class with 3.19.0 or on openjdk jdk it returns only TestAnnFirst at runtime. But with the latest ecj (3.22.0) it returns 2 annotations. 
I provided a test case on how to reproduce it.
I run the same issue on JDK8 and also on JDK14.
Comment 1 Jay Arthanareeswaran CLA 2020-09-09 06:27:04 EDT
Just to be sure, you are not expecting the annotations with no @Target to show up on the type of field, right?

If that's the case, then I think we are looking at bug 552082. This was forced by some change on the spec, but strangely was never implemented fully by the Javac.
Comment 2 Andres Luuk CLA 2020-09-09 06:48:30 EDT
I read though the case.
I think you are right. It is probably the same case.
I think the only difference here is that, I got the issue from runtime and not from compile time. 
So currently cases like this will be compiled differently with jdk and ecj.
I will just ignore the case for ecj then and if/once they fix the JDK runtime I will revisit the use case on our side.
Comment 3 Jay Arthanareeswaran CLA 2020-09-09 07:58:42 EDT
(In reply to Andres Luuk from comment #2)
> I read though the case.
> I think you are right. It is probably the same case.
> I think the only difference here is that, I got the issue from runtime and
> not from compile time. 
> So currently cases like this will be compiled differently with jdk and ecj.
> I will just ignore the case for ecj then and if/once they fix the JDK
> runtime I will revisit the use case on our side.

Thanks. Also as workaround, you can use specific targets for the affected annotations.
Comment 4 Eclipse Genie CLA 2022-09-27 01:26:43 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 5 Srikanth Sankaran CLA 2023-06-01 03:21:03 EDT
This is fixed by https://github.com/eclipse-jdt/eclipse.jdt.core/issues/1096 and I will include the test case from here into the PR https://github.com/eclipse-jdt/eclipse.jdt.core/pull/1097