RFR JDK-8208470: Type annotations on inner type that is an array component

B. Blaser bsrbnd at gmail.com
Wed Dec 12 14:55:13 UTC 2018


Hi,

During a private conversation, Werner noticed an interesting point
related to [4].

The following expression produces two raw type warnings:

@TA B @TA[] arr = new @TA B @TA [0];

Currently, none of them refers to @TA but with the suggested fix, only
the first one will.

So, I tried some other examples to see what's currently done in
similar situations:

$ cat Warning.java
import java.lang.annotation.*;

// See test warnings/6747671
class Warning {
    @Target(ElementType.TYPE_USE)
    @interface TA {}

    static class B<X> {}

    Warning. at TA B b1 = new Warning. at TA B();
    @TA B b2 = new @TA B();

    Warning. at TA B @TA[] a2 = new Warning. at TA B @TA [0];
    @TA B @TA[] a1 = new @TA B @TA [0];
}

Without fix:

$ javac -XDrawDiagnostics -Xlint:rawtypes Warning.java
Warning.java:10:13: compiler.warn.raw.class.use: @Warning.TA
Warning.B, Warning.B<X>
Warning.java:10:36: compiler.warn.raw.class.use: Warning.B, Warning.B<X>
Warning.java:11:9: compiler.warn.raw.class.use: @Warning.TA Warning.B,
Warning.B<X>
Warning.java:11:20: compiler.warn.raw.class.use: Warning.B, Warning.B<X>
Warning.java:13:13: compiler.warn.raw.class.use: @Warning.TA
Warning.B, Warning.B<X>
Warning.java:13:42: compiler.warn.raw.class.use: Warning.B, Warning.B<X>
Warning.java:14:9: compiler.warn.raw.class.use: Warning.B, Warning.B<X>
Warning.java:14:26: compiler.warn.raw.class.use: Warning.B, Warning.B<X>
8 warnings

With fix:

$ javac -XDrawDiagnostics -Xlint:rawtypes Warning.java
Warning.java:10:13: compiler.warn.raw.class.use: @Warning.TA
Warning.B, Warning.B<X>
Warning.java:10:36: compiler.warn.raw.class.use: Warning.B, Warning.B<X>
Warning.java:11:9: compiler.warn.raw.class.use: @Warning.TA Warning.B,
Warning.B<X>
Warning.java:11:20: compiler.warn.raw.class.use: Warning.B, Warning.B<X>
Warning.java:13:13: compiler.warn.raw.class.use: @Warning.TA
Warning.B, Warning.B<X>
Warning.java:13:42: compiler.warn.raw.class.use: Warning.B, Warning.B<X>
Warning.java:14:9: compiler.warn.raw.class.use: @Warning.TA Warning.B,
Warning.B<X>
Warning.java:14:26: compiler.warn.raw.class.use: Warning.B, Warning.B<X>
8 warnings

We see that the fix brings more warning consistency by adding one
missing @TA at line 14:9.

Now, the question of Werner to be addressed in a separate issue is why
isn't there any @TA on "new" expression warnings?

Any clarification about this would be very helpful.

Thanks,
Bernard


On Sat, 22 Sep 2018 at 18:59, B. Blaser <bsrbnd at gmail.com> wrote:
>
> Hi,
>
> I tried the initial example at processing and at runtime:
> [...]
> All seems to be fine with the fix:
> [...]
>
> Thoughts?
>
> Thanks,
> Bernard
>
> On Tue, 18 Sep 2018 at 15:41, B. Blaser <bsrbnd at gmail.com> wrote:
> >
> > Hi,
> >
> > Please review the following fix for [1]:
> >
> > http://cr.openjdk.java.net/~bsrbnd/jdk8208470/webrev.00/
> >
> > We've seen in thread [2] that [3] has probably caused the regression.
> > Among the variants we explored, Werner's one enhanced as discussed in
> > [2] seems quite good to me.
> > It has a small side-effect as the array element type would then carry
> > the annotation which is revealed by test [4], but I'm of Werner's
> > opinion that this would be correct.
> > I've made other attempts [5] to avoid this side-effect but I'm not
> > sure this is really the right approach.
> >
> > Any feedback is welcome (langtools:tier1 is OK),
> > Bernard
> >
> > [1] https://bugs.openjdk.java.net/browse/JDK-8208470
> > [2] http://mail.openjdk.java.net/pipermail/compiler-dev/2018-July/012199.html
> > [3] http://hg.openjdk.java.net/jdk9/dev/langtools/rev/62e285806e83#l6.440
> > [4] http://cr.openjdk.java.net/~bsrbnd/jdk8208470/webrev.00/test/langtools/tools/javac/warnings/6747671/T6747671.out.frames.html
> > [5] http://mail.openjdk.java.net/pipermail/compiler-dev/2018-July/012266.html


More information about the compiler-dev mailing list