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

Jan Lahoda jlahoda at openjdk.java.net
Mon Nov 29 19:56:08 UTC 2021


On Wed, 24 Nov 2021 22:34:29 GMT, Vicente Romero <vromero 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.

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?)

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.)

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

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


More information about the compiler-dev mailing list