RFR: 8274617: constructor and parameter annotations are not copied to the anonymous class constructor

Vicente Romero vromero at openjdk.java.net
Mon Nov 29 20:13:07 UTC 2021


On Mon, 29 Nov 2021 19:47:56 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

>> Please review this PR which is about propagating constructor and parameter annotations to the anonymous class constructor. Currently we are propagating them to bridge methods which are synthetic. Propagating them to the anonymous class constructor seems sensible given that they are mandated by the spec. Please review also the related CSR,
>> 
>> TIA
>
> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TypeEnter.java line 1341:
> 
>> 1339:         public MethodSymbol constructorSymbol() {
>> 1340:             // we should do this only once
>> 1341:             boolean copyConstAnnos = constructorSymbol == null;
> 
> Question: can we avoid repeating this method completely if `constructorSymbol != null`? Seems a bit weird to not copy the annotation again (which I understand), but redo all the rest again.

yep good point

> test/langtools/tools/javac/annos_not_copied_anonymous_ctr/AnnosNotCopiedToAnonymousCtrTest.java line 116:
> 
>> 114:         @VisibleCtrAnnotation
>> 115:         @InvisibleCtrAnnotation
>> 116:         public Test(String firstParam, @VisibleParamAnnotation String secondParam, @InvisibleParamAnnotation String thirdParam) {}
> 
> How about type annotations of the parameter types? Should these be copied? (And tested?)

yep I should add a test for type annotations, good point

> test/langtools/tools/jdeps/listdeps/ListModuleDeps.java line 98:
> 
>> 96:                                 "java.base/jdk.internal.jmod",
>> 97:                                 "java.base/jdk.internal.misc",
>> 98:                                 "java.base/jdk.internal.vm.annotation",
> 
> This looks a bit suspicious to me - why the new entry? Do we know why it was necessary? (I would expect that any change here would be caused by a change in dependencies among modules, but I don't seem to see that change.)

tbh I'm not sure why this new dependency appeared there is no new import, I will do some research

-------------

PR: https://git.openjdk.java.net/jdk/pull/6548


More information about the compiler-dev mailing list