RFR: 8264373: javac hangs when annotation is declared with sealed public modifier

Vicente Romero vromero at openjdk.java.net
Tue Mar 30 16:55:37 UTC 2021


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?

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

Commit messages:
 - 8264373: javac hangs when annotation is declared with sealed public modifier

Changes: https://git.openjdk.java.net/jdk/pull/3273/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=3273&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8264373
  Stats: 3 lines in 2 files changed: 1 ins; 0 del; 2 mod
  Patch: https://git.openjdk.java.net/jdk/pull/3273.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/3273/head:pull/3273

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


More information about the compiler-dev mailing list