From markus_keller at ch.ibm.com Wed Nov 6 11:10:25 2013 From: markus_keller at ch.ibm.com (Markus Keller) Date: Wed, 6 Nov 2013 20:10:25 +0100 Subject: [type-annos-observers] formatting of annotated array types Message-ID: I know that coding conventions used by examples in the JLS are not normative, but a consistent notation is nonetheless helpful. JLS7 consistently uses a terse array type notation without any spaces between the type and the brackets, e.g. int[][] or Class[]. java-annotation-design.html and 308.pdf usually keep the terse notation, but add a space on both sides of an interspersed type annotation. These spaces are not enforced by the grammar, but I agree they improve readability. Could this style be used consistently in the code examples? 2013-10-24 only needs corrections in two places: 308.pdf: int [] @Foo [] f; expected: int[] @Foo [] f; 308.pdf: @X String [] [] String @X [] [] String [] @X [] expected: @X String[][] String @X [][] String[] @X [] Thanks, Markus From alex.buckley at oracle.com Wed Nov 6 11:42:09 2013 From: alex.buckley at oracle.com (Alex Buckley) Date: Wed, 06 Nov 2013 11:42:09 -0800 Subject: [type-annos-observers] formatting of annotated array types In-Reply-To: References: Message-ID: <527A9B91.5030001@oracle.com> OK. Also I changed @X to @Foo in the JVMS chapter. On 11/6/2013 11:10 AM, Markus Keller wrote: > I know that coding conventions used by examples in the JLS are not > normative, but a consistent notation is nonetheless helpful. > > JLS7 consistently uses a terse array type notation without any spaces > between the type and the brackets, e.g. int[][] or Class[]. > > java-annotation-design.html and 308.pdf usually keep the terse notation, > but add a space on both sides of an interspersed type annotation. These > spaces are not enforced by the grammar, but I agree they improve > readability. > > Could this style be used consistently in the code examples? 2013-10-24 > only needs corrections in two places: > > 308.pdf: int [] @Foo [] f; > expected: int[] @Foo [] f; > > 308.pdf: @X String [] [] > String @X [] [] > String [] @X [] > > expected: @X String[][] > String @X [][] > String[] @X [] > > Thanks, > Markus > From alex.buckley at oracle.com Wed Nov 6 11:51:15 2013 From: alex.buckley at oracle.com (Alex Buckley) Date: Wed, 06 Nov 2013 11:51:15 -0800 Subject: [type-annos-observers] Public Review for JSR 308 In-Reply-To: <525EDBC6.3030101@oracle.com> References: <525EDBC6.3030101@oracle.com> Message-ID: <527A9DB3.60707@oracle.com> The Public Review has started! The dates are 4 Nov 2013 - 4 Dec 2013. Please see http://www.jcp.org/en/jsr/detail?id=308. FYI the file 2013-10-24-jsr308-spec.pdf in the Public Review is the same as the file 308.pdf at cr.openjdk.java.net/~abuckley. Many thanks for everyone's contributions so far! Alex On 10/16/2013 11:32 AM, Alex Buckley wrote: > In line with the Java SE 8 Platform schedule at > http://openjdk.java.net/projects/jdk8/spec/, we're planning to submit > materials for the Public Review of JSR 308 next Thursday, 10/24. > > The Public Review will run from 10/31 to 12/02, with approval ballots in > the JCP Executive Committee from 12/03 to 12/16. The other SE 8 JSRs are > doing the same. > > In preparation for this milestone, I have updated the draft JLS/JVMS > document at http://cr.openjdk.java.net/~abuckley/308.pdf, considering > Markus' recent comments and adding a summary of API changes. The full SE > 8 API will be presented in the Umbrella JSR's Public Review. > > Comments are welcome any time on type-annotation-spec-experts or > -comments, though you may wish to batch up your comments and submit them > during throughout the PR period. > > Alex From srikanth_sankaran at in.ibm.com Sun Nov 10 22:51:57 2013 From: srikanth_sankaran at in.ibm.com (Srikanth S Adayapalam) Date: Mon, 11 Nov 2013 12:21:57 +0530 Subject: [type-annos-observers] TYPE_USE target and repeatable annotations. Message-ID: Hello ! The following program fails to compile with both javac and ECJ: // -- import java.lang.annotation.ElementType; import java.lang.annotation.Repeatable; import java.lang.annotation.Target; @Target({ElementType.TYPE_USE}) @Repeatable(FooContainer.class) @interface Foo {} @Target({ElementType.TYPE, ElementType.TYPE_USE}) @interface FooContainer { Foo[] value(); } // -- ECJ error message: The container annotation type @FooContainer is allowed at targets where the repeatable annotation type @Foo is not: TYPE javac error message: X.java:6: error: target of container annotation FooContainer is not a subset of target of repeated annotation Foo. >From the spec: If Foo has an @Target meta-annotation, then in the judgment of the designers of the Java programming language, FooContainer must be declared with knowledge of the Foo's applicability. Specifically, the kind of program element where FooContainer may appear must be the same as, or a subset of, Foo's kinds. Given TYPE_USE annotations can appear on type declarations, the last sentence is certainly valid for the program above. What do we want to say about this case ? Thanks! Srikanth From srikanth_sankaran at in.ibm.com Mon Nov 11 01:02:03 2013 From: srikanth_sankaran at in.ibm.com (Srikanth S Adayapalam) Date: Mon, 11 Nov 2013 14:32:03 +0530 Subject: [type-annos-observers] TYPE_USE target and repeatable annotations. In-Reply-To: References: Message-ID: > From: Srikanth S Adayapalam/India/IBM > Subject: TYPE_USE target and repeatable annotations. > The following program fails to compile with both javac and ECJ: > > // -- > import java.lang.annotation.ElementType; > import java.lang.annotation.Repeatable; > import java.lang.annotation.Target; > > @Target({ElementType.TYPE_USE}) > @Repeatable(FooContainer.class) > @interface Foo {} > @Target({ElementType.TYPE, ElementType.TYPE_USE}) > @interface FooContainer { > Foo[] value(); > } [...] > From the spec: > > If Foo has an @Target meta-annotation, then in the judgment of the > designers of the > Java programming language, FooContainer must be declared with knowledge of the > Foo's applicability. Specifically, the kind of program element where > FooContainer > may appear must be the same as, or a subset of, Foo's kinds. > > Given TYPE_USE annotations can appear on type declarations, the > last sentence is certainly valid for the program above. Not quite, just after pushing the send button, I realized that FooContainer by virtue of its TYPE target, can appear on annotation types, while @Foo cannot. So there is no contradiction here. I'll withdraw this issue as requiring no follow up on the spec side. Note however that 8b112 does not complain on this program, I believe it should, given that annotation type uses cannot be type annotated, the short hand of annotating the declaration should also be invalid. import java.lang.annotation.ElementType; import java.lang.annotation.Target; @Target({ElementType.TYPE_USE}) @interface Foo {} @Foo @interface Marker { } Thanks! Srikanth From alex.buckley at oracle.com Mon Nov 11 11:10:04 2013 From: alex.buckley at oracle.com (Alex Buckley) Date: Mon, 11 Nov 2013 11:10:04 -0800 Subject: [type-annos-observers] TYPE_USE target and repeatable annotations. In-Reply-To: References: Message-ID: <52812B8C.1010800@oracle.com> On 11/11/2013 1:02 AM, Srikanth S Adayapalam wrote: >> From: Srikanth S Adayapalam/India/IBM >> Subject: TYPE_USE target and repeatable annotations. > >> The following program fails to compile with both javac and ECJ: >> >> // -- >> import java.lang.annotation.ElementType; >> import java.lang.annotation.Repeatable; >> import java.lang.annotation.Target; >> >> @Target({ElementType.TYPE_USE}) >> @Repeatable(FooContainer.class) >> @interface Foo {} >> @Target({ElementType.TYPE, ElementType.TYPE_USE}) >> @interface FooContainer { >> Foo[] value(); >> } > > [...] > >> From the spec: >> >> If Foo has an @Target meta-annotation, then in the judgment of the >> designers of the >> Java programming language, FooContainer must be declared with knowledge > of the >> Foo's applicability. Specifically, the kind of program element where >> FooContainer >> may appear must be the same as, or a subset of, Foo's kinds. >> >> Given TYPE_USE annotations can appear on type declarations, the >> last sentence is certainly valid for the program above. > > Not quite, just after pushing the send button, I realized that > FooContainer by virtue of its TYPE target, can appear on annotation > types, while @Foo cannot. So there is no contradiction here. There is some confusion here. @Foo can appear on the declaration of an annotation type just like @FooContainer. The Foo type has a TYPE_USE target, so @Foo can appear in at least the places permitted by a TYPE target, which includes declarations of annotation types. This policy has always been in section 2.3 of java-annotation-design.pdf, and is formalized in the 308 Public Review spec as: "It is a compile-time error if an annotation of type T is syntactically a modifier for: ... an annotation type declaration, but T is not applicable to annotation type declarations or type declarations or type contexts." Now to the program above. The targets of Foo and FooContainer are such that logically, @Foo can appear in exactly the same places as @FooContainer. Therefore, the rules for repeatable annotation types should not require an error. I think that was your initial suspicion: that javac and ecj _should_ compile it. However, the target set for FooContainer has more elements that the target set for Foo, so by the rules of JLS 9.6.3 an error is due: "An annotation type TC is a containing annotation type of T if all of the following are true: ... - T is applicable to at least the same kinds of program element as TC (?9.6.4.1). Specifically, if the kinds of program element where T is applicable are denoted by the set m1, and the kinds of program element where TC is applicable are denoted by the set m2, then each kind in m2 must occur in m1 unless the kind in m2 is java.lang.annotation.ElementType.ANNOTATION_TYPE, in which case at least one of java.lang.annotation.ElementType.ANNOTATION_TYPE or java.lang.annotation.ElementType.TYPE must occur in m1." To properly integrate this rule with JSR 308, the Proposed Final Draft of JLS8 should say: "... then each kind in m2 must occur in m1, unless a) the kind in m2 is ANNOTATION_TYPE, in which case at least one of ANNOTATION_TYPE or TYPE or TYPE_USE must occur in m1, and b) the kind in m2 is TYPE, in which case at least one of TYPE or TYPE_USE must occur in m1." Then the program will compile fine. I will file a bug against javac. > Note however that 8b112 does not complain on this program, I believe > it should, given that annotation type uses cannot be type annotated, > the short hand of annotating the declaration should also be invalid. > > import java.lang.annotation.ElementType; > import java.lang.annotation.Target; > > @Target({ElementType.TYPE_USE}) > @interface Foo {} > > @Foo > @interface Marker { > > } Again, a TYPE_USE annotation has always been allowed by JSR 308 wherever a TYPE annotation is allowed, which includes declarations of annotation types. So there is nothing wrong with this program. Alex From srikanth_sankaran at in.ibm.com Mon Nov 11 17:55:57 2013 From: srikanth_sankaran at in.ibm.com (Srikanth S Adayapalam) Date: Tue, 12 Nov 2013 07:25:57 +0530 Subject: [type-annos-observers] TYPE_USE target and repeatable annotations. In-Reply-To: <52812B8C.1010800@oracle.com> References: <52812B8C.1010800@oracle.com> Message-ID: > > Again, a TYPE_USE annotation has always been allowed by JSR 308 wherever > a TYPE annotation is allowed, Well, "Has always been allowed" is not an argument for it being correct, sound or meaningful - is it ? > which includes declarations of annotation > types. So there is nothing wrong with this program. What is the meaning of the type use annotation being applied to an annotation declaration ? Perhaps this is the piece missing in my understanding. Thanks! Srikanth. From alex.buckley at oracle.com Mon Nov 11 18:41:20 2013 From: alex.buckley at oracle.com (Alex Buckley) Date: Mon, 11 Nov 2013 18:41:20 -0800 Subject: [type-annos-observers] TYPE_USE target and repeatable annotations. In-Reply-To: References: <52812B8C.1010800@oracle.com> Message-ID: <52819550.6030309@oracle.com> JSR 308 introduced ElementType.TYPE_USE as pertaining not only to uses of types but also to declarations of types; logically, it's a "supertype" of ElementType.TYPE. The rationale is to simplify migration of annotation types which have a target of ElementType.TYPE but would like to have their annotations work on uses of types. The time to discuss this rationale has long passed. Separately, ElementType.TYPE is logically a supertype of ElementType.ANNOTATION_TYPE. You've been able to write a TYPE annotation on the declaration of an annotation type since 2004. Together, this means you can write a TYPE_USE annotation on the declaration of an annotation type. Alex On 11/11/2013 5:55 PM, Srikanth S Adayapalam wrote: > > > > Again, a TYPE_USE annotation has always been allowed by JSR 308 wherever > > a TYPE annotation is allowed, > > Well, "Has always been allowed" is not an argument for it being correct, > sound or meaningful - is it ? > > > which includes declarations of annotation > > types. So there is nothing wrong with this program. > > What is the meaning of the type use annotation being applied to an > annotation > declaration ? Perhaps this is the piece missing in my understanding. > > Thanks! > Srikanth. From elena.votchennikova at oracle.com Wed Nov 20 04:06:27 2013 From: elena.votchennikova at oracle.com (elena votchennikova) Date: Wed, 20 Nov 2013 16:06:27 +0400 Subject: [type-annos-observers] Receivers and parameters annotated type question Message-ID: <528CA5C3.6060901@oracle.com> Hi all, could you please help me to understand behavior of the following cases. I get annotations of annotated type via reflection API of the following parameter (or receiver with the same annotated type) @Annot(2) MiniTest. @Annot(3) Inner parameter The results are Ok for all cases except one - parameter of the constructor of Inner class. Please take a look at the example bellow. The output of the MiniTest run (on the jdk8-b116) will be ------------------------------------------------------- MiniTest constructor parameter - annotations count: 1 Annot value: 3 Inner constructor parameter - annotations count: 1 Annot value: 2 InnerInner constructor receiver - annotations count: 1 Annot value: 1 InnerInner constructor parameter - annotations count: 1 Annot value: 3 ------------------------------------------------------- Looks like 'Annot value' for the 'Inner constructor parameter' case should be 3. Thank you a lot, Elena public class MiniTest { public MiniTest(@Annot(2) MiniTest. @Annot(3) Inner param) { } class Inner { public Inner(@Annot(2) MiniTest. @Annot(3) Inner param) { } class InnerInner { public InnerInner(@Annot(0) MiniTest. @Annot(1) Inner Inner.this, @Annot(2) MiniTest. @Annot(3) Inner param) { } } } public static void main(String[] args) throws NoSuchMethodException { Constructor constructor = MiniTest.class.getConstructor(Inner.class); AnnotatedType paramType = constructor.getAnnotatedParameterTypes()[0]; printInfo(paramType, "MiniTest constructor parameter"); Constructor innerConstructor = Inner.class.getConstructor(MiniTest.class, Inner.class); AnnotatedType innerParamType = innerConstructor.getAnnotatedParameterTypes()[0]; printInfo(innerParamType, "Inner constructor parameter"); Constructor innerInnerConstructor = Inner.InnerInner.class.getConstructor(Inner.class, Inner.class); AnnotatedType innerInnerReceiverType = innerInnerConstructor.getAnnotatedReceiverType(); printInfo(innerInnerReceiverType, "InnerInner constructor receiver"); AnnotatedType innerInnerParamType = innerInnerConstructor.getAnnotatedParameterTypes()[0]; printInfo(innerInnerParamType, "InnerInner constructor parameter"); } private static void printInfo(AnnotatedType aType, String name) { System.out.println(name); System.out.println("- annotations count: " + aType.getAnnotations().length); System.out.println(" Annot value: " + ((Annot) aType.getAnnotations()[0]).value()); } } @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE_USE) @interface Annot { int value(); } From elena.votchennikova at oracle.com Thu Nov 21 04:16:41 2013 From: elena.votchennikova at oracle.com (elena votchennikova) Date: Thu, 21 Nov 2013 16:16:41 +0400 Subject: [type-annos-observers] Receivers and parameters annotated type question In-Reply-To: <528CA5C3.6060901@oracle.com> References: <528CA5C3.6060901@oracle.com> Message-ID: <528DF9A9.5020204@oracle.com> Please take a look at another case. I've added constructor with InnerInner annotated parameter in every class. ----------------------------------------------------------------------------------------- public class MiniTest { public MiniTest(@Annot(2) MiniTest. @Annot(3) Inner. @Annot(4) InnerInner param) { } class Inner { public Inner(@Annot(2) MiniTest. @Annot(3) Inner. @Annot(4) InnerInner param) { } class InnerInner { public InnerInner(@Annot(2) MiniTest. @Annot(3) Inner. @Annot(4) InnerInner param) { } } } ... ----------------------------------------------------------------------------------------- And the result is strange too: ----------------------------------------------------------------------------------------- MiniTest constructor1 parameter - annotations count: 1 Annot value: 4 Inner constructor1 parameter - annotations count: 1 Annot value: 2 InnerInner constructor1 parameter - annotations count: 1 Annot value: 3 ----------------------------------------------------------------------------------------- The full mini-test is attached. Thanks a lot, Elena On 20.11.2013 16:06, elena votchennikova wrote: > Hi all, > > could you please help me to understand behavior of the following cases. > > I get annotations of annotated type via reflection API of the > following parameter (or receiver with the same annotated type) > @Annot(2) MiniTest. @Annot(3) Inner parameter > > The results are Ok for all cases except one - parameter of the > constructor of Inner class. > Please take a look at the example bellow. > > The output of the MiniTest run (on the jdk8-b116) will be > ------------------------------------------------------- > > MiniTest constructor parameter > - annotations count: 1 > Annot value: 3 > Inner constructor parameter > - annotations count: 1 > Annot value: 2 > InnerInner constructor receiver > - annotations count: 1 > Annot value: 1 > InnerInner constructor parameter > - annotations count: 1 > Annot value: 3 > ------------------------------------------------------- > > Looks like 'Annot value' for the 'Inner constructor parameter' case > should be 3. > > Thank you a lot, > Elena > > > public class MiniTest { > > public MiniTest(@Annot(2) MiniTest. @Annot(3) Inner param) { > } > > class Inner { > > public Inner(@Annot(2) MiniTest. @Annot(3) Inner param) { > } > > class InnerInner { > public InnerInner(@Annot(0) MiniTest. @Annot(1) Inner > Inner.this, @Annot(2) MiniTest. @Annot(3) Inner param) { > } > } > } > > public static void main(String[] args) throws NoSuchMethodException { > Constructor constructor = > MiniTest.class.getConstructor(Inner.class); > AnnotatedType paramType = > constructor.getAnnotatedParameterTypes()[0]; > printInfo(paramType, "MiniTest constructor parameter"); > > Constructor innerConstructor = > Inner.class.getConstructor(MiniTest.class, Inner.class); > AnnotatedType innerParamType = > innerConstructor.getAnnotatedParameterTypes()[0]; > printInfo(innerParamType, "Inner constructor parameter"); > > Constructor innerInnerConstructor = > Inner.InnerInner.class.getConstructor(Inner.class, Inner.class); > AnnotatedType innerInnerReceiverType = > innerInnerConstructor.getAnnotatedReceiverType(); > printInfo(innerInnerReceiverType, "InnerInner constructor > receiver"); > AnnotatedType innerInnerParamType = > innerInnerConstructor.getAnnotatedParameterTypes()[0]; > printInfo(innerInnerParamType, "InnerInner constructor > parameter"); > } > > private static void printInfo(AnnotatedType aType, String name) { > System.out.println(name); > System.out.println("- annotations count: " + > aType.getAnnotations().length); > System.out.println(" Annot value: " + ((Annot) > aType.getAnnotations()[0]).value()); > } > } > > @Retention(RetentionPolicy.RUNTIME) > @Target(ElementType.TYPE_USE) > @interface Annot { > int value(); > } From joel.franck at oracle.com Thu Nov 21 07:04:50 2013 From: joel.franck at oracle.com (Joel Borggren-Franck) Date: Thu, 21 Nov 2013 16:04:50 +0100 Subject: [type-annos-observers] Receivers and parameters annotated type question In-Reply-To: <528DF9A9.5020204@oracle.com> References: <528CA5C3.6060901@oracle.com> <528DF9A9.5020204@oracle.com> Message-ID: <20131121150450.GA25772@oracle.com> Hi Elena, Thanks for the report. This looks like a bug in core reflection. I will file one. cheers /Joel On 2013-11-21, elena votchennikova wrote: > Please take a look at another case. > > I've added constructor with InnerInner annotated parameter in every class. > > ----------------------------------------------------------------------------------------- > public class MiniTest { > public MiniTest(@Annot(2) MiniTest. @Annot(3) Inner. @Annot(4) > InnerInner param) { > } > > class Inner { > public Inner(@Annot(2) MiniTest. @Annot(3) Inner. @Annot(4) > InnerInner param) { > } > > class InnerInner { > public InnerInner(@Annot(2) MiniTest. @Annot(3) Inner. > @Annot(4) InnerInner param) { > } > } > } > ... > ----------------------------------------------------------------------------------------- > > And the result is strange too: > ----------------------------------------------------------------------------------------- > MiniTest constructor1 parameter > - annotations count: 1 > Annot value: 4 > Inner constructor1 parameter > - annotations count: 1 > Annot value: 2 > InnerInner constructor1 parameter > - annotations count: 1 > Annot value: 3 > ----------------------------------------------------------------------------------------- > > The full mini-test is attached. > > > Thanks a lot, > Elena > > > On 20.11.2013 16:06, elena votchennikova wrote: > >Hi all, > > > >could you please help me to understand behavior of the following cases. > > > >I get annotations of annotated type via reflection API of the > >following parameter (or receiver with the same annotated type) > >@Annot(2) MiniTest. @Annot(3) Inner parameter > > > >The results are Ok for all cases except one - parameter of the > >constructor of Inner class. > >Please take a look at the example bellow. > > > >The output of the MiniTest run (on the jdk8-b116) will be > >------------------------------------------------------- > > > >MiniTest constructor parameter > >- annotations count: 1 > > Annot value: 3 > >Inner constructor parameter > >- annotations count: 1 > > Annot value: 2 > >InnerInner constructor receiver > >- annotations count: 1 > > Annot value: 1 > >InnerInner constructor parameter > >- annotations count: 1 > > Annot value: 3 > >------------------------------------------------------- > > > >Looks like 'Annot value' for the 'Inner constructor parameter' > >case should be 3. > > > >Thank you a lot, > >Elena > > > > > >public class MiniTest { > > > > public MiniTest(@Annot(2) MiniTest. @Annot(3) Inner param) { > > } > > > > class Inner { > > > > public Inner(@Annot(2) MiniTest. @Annot(3) Inner param) { > > } > > > > class InnerInner { > > public InnerInner(@Annot(0) MiniTest. @Annot(1) Inner > >Inner.this, @Annot(2) MiniTest. @Annot(3) Inner param) { > > } > > } > > } > > > > public static void main(String[] args) throws NoSuchMethodException { > > Constructor constructor = > >MiniTest.class.getConstructor(Inner.class); > > AnnotatedType paramType = > >constructor.getAnnotatedParameterTypes()[0]; > > printInfo(paramType, "MiniTest constructor parameter"); > > > > Constructor innerConstructor = > >Inner.class.getConstructor(MiniTest.class, Inner.class); > > AnnotatedType innerParamType = > >innerConstructor.getAnnotatedParameterTypes()[0]; > > printInfo(innerParamType, "Inner constructor parameter"); > > > > Constructor innerInnerConstructor = > >Inner.InnerInner.class.getConstructor(Inner.class, Inner.class); > > AnnotatedType innerInnerReceiverType = > >innerInnerConstructor.getAnnotatedReceiverType(); > > printInfo(innerInnerReceiverType, "InnerInner constructor > >receiver"); > > AnnotatedType innerInnerParamType = > >innerInnerConstructor.getAnnotatedParameterTypes()[0]; > > printInfo(innerInnerParamType, "InnerInner constructor > >parameter"); > > } > > > > private static void printInfo(AnnotatedType aType, String name) { > > System.out.println(name); > > System.out.println("- annotations count: " + > >aType.getAnnotations().length); > > System.out.println(" Annot value: " + ((Annot) > >aType.getAnnotations()[0]).value()); > > } > >} > > > >@Retention(RetentionPolicy.RUNTIME) > >@Target(ElementType.TYPE_USE) > >@interface Annot { > > int value(); > >} > > import java.lang.annotation.*; > import java.lang.reflect.AnnotatedType; > import java.lang.reflect.Constructor; > > public class MiniTest { > > public MiniTest(@Annot(2) MiniTest. @Annot(3) Inner param) { > } > > public MiniTest(@Annot(2) MiniTest. @Annot(3) Inner. @Annot(4) InnerInner param) { > } > > class Inner { > > public Inner(@Annot(2) MiniTest. @Annot(3) Inner param) { > } > > public Inner(@Annot(2) MiniTest. @Annot(3) Inner. @Annot(4) InnerInner param) { > } > > class InnerInner { > public InnerInner(@Annot(0) MiniTest. @Annot(1) Inner Inner.this, @Annot(2) MiniTest. @Annot(3) Inner param) { > } > > public InnerInner(@Annot(2) MiniTest. @Annot(3) Inner. @Annot(4) InnerInner param) { > } > } > } > > public static void main(String[] args) throws NoSuchMethodException { > Constructor constructor = MiniTest.class.getConstructor(Inner.class); > AnnotatedType paramType = constructor.getAnnotatedParameterTypes()[0]; > printInfo(paramType, "MiniTest constructor parameter"); > > Constructor innerConstructor = Inner.class.getConstructor(MiniTest.class, Inner.class); > AnnotatedType innerParamType = innerConstructor.getAnnotatedParameterTypes()[0]; > printInfo(innerParamType, "Inner constructor parameter"); > > Constructor innerInnerConstructor = Inner.InnerInner.class.getConstructor(Inner.class, Inner.class); > AnnotatedType innerInnerReceiverType = innerInnerConstructor.getAnnotatedReceiverType(); > printInfo(innerInnerReceiverType, "InnerInner constructor receiver"); > AnnotatedType innerInnerParamType = innerInnerConstructor.getAnnotatedParameterTypes()[0]; > printInfo(innerInnerParamType, "InnerInner constructor parameter"); > > System.out.println(); > > Constructor constructor1 = MiniTest.class.getConstructor(Inner.InnerInner.class); > AnnotatedType paramType1 = constructor1.getAnnotatedParameterTypes()[0]; > printInfo(paramType1, "MiniTest constructor1 parameter"); > > Constructor innerConstructor1 = Inner.class.getConstructor(MiniTest.class, Inner.InnerInner.class); > AnnotatedType innerParamType1 = innerConstructor1.getAnnotatedParameterTypes()[0]; > printInfo(innerParamType1, "Inner constructor1 parameter"); > > Constructor innerInnerConstructor1 = Inner.InnerInner.class.getConstructor(Inner.class, Inner.InnerInner.class); > AnnotatedType innerInnerParamType1 = innerInnerConstructor1.getAnnotatedParameterTypes()[0]; > printInfo(innerInnerParamType1, "InnerInner constructor1 parameter"); > > } > > private static void printInfo(AnnotatedType aType, String name) { > System.out.println(name); > System.out.println("- annotations count: " + aType.getAnnotations().length); > System.out.println(" Annot value: " + ((Annot) aType.getAnnotations()[0]).value()); > } > } > > @Retention(RetentionPolicy.RUNTIME) > @Target(ElementType.TYPE_USE) > @interface Annot { > int value(); > } From elena.votchennikova at oracle.com Thu Nov 21 07:29:31 2013 From: elena.votchennikova at oracle.com (elena votchennikova) Date: Thu, 21 Nov 2013 19:29:31 +0400 Subject: [type-annos-observers] Receivers and parameters annotated type question In-Reply-To: <20131121150450.GA25772@oracle.com> References: <528CA5C3.6060901@oracle.com> <528DF9A9.5020204@oracle.com> <20131121150450.GA25772@oracle.com> Message-ID: <528E26DB.4010802@oracle.com> Hi Joel, thank you a lot for taking care about it. Is my understanding correct: if we have the following definition of the parameter @Annot(0) MiniTest. @Annot(1) Inner. @Annot(2) InnerInner param then AnnotatedType of the param will has type InnerInner with the only one annotation @Annot(2) because other annotations (@Annot(1) and @Annot(0)) relate to the Inner and MiniTest types corresponding. Thank you, Elena On 21.11.2013 19:04, Joel Borggren-Franck wrote: > Hi Elena, > > Thanks for the report. This looks like a bug in core reflection. > > I will file one. > > cheers > /Joel > > On 2013-11-21, elena votchennikova wrote: >> Please take a look at another case. >> >> I've added constructor with InnerInner annotated parameter in every class. >> >> ----------------------------------------------------------------------------------------- >> public class MiniTest { >> public MiniTest(@Annot(2) MiniTest. @Annot(3) Inner. @Annot(4) >> InnerInner param) { >> } >> >> class Inner { >> public Inner(@Annot(2) MiniTest. @Annot(3) Inner. @Annot(4) >> InnerInner param) { >> } >> >> class InnerInner { >> public InnerInner(@Annot(2) MiniTest. @Annot(3) Inner. >> @Annot(4) InnerInner param) { >> } >> } >> } >> ... >> ----------------------------------------------------------------------------------------- >> >> And the result is strange too: >> ----------------------------------------------------------------------------------------- >> MiniTest constructor1 parameter >> - annotations count: 1 >> Annot value: 4 >> Inner constructor1 parameter >> - annotations count: 1 >> Annot value: 2 >> InnerInner constructor1 parameter >> - annotations count: 1 >> Annot value: 3 >> ----------------------------------------------------------------------------------------- >> >> The full mini-test is attached. >> >> >> Thanks a lot, >> Elena >> >> >> On 20.11.2013 16:06, elena votchennikova wrote: >>> Hi all, >>> >>> could you please help me to understand behavior of the following cases. >>> >>> I get annotations of annotated type via reflection API of the >>> following parameter (or receiver with the same annotated type) >>> @Annot(2) MiniTest. @Annot(3) Inner parameter >>> >>> The results are Ok for all cases except one - parameter of the >>> constructor of Inner class. >>> Please take a look at the example bellow. >>> >>> The output of the MiniTest run (on the jdk8-b116) will be >>> ------------------------------------------------------- >>> >>> MiniTest constructor parameter >>> - annotations count: 1 >>> Annot value: 3 >>> Inner constructor parameter >>> - annotations count: 1 >>> Annot value: 2 >>> InnerInner constructor receiver >>> - annotations count: 1 >>> Annot value: 1 >>> InnerInner constructor parameter >>> - annotations count: 1 >>> Annot value: 3 >>> ------------------------------------------------------- >>> >>> Looks like 'Annot value' for the 'Inner constructor parameter' >>> case should be 3. >>> >>> Thank you a lot, >>> Elena >>> >>> >>> public class MiniTest { >>> >>> public MiniTest(@Annot(2) MiniTest. @Annot(3) Inner param) { >>> } >>> >>> class Inner { >>> >>> public Inner(@Annot(2) MiniTest. @Annot(3) Inner param) { >>> } >>> >>> class InnerInner { >>> public InnerInner(@Annot(0) MiniTest. @Annot(1) Inner >>> Inner.this, @Annot(2) MiniTest. @Annot(3) Inner param) { >>> } >>> } >>> } >>> >>> public static void main(String[] args) throws NoSuchMethodException { >>> Constructor constructor = >>> MiniTest.class.getConstructor(Inner.class); >>> AnnotatedType paramType = >>> constructor.getAnnotatedParameterTypes()[0]; >>> printInfo(paramType, "MiniTest constructor parameter"); >>> >>> Constructor innerConstructor = >>> Inner.class.getConstructor(MiniTest.class, Inner.class); >>> AnnotatedType innerParamType = >>> innerConstructor.getAnnotatedParameterTypes()[0]; >>> printInfo(innerParamType, "Inner constructor parameter"); >>> >>> Constructor innerInnerConstructor = >>> Inner.InnerInner.class.getConstructor(Inner.class, Inner.class); >>> AnnotatedType innerInnerReceiverType = >>> innerInnerConstructor.getAnnotatedReceiverType(); >>> printInfo(innerInnerReceiverType, "InnerInner constructor >>> receiver"); >>> AnnotatedType innerInnerParamType = >>> innerInnerConstructor.getAnnotatedParameterTypes()[0]; >>> printInfo(innerInnerParamType, "InnerInner constructor >>> parameter"); >>> } >>> >>> private static void printInfo(AnnotatedType aType, String name) { >>> System.out.println(name); >>> System.out.println("- annotations count: " + >>> aType.getAnnotations().length); >>> System.out.println(" Annot value: " + ((Annot) >>> aType.getAnnotations()[0]).value()); >>> } >>> } >>> >>> @Retention(RetentionPolicy.RUNTIME) >>> @Target(ElementType.TYPE_USE) >>> @interface Annot { >>> int value(); >>> } >> import java.lang.annotation.*; >> import java.lang.reflect.AnnotatedType; >> import java.lang.reflect.Constructor; >> >> public class MiniTest { >> >> public MiniTest(@Annot(2) MiniTest. @Annot(3) Inner param) { >> } >> >> public MiniTest(@Annot(2) MiniTest. @Annot(3) Inner. @Annot(4) InnerInner param) { >> } >> >> class Inner { >> >> public Inner(@Annot(2) MiniTest. @Annot(3) Inner param) { >> } >> >> public Inner(@Annot(2) MiniTest. @Annot(3) Inner. @Annot(4) InnerInner param) { >> } >> >> class InnerInner { >> public InnerInner(@Annot(0) MiniTest. @Annot(1) Inner Inner.this, @Annot(2) MiniTest. @Annot(3) Inner param) { >> } >> >> public InnerInner(@Annot(2) MiniTest. @Annot(3) Inner. @Annot(4) InnerInner param) { >> } >> } >> } >> >> public static void main(String[] args) throws NoSuchMethodException { >> Constructor constructor = MiniTest.class.getConstructor(Inner.class); >> AnnotatedType paramType = constructor.getAnnotatedParameterTypes()[0]; >> printInfo(paramType, "MiniTest constructor parameter"); >> >> Constructor innerConstructor = Inner.class.getConstructor(MiniTest.class, Inner.class); >> AnnotatedType innerParamType = innerConstructor.getAnnotatedParameterTypes()[0]; >> printInfo(innerParamType, "Inner constructor parameter"); >> >> Constructor innerInnerConstructor = Inner.InnerInner.class.getConstructor(Inner.class, Inner.class); >> AnnotatedType innerInnerReceiverType = innerInnerConstructor.getAnnotatedReceiverType(); >> printInfo(innerInnerReceiverType, "InnerInner constructor receiver"); >> AnnotatedType innerInnerParamType = innerInnerConstructor.getAnnotatedParameterTypes()[0]; >> printInfo(innerInnerParamType, "InnerInner constructor parameter"); >> >> System.out.println(); >> >> Constructor constructor1 = MiniTest.class.getConstructor(Inner.InnerInner.class); >> AnnotatedType paramType1 = constructor1.getAnnotatedParameterTypes()[0]; >> printInfo(paramType1, "MiniTest constructor1 parameter"); >> >> Constructor innerConstructor1 = Inner.class.getConstructor(MiniTest.class, Inner.InnerInner.class); >> AnnotatedType innerParamType1 = innerConstructor1.getAnnotatedParameterTypes()[0]; >> printInfo(innerParamType1, "Inner constructor1 parameter"); >> >> Constructor innerInnerConstructor1 = Inner.InnerInner.class.getConstructor(Inner.class, Inner.InnerInner.class); >> AnnotatedType innerInnerParamType1 = innerInnerConstructor1.getAnnotatedParameterTypes()[0]; >> printInfo(innerInnerParamType1, "InnerInner constructor1 parameter"); >> >> } >> >> private static void printInfo(AnnotatedType aType, String name) { >> System.out.println(name); >> System.out.println("- annotations count: " + aType.getAnnotations().length); >> System.out.println(" Annot value: " + ((Annot) aType.getAnnotations()[0]).value()); >> } >> } >> >> @Retention(RetentionPolicy.RUNTIME) >> @Target(ElementType.TYPE_USE) >> @interface Annot { >> int value(); >> } From joel.franck at oracle.com Fri Nov 22 06:27:02 2013 From: joel.franck at oracle.com (Joel Borggren-Franck) Date: Fri, 22 Nov 2013 15:27:02 +0100 Subject: [type-annos-observers] Receivers and parameters annotated type question In-Reply-To: <528E26DB.4010802@oracle.com> References: <528CA5C3.6060901@oracle.com> <528DF9A9.5020204@oracle.com> <20131121150450.GA25772@oracle.com> <528E26DB.4010802@oracle.com> Message-ID: <20131122142702.GA27261@oracle.com> Hi Elena, This turned out to be a compiler issue: https://bugs.openjdk.java.net/browse/JDK-8029012 public class A { public A() { } class B { public B(@X A. @Y B param) { } } } "param" here should return [@Y] from getAnnotatedType().getAnnotations(). The constructor for B..getAnnotatedParameterTypes()[0] will return the outer.this synthetic/mandated parameter which should not have any annotations in this case and in this case have type A (and therefor gets the @X annotation). HTH cheers /Joel On 2013-11-21, elena votchennikova wrote: > Hi Joel, > > thank you a lot for taking care about it. > > Is my understanding correct: > if we have the following definition of the parameter > @Annot(0) MiniTest. @Annot(1) Inner. @Annot(2) InnerInner param > > then AnnotatedType of the param will has type InnerInner with the > only one annotation @Annot(2) because other annotations (@Annot(1) > and @Annot(0)) relate to the Inner and MiniTest types corresponding. > > > Thank you, > Elena > > On 21.11.2013 19:04, Joel Borggren-Franck wrote: > >Hi Elena, > > > >Thanks for the report. This looks like a bug in core reflection. > > > >I will file one. > > > >cheers > >/Joel > > > >On 2013-11-21, elena votchennikova wrote: > >>Please take a look at another case. > >> > >>I've added constructor with InnerInner annotated parameter in every class. > >> > >>----------------------------------------------------------------------------------------- > >>public class MiniTest { > >> public MiniTest(@Annot(2) MiniTest. @Annot(3) Inner. @Annot(4) > >>InnerInner param) { > >> } > >> > >> class Inner { > >> public Inner(@Annot(2) MiniTest. @Annot(3) Inner. @Annot(4) > >>InnerInner param) { > >> } > >> > >> class InnerInner { > >> public InnerInner(@Annot(2) MiniTest. @Annot(3) Inner. > >>@Annot(4) InnerInner param) { > >> } > >> } > >> } > >>... > >>----------------------------------------------------------------------------------------- > >> > >>And the result is strange too: > >>----------------------------------------------------------------------------------------- > >>MiniTest constructor1 parameter > >>- annotations count: 1 > >> Annot value: 4 > >>Inner constructor1 parameter > >>- annotations count: 1 > >> Annot value: 2 > >>InnerInner constructor1 parameter > >>- annotations count: 1 > >> Annot value: 3 > >>----------------------------------------------------------------------------------------- > >> > >>The full mini-test is attached. > >> > >> > >>Thanks a lot, > >>Elena > >> > >> > >>On 20.11.2013 16:06, elena votchennikova wrote: > >>>Hi all, > >>> > >>>could you please help me to understand behavior of the following cases. > >>> > >>>I get annotations of annotated type via reflection API of the > >>>following parameter (or receiver with the same annotated type) > >>>@Annot(2) MiniTest. @Annot(3) Inner parameter > >>> > >>>The results are Ok for all cases except one - parameter of the > >>>constructor of Inner class. > >>>Please take a look at the example bellow. > >>> > >>>The output of the MiniTest run (on the jdk8-b116) will be > >>>------------------------------------------------------- > >>> > >>>MiniTest constructor parameter > >>>- annotations count: 1 > >>> Annot value: 3 > >>>Inner constructor parameter > >>>- annotations count: 1 > >>> Annot value: 2 > >>>InnerInner constructor receiver > >>>- annotations count: 1 > >>> Annot value: 1 > >>>InnerInner constructor parameter > >>>- annotations count: 1 > >>> Annot value: 3 > >>>------------------------------------------------------- > >>> > >>>Looks like 'Annot value' for the 'Inner constructor parameter' > >>>case should be 3. > >>> > >>>Thank you a lot, > >>>Elena > >>> > >>> > >>>public class MiniTest { > >>> > >>> public MiniTest(@Annot(2) MiniTest. @Annot(3) Inner param) { > >>> } > >>> > >>> class Inner { > >>> > >>> public Inner(@Annot(2) MiniTest. @Annot(3) Inner param) { > >>> } > >>> > >>> class InnerInner { > >>> public InnerInner(@Annot(0) MiniTest. @Annot(1) Inner > >>>Inner.this, @Annot(2) MiniTest. @Annot(3) Inner param) { > >>> } > >>> } > >>> } > >>> > >>> public static void main(String[] args) throws NoSuchMethodException { > >>> Constructor constructor = > >>>MiniTest.class.getConstructor(Inner.class); > >>> AnnotatedType paramType = > >>>constructor.getAnnotatedParameterTypes()[0]; > >>> printInfo(paramType, "MiniTest constructor parameter"); > >>> > >>> Constructor innerConstructor = > >>>Inner.class.getConstructor(MiniTest.class, Inner.class); > >>> AnnotatedType innerParamType = > >>>innerConstructor.getAnnotatedParameterTypes()[0]; > >>> printInfo(innerParamType, "Inner constructor parameter"); > >>> > >>> Constructor innerInnerConstructor = > >>>Inner.InnerInner.class.getConstructor(Inner.class, Inner.class); > >>> AnnotatedType innerInnerReceiverType = > >>>innerInnerConstructor.getAnnotatedReceiverType(); > >>> printInfo(innerInnerReceiverType, "InnerInner constructor > >>>receiver"); > >>> AnnotatedType innerInnerParamType = > >>>innerInnerConstructor.getAnnotatedParameterTypes()[0]; > >>> printInfo(innerInnerParamType, "InnerInner constructor > >>>parameter"); > >>> } > >>> > >>> private static void printInfo(AnnotatedType aType, String name) { > >>> System.out.println(name); > >>> System.out.println("- annotations count: " + > >>>aType.getAnnotations().length); > >>> System.out.println(" Annot value: " + ((Annot) > >>>aType.getAnnotations()[0]).value()); > >>> } > >>>} > >>> > >>>@Retention(RetentionPolicy.RUNTIME) > >>>@Target(ElementType.TYPE_USE) > >>>@interface Annot { > >>> int value(); > >>>} > >>import java.lang.annotation.*; > >>import java.lang.reflect.AnnotatedType; > >>import java.lang.reflect.Constructor; > >> > >>public class MiniTest { > >> > >> public MiniTest(@Annot(2) MiniTest. @Annot(3) Inner param) { > >> } > >> > >> public MiniTest(@Annot(2) MiniTest. @Annot(3) Inner. @Annot(4) InnerInner param) { > >> } > >> > >> class Inner { > >> > >> public Inner(@Annot(2) MiniTest. @Annot(3) Inner param) { > >> } > >> > >> public Inner(@Annot(2) MiniTest. @Annot(3) Inner. @Annot(4) InnerInner param) { > >> } > >> > >> class InnerInner { > >> public InnerInner(@Annot(0) MiniTest. @Annot(1) Inner Inner.this, @Annot(2) MiniTest. @Annot(3) Inner param) { > >> } > >> > >> public InnerInner(@Annot(2) MiniTest. @Annot(3) Inner. @Annot(4) InnerInner param) { > >> } > >> } > >> } > >> > >> public static void main(String[] args) throws NoSuchMethodException { > >> Constructor constructor = MiniTest.class.getConstructor(Inner.class); > >> AnnotatedType paramType = constructor.getAnnotatedParameterTypes()[0]; > >> printInfo(paramType, "MiniTest constructor parameter"); > >> > >> Constructor innerConstructor = Inner.class.getConstructor(MiniTest.class, Inner.class); > >> AnnotatedType innerParamType = innerConstructor.getAnnotatedParameterTypes()[0]; > >> printInfo(innerParamType, "Inner constructor parameter"); > >> > >> Constructor innerInnerConstructor = Inner.InnerInner.class.getConstructor(Inner.class, Inner.class); > >> AnnotatedType innerInnerReceiverType = innerInnerConstructor.getAnnotatedReceiverType(); > >> printInfo(innerInnerReceiverType, "InnerInner constructor receiver"); > >> AnnotatedType innerInnerParamType = innerInnerConstructor.getAnnotatedParameterTypes()[0]; > >> printInfo(innerInnerParamType, "InnerInner constructor parameter"); > >> > >> System.out.println(); > >> > >> Constructor constructor1 = MiniTest.class.getConstructor(Inner.InnerInner.class); > >> AnnotatedType paramType1 = constructor1.getAnnotatedParameterTypes()[0]; > >> printInfo(paramType1, "MiniTest constructor1 parameter"); > >> > >> Constructor innerConstructor1 = Inner.class.getConstructor(MiniTest.class, Inner.InnerInner.class); > >> AnnotatedType innerParamType1 = innerConstructor1.getAnnotatedParameterTypes()[0]; > >> printInfo(innerParamType1, "Inner constructor1 parameter"); > >> > >> Constructor innerInnerConstructor1 = Inner.InnerInner.class.getConstructor(Inner.class, Inner.InnerInner.class); > >> AnnotatedType innerInnerParamType1 = innerInnerConstructor1.getAnnotatedParameterTypes()[0]; > >> printInfo(innerInnerParamType1, "InnerInner constructor1 parameter"); > >> > >> } > >> > >> private static void printInfo(AnnotatedType aType, String name) { > >> System.out.println(name); > >> System.out.println("- annotations count: " + aType.getAnnotations().length); > >> System.out.println(" Annot value: " + ((Annot) aType.getAnnotations()[0]).value()); > >> } > >>} > >> > >>@Retention(RetentionPolicy.RUNTIME) > >>@Target(ElementType.TYPE_USE) > >>@interface Annot { > >> int value(); > >>} > From elena.votchennikova at oracle.com Fri Nov 22 07:10:17 2013 From: elena.votchennikova at oracle.com (elena votchennikova) Date: Fri, 22 Nov 2013 19:10:17 +0400 Subject: [type-annos-observers] Receivers and parameters annotated type question In-Reply-To: <20131122142702.GA27261@oracle.com> References: <528CA5C3.6060901@oracle.com> <528DF9A9.5020204@oracle.com> <20131121150450.GA25772@oracle.com> <528E26DB.4010802@oracle.com> <20131122142702.GA27261@oracle.com> Message-ID: <528F73D9.1000405@oracle.com> Hi Joel, On 22.11.2013 18:27, Joel Borggren-Franck wrote: > Hi Elena, > > This turned out to be a compiler issue: > https://bugs.openjdk.java.net/browse/JDK-8029012 > > public class A { > public A() { } > > class B { > public B(@X A. @Y B param) { } > } > } > > "param" here should return [@Y] from getAnnotatedType().getAnnotations(). Ok > > The constructor for B..getAnnotatedParameterTypes()[0] will return the > outer.this synthetic/mandated parameter which should not have any > annotations in this case and in this case have type A (and therefor gets > the @X annotation). Oh, right! Thank you a lot, Elena > > HTH > > cheers > /Joel > > On 2013-11-21, elena votchennikova wrote: >> Hi Joel, >> >> thank you a lot for taking care about it. >> >> Is my understanding correct: >> if we have the following definition of the parameter >> @Annot(0) MiniTest. @Annot(1) Inner. @Annot(2) InnerInner param >> >> then AnnotatedType of the param will has type InnerInner with the >> only one annotation @Annot(2) because other annotations (@Annot(1) >> and @Annot(0)) relate to the Inner and MiniTest types corresponding. >> >> >> Thank you, >> Elena >> >> On 21.11.2013 19:04, Joel Borggren-Franck wrote: >>> Hi Elena, >>> >>> Thanks for the report. This looks like a bug in core reflection. >>> >>> I will file one. >>> >>> cheers >>> /Joel >>> >>> On 2013-11-21, elena votchennikova wrote: >>>> Please take a look at another case. >>>> >>>> I've added constructor with InnerInner annotated parameter in every class. >>>> >>>> ----------------------------------------------------------------------------------------- >>>> public class MiniTest { >>>> public MiniTest(@Annot(2) MiniTest. @Annot(3) Inner. @Annot(4) >>>> InnerInner param) { >>>> } >>>> >>>> class Inner { >>>> public Inner(@Annot(2) MiniTest. @Annot(3) Inner. @Annot(4) >>>> InnerInner param) { >>>> } >>>> >>>> class InnerInner { >>>> public InnerInner(@Annot(2) MiniTest. @Annot(3) Inner. >>>> @Annot(4) InnerInner param) { >>>> } >>>> } >>>> } >>>> ... >>>> ----------------------------------------------------------------------------------------- >>>> >>>> And the result is strange too: >>>> ----------------------------------------------------------------------------------------- >>>> MiniTest constructor1 parameter >>>> - annotations count: 1 >>>> Annot value: 4 >>>> Inner constructor1 parameter >>>> - annotations count: 1 >>>> Annot value: 2 >>>> InnerInner constructor1 parameter >>>> - annotations count: 1 >>>> Annot value: 3 >>>> ----------------------------------------------------------------------------------------- >>>> >>>> The full mini-test is attached. >>>> >>>> >>>> Thanks a lot, >>>> Elena >>>> >>>> >>>> On 20.11.2013 16:06, elena votchennikova wrote: >>>>> Hi all, >>>>> >>>>> could you please help me to understand behavior of the following cases. >>>>> >>>>> I get annotations of annotated type via reflection API of the >>>>> following parameter (or receiver with the same annotated type) >>>>> @Annot(2) MiniTest. @Annot(3) Inner parameter >>>>> >>>>> The results are Ok for all cases except one - parameter of the >>>>> constructor of Inner class. >>>>> Please take a look at the example bellow. >>>>> >>>>> The output of the MiniTest run (on the jdk8-b116) will be >>>>> ------------------------------------------------------- >>>>> >>>>> MiniTest constructor parameter >>>>> - annotations count: 1 >>>>> Annot value: 3 >>>>> Inner constructor parameter >>>>> - annotations count: 1 >>>>> Annot value: 2 >>>>> InnerInner constructor receiver >>>>> - annotations count: 1 >>>>> Annot value: 1 >>>>> InnerInner constructor parameter >>>>> - annotations count: 1 >>>>> Annot value: 3 >>>>> ------------------------------------------------------- >>>>> >>>>> Looks like 'Annot value' for the 'Inner constructor parameter' >>>>> case should be 3. >>>>> >>>>> Thank you a lot, >>>>> Elena >>>>> >>>>> >>>>> public class MiniTest { >>>>> >>>>> public MiniTest(@Annot(2) MiniTest. @Annot(3) Inner param) { >>>>> } >>>>> >>>>> class Inner { >>>>> >>>>> public Inner(@Annot(2) MiniTest. @Annot(3) Inner param) { >>>>> } >>>>> >>>>> class InnerInner { >>>>> public InnerInner(@Annot(0) MiniTest. @Annot(1) Inner >>>>> Inner.this, @Annot(2) MiniTest. @Annot(3) Inner param) { >>>>> } >>>>> } >>>>> } >>>>> >>>>> public static void main(String[] args) throws NoSuchMethodException { >>>>> Constructor constructor = >>>>> MiniTest.class.getConstructor(Inner.class); >>>>> AnnotatedType paramType = >>>>> constructor.getAnnotatedParameterTypes()[0]; >>>>> printInfo(paramType, "MiniTest constructor parameter"); >>>>> >>>>> Constructor innerConstructor = >>>>> Inner.class.getConstructor(MiniTest.class, Inner.class); >>>>> AnnotatedType innerParamType = >>>>> innerConstructor.getAnnotatedParameterTypes()[0]; >>>>> printInfo(innerParamType, "Inner constructor parameter"); >>>>> >>>>> Constructor innerInnerConstructor = >>>>> Inner.InnerInner.class.getConstructor(Inner.class, Inner.class); >>>>> AnnotatedType innerInnerReceiverType = >>>>> innerInnerConstructor.getAnnotatedReceiverType(); >>>>> printInfo(innerInnerReceiverType, "InnerInner constructor >>>>> receiver"); >>>>> AnnotatedType innerInnerParamType = >>>>> innerInnerConstructor.getAnnotatedParameterTypes()[0]; >>>>> printInfo(innerInnerParamType, "InnerInner constructor >>>>> parameter"); >>>>> } >>>>> >>>>> private static void printInfo(AnnotatedType aType, String name) { >>>>> System.out.println(name); >>>>> System.out.println("- annotations count: " + >>>>> aType.getAnnotations().length); >>>>> System.out.println(" Annot value: " + ((Annot) >>>>> aType.getAnnotations()[0]).value()); >>>>> } >>>>> } >>>>> >>>>> @Retention(RetentionPolicy.RUNTIME) >>>>> @Target(ElementType.TYPE_USE) >>>>> @interface Annot { >>>>> int value(); >>>>> } >>>> import java.lang.annotation.*; >>>> import java.lang.reflect.AnnotatedType; >>>> import java.lang.reflect.Constructor; >>>> >>>> public class MiniTest { >>>> >>>> public MiniTest(@Annot(2) MiniTest. @Annot(3) Inner param) { >>>> } >>>> >>>> public MiniTest(@Annot(2) MiniTest. @Annot(3) Inner. @Annot(4) InnerInner param) { >>>> } >>>> >>>> class Inner { >>>> >>>> public Inner(@Annot(2) MiniTest. @Annot(3) Inner param) { >>>> } >>>> >>>> public Inner(@Annot(2) MiniTest. @Annot(3) Inner. @Annot(4) InnerInner param) { >>>> } >>>> >>>> class InnerInner { >>>> public InnerInner(@Annot(0) MiniTest. @Annot(1) Inner Inner.this, @Annot(2) MiniTest. @Annot(3) Inner param) { >>>> } >>>> >>>> public InnerInner(@Annot(2) MiniTest. @Annot(3) Inner. @Annot(4) InnerInner param) { >>>> } >>>> } >>>> } >>>> >>>> public static void main(String[] args) throws NoSuchMethodException { >>>> Constructor constructor = MiniTest.class.getConstructor(Inner.class); >>>> AnnotatedType paramType = constructor.getAnnotatedParameterTypes()[0]; >>>> printInfo(paramType, "MiniTest constructor parameter"); >>>> >>>> Constructor innerConstructor = Inner.class.getConstructor(MiniTest.class, Inner.class); >>>> AnnotatedType innerParamType = innerConstructor.getAnnotatedParameterTypes()[0]; >>>> printInfo(innerParamType, "Inner constructor parameter"); >>>> >>>> Constructor innerInnerConstructor = Inner.InnerInner.class.getConstructor(Inner.class, Inner.class); >>>> AnnotatedType innerInnerReceiverType = innerInnerConstructor.getAnnotatedReceiverType(); >>>> printInfo(innerInnerReceiverType, "InnerInner constructor receiver"); >>>> AnnotatedType innerInnerParamType = innerInnerConstructor.getAnnotatedParameterTypes()[0]; >>>> printInfo(innerInnerParamType, "InnerInner constructor parameter"); >>>> >>>> System.out.println(); >>>> >>>> Constructor constructor1 = MiniTest.class.getConstructor(Inner.InnerInner.class); >>>> AnnotatedType paramType1 = constructor1.getAnnotatedParameterTypes()[0]; >>>> printInfo(paramType1, "MiniTest constructor1 parameter"); >>>> >>>> Constructor innerConstructor1 = Inner.class.getConstructor(MiniTest.class, Inner.InnerInner.class); >>>> AnnotatedType innerParamType1 = innerConstructor1.getAnnotatedParameterTypes()[0]; >>>> printInfo(innerParamType1, "Inner constructor1 parameter"); >>>> >>>> Constructor innerInnerConstructor1 = Inner.InnerInner.class.getConstructor(Inner.class, Inner.InnerInner.class); >>>> AnnotatedType innerInnerParamType1 = innerInnerConstructor1.getAnnotatedParameterTypes()[0]; >>>> printInfo(innerInnerParamType1, "InnerInner constructor1 parameter"); >>>> >>>> } >>>> >>>> private static void printInfo(AnnotatedType aType, String name) { >>>> System.out.println(name); >>>> System.out.println("- annotations count: " + aType.getAnnotations().length); >>>> System.out.println(" Annot value: " + ((Annot) aType.getAnnotations()[0]).value()); >>>> } >>>> } >>>> >>>> @Retention(RetentionPolicy.RUNTIME) >>>> @Target(ElementType.TYPE_USE) >>>> @interface Annot { >>>> int value(); >>>> }