RFR: 8264373: javac hangs when annotation is declared with sealed public modifier
Jan Lahoda
jlahoda at openjdk.java.net
Thu Apr 15 10:24:36 UTC 2021
On Tue, 30 Mar 2021 16:41:37 GMT, Vicente Romero <vromero at openjdk.org> wrote:
> Please review this one liner fix. Although the title mentions the `sealed` modifier, the issue is not strictly related to it. Basically the situation is the following: modifiers `sealed` + `annotation` can't be applied together meaning that this declaration:
>
> sealed public @interface SealedTest { }
>
>
> should be rejected by the compiler. We check this assertion at method: `Check::checkFlags` which then invokes `Check::checkDisjoint` which at the end invokes `TreeInfo::firstFlag` to find out what is the first low order bit set to 1 in the intersection between the current symbol flags and subset of them. Now the current implementation of this method is:
>
>
> public static long firstFlag(long flags) {
> long flag = 1;
> while ((flag & flags & ExtendedStandardFlags) == 0)
> flag = flag << 1;
> return flag;
> }
>
> but given that `ExtendedStandardFlags` is defined as: `StandardFlags | DEFAULT | SEALED | NON_SEALED` and `StandardFlags` is: `0x0FFF` which if we intersect with the ANNOTATION flag (1<<13) will always return 0, the the loop executes forever. I guess we didn't see this issue before because we didn't had a constraint involving a flag with a value > 0x0FFF and less than 0xFFFF which is the case of the ANNOTATION flag. It seems to me that we can safely drop the `& ExtendedStandardFlags` in method `TreeInfo::firstFlag` given that it is used only by Check::checkDisjoint and it is invoked with an intersection of the current flags and the subset the invoking method cares about. So it won't be possible for the argument of `TreeInfo::firstFlag` to contain some javac internal flags we don't want a compiler user to see. What do you think?
Looks good.
-------------
Marked as reviewed by jlahoda (Reviewer).
PR: https://git.openjdk.java.net/jdk/pull/3273
More information about the compiler-dev
mailing list